This is an automated email from the ASF dual-hosted git repository. amanin pushed a commit to branch refactor/sql-store in repository https://gitbox.apache.org/repos/asf/sis.git
commit 10052535cf3e220d6aac62f817aa607471198da7 Author: Alexis Manin <[email protected]> AuthorDate: Thu Oct 10 16:20:30 2019 +0200 WIP(Feature): test CRS checking in intersect operation. --- .../java/org/apache/sis/filter/CRSMatching.java | 30 +++++++-------- .../test/java/org/apache/sis/filter/SQLMMTest.java | 43 +++++++++++++++++++--- .../sis/internal/feature/GeometriesTestCase.java | 2 +- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/CRSMatching.java b/core/sis-feature/src/main/java/org/apache/sis/filter/CRSMatching.java index 8f8a265..23dfdf2 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/filter/CRSMatching.java +++ b/core/sis-feature/src/main/java/org/apache/sis/filter/CRSMatching.java @@ -7,32 +7,32 @@ import org.opengis.referencing.operation.CoordinateOperation; import org.opengis.util.FactoryException; import org.apache.sis.referencing.CRS; -import org.apache.sis.util.NullArgumentException; import org.apache.sis.util.Utilities; import org.apache.sis.util.collection.BackingStoreException; +import static org.apache.sis.referencing.IdentifiedObjects.getIdentifierOrName; + /** - * TODO: improve CRS conversion/suggestion by infering a geographic region of interest. + * TODO: improve CRS conversion/suggestion by allowing user to input a geographic region of interest. */ +@FunctionalInterface public interface CRSMatching { static CRSMatching left(final CoordinateReferenceSystem source) { if (source == null) { - return new CRSMatching() { - @Override - public Match right(CoordinateReferenceSystem other) { - if (other == null) return new NullMatch(); - else throw new IllegalArgumentException("No match can be established with given CRS because source one is null."); - } + return other -> { + if (other == null) return new NullMatch(); + else throw new IllegalArgumentException("No match can be established with given CRS because source one is null."); }; } else { - return new CRSMatching() { - @Override - public Match right(CoordinateReferenceSystem other) { - if (other == null) throw new NullArgumentException("No match can be established with previous CRS because input one is null"); - final CoordinateReferenceSystem commonCrs = CRS.suggestCommonTarget(null, source, other); - return new DefaultMatch(commonCrs, source, other); - } + return other -> { + if (other == null) throw new IllegalArgumentException("No match can be established with previous CRS because input one is null"); + final CoordinateReferenceSystem commonCrs = CRS.suggestCommonTarget(null, source, other); + if (commonCrs == null) throw new IllegalArgumentException(String.format( + "No common space can be found between %s and %s", + getIdentifierOrName(source), getIdentifierOrName(other) + )); + return new DefaultMatch(commonCrs, source, other); }; } } diff --git a/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java b/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java index 75a2fbc..8b2cda5 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java @@ -25,6 +25,7 @@ import org.opengis.filter.expression.Literal; import org.opengis.filter.expression.PropertyName; import org.opengis.geometry.Envelope; import org.opengis.referencing.crs.CoordinateReferenceSystem; +import org.opengis.referencing.crs.ProjectedCRS; import org.apache.sis.feature.builder.FeatureTypeBuilder; import org.apache.sis.geometry.GeneralEnvelope; @@ -40,6 +41,7 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.LinearRing; import org.locationtech.jts.geom.Point; +import static org.apache.sis.internal.feature.GeometriesTestCase.expectFailFast; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -170,22 +172,53 @@ public class SQLMMTest extends TestCase { }); final Literal lring = factory.literal(ring); - ST_Intersects st = new ST_Intersects(new Expression[]{factory.literal(gf.createPoint(new Coordinate(2, 4))), lring}); + ST_Intersects st = intersects(factory.literal(gf.createPoint(new Coordinate(2, 4))), lring); // Ensure argument nullity does not modify behavior assertFalse("Unexpected intersection", st.evaluate(null)); assertFalse("Unexpected intersection", st.evaluate(new Object())); // Border should intersect final Feature f = mock(); - f.setPropertyValue(P_NAME, gf.createPoint(second)); + final Point point = gf.createPoint(second); + f.setPropertyValue(P_NAME, point); final PropertyName geomName = factory.property(P_NAME); - st = new ST_Intersects(new Expression[]{geomName, lring}); + st = intersects(geomName, lring); assertTrue("Border point should intersect triangle", st.evaluate(f)); // Ensure inverting expression does not modify behavior. - st = new ST_Intersects(new Expression[]{lring, geomName}); + st = intersects(lring, geomName); assertTrue("Border point should intersect triangle", st.evaluate(f)); - // TODO: add CRS checking tests. + // Ensure CRS conversion works as expected (see package-info). + // Missing + point.setUserData(CommonCRS.defaultGeographic()); + expectFailFast(() -> intersects(geomName, lring).evaluate(f), IllegalArgumentException.class); + final Literal lPoint = factory.literal(point); + expectFailFast(() -> intersects(lPoint, lring).evaluate(null), IllegalArgumentException.class); + + // Disjoint + final ProjectedCRS nadUtm = CommonCRS.NAD27.universal(32, 37); + final ProjectedCRS wgsUtm = CommonCRS.WGS84.universal(-2, 4); + + point.setUserData(nadUtm); + ring.setUserData(wgsUtm); + expectFailFast(() -> intersects(geomName, lring).evaluate(f), IllegalArgumentException.class); + expectFailFast(() -> intersects(lPoint, lring).evaluate(null), IllegalArgumentException.class); + + // TODO: activate back after fixing CRS.suggestCommonTarget + // utm domain contained in CRS:84 +// ring.setUserData(CommonCRS.defaultGeographic()); +// assertTrue("Intersection should be found when CRS are compatible", intersects(geomName, lring).evaluate(f)); +// assertTrue("Intersection should be found when CRS are compatible", intersects(lPoint, lring).evaluate(null)); + + // Common base CRS +// ring.setUserData(CommonCRS.WGS84.universal(0, 0)); +// point.setUserData(CommonCRS.WGS84.universal(7, 8)); +// assertTrue("Intersection should be found when CRS are compatible", intersects(geomName, lring).evaluate(f)); +// assertTrue("Intersection should be found when CRS are compatible", intersects(lPoint, lring).evaluate(null)); + } + + private static ST_Intersects intersects(final Expression left, Expression right) { + return new ST_Intersects(new Expression[]{left, right}); } /** diff --git a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java index 7aa7a44..f49d481 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java +++ b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java @@ -194,7 +194,7 @@ public abstract strictfp class GeometriesTestCase extends TestCase { expectFailFast(() -> factory.tryConvertToGeometry(wrapped3d, NONE), IllegalArgumentException.class); } - private static void expectFailFast(Callable whichMustFail, Class<? extends Exception>... expectedErrorTypes) { + public static void expectFailFast(Callable whichMustFail, Class<? extends Exception>... expectedErrorTypes) { try { final Object result = whichMustFail.call(); fail("Fail fast expected, but successfully returned "+result);
