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 2535fd14d0d8fe24f20bd9a70d9ed9fc75202696
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Tue Jan 8 16:09:26 2019 +0100

    Make 'findCoordinateReferenceSystem' more library-independent.
---
 .../apache/sis/internal/feature/Geometries.java    | 32 ++++++++
 .../java/org/apache/sis/internal/feature/JTS.java  | 92 ++++++++++++----------
 .../sis/internal/feature/GeometriesTestCase.java   |  2 +-
 .../org/apache/sis/internal/feature/JTSTest.java   | 43 +++++-----
 ide-project/NetBeans/nbproject/project.properties  |  4 +-
 pom.xml                                            |  4 +-
 6 files changed, 106 insertions(+), 71 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
index 4572e9f..0d6beae 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
@@ -19,6 +19,8 @@ package org.apache.sis.internal.feature;
 import java.util.Iterator;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.geometry.GeneralEnvelope;
@@ -161,6 +163,8 @@ public abstract class Geometries<G> {
      *         or {@code null} if the given object is not a recognized 
implementation.
      *
      * @see #createPoint(double, double)
+     *
+     * @see #getCoordinateReferenceSystem(Object)
      */
     public static double[] getCoordinate(final Object point) {
         for (Geometries<?> g = implementation; g != null; g = g.fallback) {
@@ -293,6 +297,34 @@ public abstract class Geometries<G> {
     public abstract Object parseWKT(String wkt) throws Exception;
 
     /**
+     * If the given geometry is an implementation of this library, returns its 
coordinate reference system.
+     * Otherwise returns {@code null}.
+     *
+     * @param  geometry  the geometry from which to get the CRS.
+     * @return the coordinate reference system, or {@code null} if none.
+     * @throws FactoryException if the CRS can not be created from the SRID 
code.
+     */
+    CoordinateReferenceSystem tryGetCoordinateReferenceSystem(Object geometry) 
throws FactoryException {
+        return null;
+    }
+
+    /**
+     * If the given object is one of the recognized geometry implementations, 
gets its Coordinate Reference System (CRS).
+     * Otherwise returns {@code null}.
+     *
+     * @param  geometry  the geometry from which to get the CRS.
+     * @return the coordinate reference system, or {@code null} if none.
+     * @throws FactoryException if the CRS can not be created from the SRID 
code.
+     */
+    public static CoordinateReferenceSystem getCoordinateReferenceSystem(final 
Object geometry) throws FactoryException {
+        for (Geometries<?> g = implementation; g != null; g = g.fallback) {
+            CoordinateReferenceSystem crs = 
g.tryGetCoordinateReferenceSystem(geometry);
+            if (crs != null) return crs;
+        }
+        return null;
+    }
+
+    /**
      * Returns an error message for an unsupported geometry object.
      *
      * @param  dimension  number of dimensions (2 or 3) requested for the 
geometry object.
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
index 0471784..27879af 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
@@ -21,6 +21,11 @@ import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.TransformException;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Point;
 import org.locationtech.jts.geom.Polygon;
@@ -36,14 +41,8 @@ import 
org.apache.sis.internal.feature.jts.GeometryCoordinateTransform;
 import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.math.Vector;
 import org.apache.sis.referencing.CRS;
-import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Utilities;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.operation.CoordinateOperation;
-import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.TransformException;
-import org.opengis.util.FactoryException;
 
 
 /**
@@ -58,11 +57,11 @@ import org.opengis.util.FactoryException;
  * @module
  */
 public final class JTS extends Geometries<Geometry> {
-
     /**
-     * Key use in Geometry userData Map to store an instanceof 
CoordinateReferenceSystem.
+     * Key used in {@linkplain Geometry#getUserData() user data} map for 
storing
+     * an instance of {@link CoordinateReferenceSystem}.
      */
-    public static final String KEY_CRS = "crs";
+    public static final String CRS_KEY = "CRS";
 
     /**
      * The factory to use for creating JTS geometries. Currently set to a 
factory using
@@ -137,6 +136,8 @@ public final class JTS extends Geometries<Geometry> {
 
     /**
      * Creates a two-dimensional point from the given coordinate.
+     *
+     * @return the point for the given ordinate values.
      */
     @Override
     public Object createPoint(final double x, final double y) {
@@ -147,6 +148,8 @@ public final class JTS extends Geometries<Geometry> {
      * Creates a polyline from the given ordinate values.
      * Each {@link Double#NaN} ordinate value start a new path.
      * The implementation returned by this method must be an instance of 
{@link #rootClass}.
+     *
+     * @return the geometric object for the given points.
      */
     @Override
     public Geometry createPolyline(final int dimension, final Vector... 
ordinates) {
@@ -260,6 +263,9 @@ public final class JTS extends Geometries<Geometry> {
 
     /**
      * Parses the given WKT.
+     *
+     * @return the geometry object for the given WKT.
+     * @throws ParseException if the WKT can not be parsed.
      */
     @Override
     public Object parseWKT(final String wkt) throws ParseException {
@@ -267,42 +273,44 @@ public final class JTS extends Geometries<Geometry> {
     }
 
     /**
-     * Extract CoordinateReferenceSystem from given geometry.
-     * <p>
-     * This method expect the CoordinateReferenceSystem to be store in one
-     * the following ways :
-     * </p>
+     * Gets the Coordinate Reference System (CRS) from the given geometry.
+     * This method expects the CRS to be stored in one the following ways:
+     *
      * <ul>
-     *   <li>Geometry UserData value is a CoordinateReferenceSystem</li>
-     *   <li>Geometry UserData value is a Map with a value for key 'crs'</li>
-     *   <li>Geometry SRID is positive, interpreted as an EPSG code</li>
+     *   <li>Geometry {@linkplain Geometry#getUserData() user data} is an 
instance of {@code CoordinateReferenceSystem}.</li>
+     *   <li>{@linkplain Geometry#getUserData() user data} is a (@link Map} 
with a value for the {@value #CRS_KEY} key.</li>
+     *   <li>Geometry SRID is strictly positive, in which case it is 
interpreted as an EPSG code.</li>
      * </ul>
-     * <p>
-     * If none of the above is valid, null is returned.
-     * </p>
      *
-     * @param geometry source geometry
-     * @return CoordinateReferenceSystem or null
-     * @throws org.opengis.util.FactoryException
+     * If none of the above is valid, {@code null} is returned.
+     *
+     * @param  geometry the geometry from which to get the CRS.
+     * @return the coordinate reference system, or {@code null} if none.
+     * @throws FactoryException if the CRS can not be created from the SRID 
code.
      */
-    public static CoordinateReferenceSystem 
findCoordinateReferenceSystem(Geometry geometry) throws FactoryException {
-        Object userData = geometry.getUserData();
-        if (userData instanceof CoordinateReferenceSystem) {
-            return (CoordinateReferenceSystem) userData;
-        } else if (userData instanceof Map) {
-            final Map map = (Map) userData;
-            final Object value = map.get(KEY_CRS);
-            if (value instanceof CoordinateReferenceSystem) {
-                return (CoordinateReferenceSystem) value;
+    @Override
+    CoordinateReferenceSystem tryGetCoordinateReferenceSystem(final Object 
geometry) throws FactoryException {
+        if (geometry instanceof Geometry) {
+            final Geometry jts = (Geometry) geometry;
+            final Object userData = jts.getUserData();
+            if (userData instanceof CoordinateReferenceSystem) {
+                return (CoordinateReferenceSystem) userData;
+            } else if (userData instanceof Map<?,?>) {
+                final Map<?,?> map = (Map<?,?>) userData;
+                final Object value = map.get(CRS_KEY);
+                if (value instanceof CoordinateReferenceSystem) {
+                    return (CoordinateReferenceSystem) value;
+                }
+            }
+            /*
+             * Fallback on SRID.
+             */
+            final int srid = jts.getSRID();
+            if (srid > 0) {
+                return CRS.forCode("EPSG:" + srid);
             }
         }
-
-        //fallback on SRID
-        int srid = geometry.getSRID();
-        if (srid > 0) {
-            return CRS.forCode("EPSG:"+srid);
-        }
-        return null;
+        return super.tryGetCoordinateReferenceSystem(geometry);
     }
 
     /**
@@ -323,12 +331,12 @@ public final class JTS extends Geometries<Geometry> {
      * @throws org.opengis.util.FactoryException
      */
     public static Geometry transform(Geometry geometry, 
CoordinateReferenceSystem targetCrs)
-            throws TransformException, FactoryException {
+            throws TransformException, FactoryException
+    {
         if (geometry == null || targetCrs == null) {
             return geometry;
         }
-
-        final CoordinateReferenceSystem sourceCrs = 
findCoordinateReferenceSystem(geometry);
+        final CoordinateReferenceSystem sourceCrs = 
getCoordinateReferenceSystem(geometry);
         if (sourceCrs == null) {
             throw new TransformException("Geometry CRS is undefined");
         } else if (Utilities.equalsIgnoreMetadata(sourceCrs, targetCrs)) {
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 4105b5a..a6bb921 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
@@ -39,7 +39,7 @@ public abstract strictfp class GeometriesTestCase extends 
TestCase {
     /**
      * The factory to test.
      */
-    private final Geometries<?> factory;
+    final Geometries<?> factory;
 
     /**
      * The geometry created by the test. Provided for allowing sub-classes to 
perform additional verifications.
diff --git 
a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java 
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
index c26f1b6..4fedb0f 100644
--- 
a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
+++ 
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
@@ -16,37 +16,32 @@
  */
 package org.apache.sis.internal.feature;
 
-import java.awt.geom.AffineTransform;
 import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
-import org.apache.sis.referencing.CommonCRS;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.operation.TransformException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.locationtech.jts.geom.Point;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Geometry;
 import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.MultiLineString;
+import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
 import org.junit.Test;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.util.FactoryException;
 
 import static org.junit.Assert.*;
-import org.locationtech.jts.geom.Point;
-import org.opengis.referencing.operation.TransformException;
 
 
 /**
  * Tests {@link JTS} implementation.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
 public final strictfp class JTSTest extends GeometriesTestCase {
-
-    private static final double DELTA = 0.0000001;
-
     /**
      * Creates a new test case.
      */
@@ -101,28 +96,30 @@ public final strictfp class JTSTest extends 
GeometriesTestCase {
     }
 
     /**
-     * Tests {@link 
JTS#findCoordinateReferenceSystem(org.locationtech.jts.geom.Geometry) }.
+     * Tests {@link JTS#tryGetCoordinateReferenceSystem(Object)}.
+     *
+     * @throws FactoryException if an EPSG code can not be resolved.
      */
     @Test
-    public void testFindCoordinateReferenceSystem() throws FactoryException {
+    public void testGetCoordinateReferenceSystem() throws FactoryException {
         final GeometryFactory gf = new GeometryFactory();
         final Geometry geometry = gf.createPoint(new Coordinate(5, 6));
 
-        CoordinateReferenceSystem crs = 
JTS.findCoordinateReferenceSystem(geometry);
+        CoordinateReferenceSystem crs = 
factory.tryGetCoordinateReferenceSystem(geometry);
         assertNull(crs);
 
-        // test crs as user data
+        // Test CRS as user data.
         geometry.setUserData(CommonCRS.ED50.geographic());
-        assertEquals(CommonCRS.ED50.geographic(), 
JTS.findCoordinateReferenceSystem(geometry));
+        assertEquals(CommonCRS.ED50.geographic(), 
factory.tryGetCoordinateReferenceSystem(geometry));
 
-        // test crs as map value
-        geometry.setUserData(Collections.singletonMap("crs", 
CommonCRS.NAD83.geographic()));
-        assertEquals(CommonCRS.NAD83.geographic(), 
JTS.findCoordinateReferenceSystem(geometry));
+        // Test CRS as map value.
+        geometry.setUserData(Collections.singletonMap(JTS.CRS_KEY, 
CommonCRS.NAD83.geographic()));
+        assertEquals(CommonCRS.NAD83.geographic(), 
factory.tryGetCoordinateReferenceSystem(geometry));
 
-        // test crs as srid
+        // Test CRS as srid.
         geometry.setUserData(null);
         geometry.setSRID(4326);
-        assertEquals(CommonCRS.WGS84.geographic(), 
JTS.findCoordinateReferenceSystem(geometry));
+        assertEquals(CommonCRS.WGS84.geographic(), 
factory.tryGetCoordinateReferenceSystem(geometry));
     }
 
     /**
@@ -158,7 +155,5 @@ public final strictfp class JTSTest extends 
GeometriesTestCase {
         assertEquals(15.0, ((Point) out).getX(), 0.0);
         assertEquals(26.0, ((Point) out).getY(), 0.0);
         assertEquals(CommonCRS.WGS84.normalizedGeographic(), 
out.getUserData());
-
     }
-
 }
diff --git a/ide-project/NetBeans/nbproject/project.properties 
b/ide-project/NetBeans/nbproject/project.properties
index 3746e8e..9b386c3 100644
--- a/ide-project/NetBeans/nbproject/project.properties
+++ b/ide-project/NetBeans/nbproject/project.properties
@@ -107,8 +107,8 @@ project.GeoAPI       = 
../../../../GeoAPI/master/ide-project/NetBeans
 #
 jsr363.version       = 1.0
 jama.version         = 1.0.3
-esri.api.version     = 2.1.0
-jts.version          = 1.15.0
+esri.api.version     = 2.2.2
+jts.version          = 1.16.0
 georss.version       = 0.9.8
 rome.version         = 0.9
 jdom1.version        = 1.0
diff --git a/pom.xml b/pom.xml
index 80ec310..51daaeb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -426,13 +426,13 @@
       <dependency>
         <groupId>com.esri.geometry</groupId>
         <artifactId>esri-geometry-api</artifactId>
-        <version>2.2.0</version>
+        <version>2.2.2</version>
         <optional>true</optional>
       </dependency>
       <dependency>
         <groupId>org.locationtech.jts</groupId>
         <artifactId>jts-core</artifactId>
-        <version>1.15.1</version>
+        <version>1.16.0</version>
         <optional>true</optional>
       </dependency>
       <dependency>

Reply via email to