sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] branch geoapi-4.0 updated: Filter : fix ST_Point and ST_LineString not parsing crs when integer or string
Date Wed, 01 Apr 2020 09:48:57 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 46059c2  Filter : fix ST_Point and ST_LineString not parsing crs when integer or
string
46059c2 is described below

commit 46059c23d106b634a80acb18a40c635a109f54de
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Wed Apr 1 11:48:27 2020 +0200

    Filter : fix ST_Point and ST_LineString not parsing crs when integer or string
---
 .../filter/sqlmm/AbstractGeomConstructor.java      | 26 +++++++++++++
 .../sis/internal/filter/sqlmm/ST_LineString.java   | 19 +++++++---
 .../apache/sis/internal/filter/sqlmm/ST_Point.java | 11 +++++-
 .../sis/internal/filter/sqlmm/SQLMMTest.java       | 43 ++++++++++++----------
 4 files changed, 72 insertions(+), 27 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractGeomConstructor.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractGeomConstructor.java
index dec365d..2656759 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractGeomConstructor.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractGeomConstructor.java
@@ -19,9 +19,12 @@ package org.apache.sis.internal.filter.sqlmm;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.feature.builder.PropertyTypeBuilder;
 import org.apache.sis.internal.filter.FilterGeometryUtils;
+import org.apache.sis.referencing.CRS;
 import org.locationtech.jts.geom.Geometry;
 import org.opengis.feature.FeatureType;
 import org.opengis.filter.expression.Expression;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.util.FactoryException;
 
 /**
  *
@@ -57,7 +60,9 @@ public abstract class AbstractGeomConstructor extends AbstractSpatialFunction
{
         final Geometry geom = FilterGeometryUtils.toGeometry(candidate, parameters.get(0));
 
         if (parameters.size() == 2) {
+            final CoordinateReferenceSystem crs = toCrs(candidate,  parameters.get(1));
             geom.setSRID(((Number) parameters.get(1).evaluate(candidate)).intValue());
+            geom.setUserData(crs);
         } else if (parameters.size() > 2) {
             warning(new Exception("Unexpected number of arguments : " + parameters.size()));
             return null;
@@ -75,4 +80,25 @@ public abstract class AbstractGeomConstructor extends AbstractSpatialFunction
{
     public PropertyTypeBuilder expectedType(FeatureType valueType, FeatureTypeBuilder addTo)
{
         return addTo.addAttribute(getExpectedClass()).setName(getName());
     }
+
+    private CoordinateReferenceSystem toCrs(Object candidate, Expression exp) {
+        Object cdt = exp.evaluate(candidate);
+        if (cdt instanceof Number) {
+            try {
+                cdt = CRS.forCode("EPSG:" + ((Number) cdt).intValue());
+            } catch (FactoryException ex) {
+                warning(ex);
+            }
+        } else if (cdt instanceof String) {
+            try {
+                cdt = CRS.forCode((String) cdt);
+            } catch (FactoryException ex) {
+                warning(ex);
+            }
+        }
+        if (cdt instanceof CoordinateReferenceSystem) {
+            return (CoordinateReferenceSystem) cdt;
+        }
+        return null;
+    }
 }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_LineString.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_LineString.java
index c7bb0a1..d18d452 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_LineString.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_LineString.java
@@ -24,11 +24,11 @@ import java.util.List;
 import org.apache.sis.feature.builder.AttributeTypeBuilder;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.feature.builder.PropertyTypeBuilder;
-import org.apache.sis.internal.filter.NamedFunction;
 import org.apache.sis.internal.feature.FeatureExpression;
 import org.apache.sis.internal.filter.FilterGeometryUtils;
 import static org.apache.sis.internal.filter.FilterGeometryUtils.getWKBReader;
 import static org.apache.sis.internal.filter.FilterGeometryUtils.getWKTReader;
+import org.apache.sis.internal.filter.NamedFunction;
 import org.apache.sis.referencing.CRS;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.LineString;
@@ -82,7 +82,7 @@ final class ST_LineString extends NamedFunction implements FeatureExpression
{
         }
 
         if (this.parameters.size() > 1) {
-            constantCrs = getCrs(this.parameters.get(1), null);
+            constantCrs = toCrs(this.parameters.get(1), null);
         }
     }
 
@@ -98,7 +98,7 @@ final class ST_LineString extends NamedFunction implements FeatureExpression
{
     public Object evaluate(Object object) {
         CoordinateReferenceSystem crs = constantCrs;
         if (crs == null && parameters.size() > 1) {
-            crs = getCrs(parameters.get(1), object);
+            crs = toCrs(object, parameters.get(1));
         }
 
         Object x = parameters.get(0).evaluate(object);
@@ -164,15 +164,22 @@ final class ST_LineString extends NamedFunction implements FeatureExpression
{
         return atb;
     }
 
-    private CoordinateReferenceSystem getCrs(Expression exp, Object candidate) {
+    private CoordinateReferenceSystem toCrs(Object candidate, Expression exp) {
         Object cdt = exp.evaluate(candidate);
         if (cdt instanceof Number) {
             try {
-                return CRS.forCode("EPSG:" + ((Number) cdt).intValue());
+                cdt = CRS.forCode("EPSG:" + ((Number) cdt).intValue());
             } catch (FactoryException ex) {
                 warning(ex);
             }
-        } else if (cdt instanceof CoordinateReferenceSystem) {
+        } else if (cdt instanceof String) {
+            try {
+                cdt = CRS.forCode((String) cdt);
+            } catch (FactoryException ex) {
+                warning(ex);
+            }
+        }
+        if (cdt instanceof CoordinateReferenceSystem) {
             return (CoordinateReferenceSystem) cdt;
         }
         return null;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Point.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Point.java
index 30d7175..32d4523 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Point.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Point.java
@@ -20,9 +20,9 @@ import java.math.BigDecimal;
 import org.apache.sis.feature.builder.AttributeTypeBuilder;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.feature.builder.PropertyTypeBuilder;
-import org.apache.sis.internal.filter.NamedFunction;
 import org.apache.sis.internal.feature.FeatureExpression;
 import org.apache.sis.internal.filter.FilterGeometryUtils;
+import org.apache.sis.internal.filter.NamedFunction;
 import org.apache.sis.referencing.CRS;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Geometry;
@@ -174,7 +174,14 @@ final class ST_Point extends NamedFunction implements FeatureExpression
{
             } catch (FactoryException ex) {
                 warning(ex);
             }
-        } else if (cdt instanceof CoordinateReferenceSystem) {
+        } else if (cdt instanceof String) {
+            try {
+                cdt = CRS.forCode((String) cdt);
+            } catch (FactoryException ex) {
+                warning(ex);
+            }
+        }
+        if (cdt instanceof CoordinateReferenceSystem) {
             return (CoordinateReferenceSystem) cdt;
         }
         return null;
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 13ae7b1..f6f8f32 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
@@ -17,18 +17,6 @@
 package org.apache.sis.internal.filter.sqlmm;
 
 import java.util.Arrays;
-import org.opengis.feature.Feature;
-import org.opengis.feature.FeatureType;
-import org.opengis.filter.FilterFactory;
-import org.opengis.filter.expression.Expression;
-import org.opengis.filter.expression.Function;
-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.GeographicCRS;
-import org.opengis.referencing.crs.ProjectedCRS;
-
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.filter.DefaultFilterFactory;
 import org.apache.sis.geometry.GeneralEnvelope;
@@ -37,7 +25,10 @@ import org.apache.sis.referencing.CRS;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.test.TestCase;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import org.junit.Test;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Geometry;
@@ -45,11 +36,17 @@ import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.LineString;
 import org.locationtech.jts.geom.Point;
 import org.locationtech.jts.geom.Polygon;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.opengis.test.Assert.assertEquals;
+import org.opengis.feature.Feature;
+import org.opengis.feature.FeatureType;
+import org.opengis.filter.FilterFactory;
+import org.opengis.filter.expression.Expression;
+import org.opengis.filter.expression.Function;
+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.GeographicCRS;
+import org.opengis.referencing.crs.ProjectedCRS;
 import static org.opengis.test.Assert.assertInstanceOf;
 
 
@@ -326,13 +323,21 @@ public final strictfp class SQLMMTest extends TestCase {
         /*
          * Execute the function and check the result.
          */
-        final Point result = evaluate(Point.class, null, factory.function("ST_Point",
+        Point result = evaluate(Point.class, null, factory.function("ST_Point",
                 factory.literal(10.0),
                 factory.literal(20.0),
                 factory.literal(HardCodedCRS.WGS84)));
         assertEquals("userData", HardCodedCRS.WGS84, result.getUserData());
         assertEquals(10.0, result.getX(), STRICT);
         assertEquals(20.0, result.getY(), STRICT);
+
+        result = evaluate(Point.class, null, factory.function("ST_Point",
+                factory.literal(10.0),
+                factory.literal(20.0),
+                factory.literal("CRS:84")));
+        assertEquals("userData", HardCodedCRS.WGS84, result.getUserData());
+        assertEquals(10.0, result.getX(), STRICT);
+        assertEquals(20.0, result.getY(), STRICT);
     }
 
     /**


Mime
View raw message