This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 7a046b8e33a33104bc8abd15f3e0553a8b923d1c Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Nov 9 14:41:33 2021 +0100 Filter: fix ST_GeomFromText evaluation (cherry-pick from Johann Sorel fix). --- .../sis/internal/filter/sqlmm/GeometryParser.java | 2 +- .../sis/internal/filter/sqlmm/SQLMMTest.java | 38 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/GeometryParser.java b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/GeometryParser.java index c5fb84d..1678f6f 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/GeometryParser.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/GeometryParser.java @@ -113,7 +113,7 @@ abstract class GeometryParser<R,G> extends GeometryConstructor<R,G> { result.setCoordinateReferenceSystem(crs); } } - return geometry; + return result.implementation(); } catch (Exception e) { warning(e, false); } diff --git a/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java b/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java index 04bd541..05966c0 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java @@ -16,22 +16,41 @@ */ package org.apache.sis.internal.filter.sqlmm; +import org.opengis.feature.Feature; +import org.opengis.filter.Expression; +import org.opengis.filter.FilterFactory; +import org.locationtech.jts.geom.Polygon; +import org.apache.sis.filter.DefaultFilterFactory; +import org.apache.sis.referencing.CommonCRS; import org.apache.sis.test.TestCase; import org.junit.Test; -import static org.junit.Assert.*; +import static org.opengis.test.Assert.*; /** * Apply some validation on the {@link SQLMM} enumeration. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @author Johann Sorel (Geomatys) + * @version 1.2 * @since 1.1 * @module */ public final strictfp class SQLMMTest extends TestCase { /** + * The factory to use for creating the objects to test. + */ + private final FilterFactory<Feature,Object,?> factory; + + /** + * Creates a new test case. + */ + public SQLMMTest() { + factory = DefaultFilterFactory.forFeatures(); + } + + /** * Verifies the consistency of parameter count. */ @Test @@ -43,4 +62,19 @@ public final strictfp class SQLMMTest extends TestCase { assertTrue(name, value.geometryCount() <= value.maxParamCount); } } + + /** + * Tests {@link FilterFactory#function(String, Expression, Expression)} + * for function {@code ST_GeomFromText}. + */ + @Test + public void testST_GeomFromText() { + final String wkt = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"; + final Expression<Feature,?> exp = factory.function("ST_GeomFromText", factory.literal(wkt), factory.literal(4326)); + final Object value = exp.apply(null); + assertInstanceOf("Expected JTS implementation.", Polygon.class, value); + final Polygon polygon = (Polygon) value; + assertEquals(wkt, polygon.toText()); + assertEquals(CommonCRS.WGS84.geographic(), polygon.getUserData()); + } }