sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1829094 - in /sis/branches/JDK8: ./ core/sis-feature/ core/sis-feature/src/main/java/org/apache/sis/internal/feature/ core/sis-utility/src/main/java/org/apache/sis/setup/ ide-project/NetBeans/nbproject/ storage/sis-storage/src/main/java/or...
Date Fri, 13 Apr 2018 18:45:24 GMT
Author: desruisseaux
Date: Fri Apr 13 18:45:24 2018
New Revision: 1829094

URL: http://svn.apache.org/viewvc?rev=1829094&view=rev
Log:
Now that the Java Topology Suite (JTS) is available under Eclipse Distribution License 1.0
(a BSD-style license), replace Java reflection by direct call to JTS methods.
The JTS library stay optional, as well as the ESRI library. Apache SIS fallbacks on Java2D
if neither JTS or ESRI library is available on the classpath.

Modified:
    sis/branches/JDK8/core/sis-feature/pom.xml
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java
    sis/branches/JDK8/ide-project/NetBeans/nbproject/project.properties
    sis/branches/JDK8/pom.xml
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java

Modified: sis/branches/JDK8/core/sis-feature/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/pom.xml?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/pom.xml (original)
+++ sis/branches/JDK8/core/sis-feature/pom.xml Fri Apr 13 18:45:24 2018
@@ -124,6 +124,11 @@
       <artifactId>esri-geometry-api</artifactId>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.locationtech.jts</groupId>
+      <artifactId>jts-core</artifactId>
+      <optional>true</optional>
+    </dependency>
 
     <!-- Test dependencies -->
     <dependency>

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
[UTF-8] Fri Apr 13 18:45:24 2018
@@ -33,8 +33,7 @@ import org.apache.sis.util.Classes;
 
 /**
  * Centralizes some usages of ESRI geometry API by Apache SIS.
- * We use this class for isolating dependencies from the {@code org.apache.feature} package
- * to ESRI's API or to Java Topology Suite (JTS) API.
+ * We use this class for isolating dependencies from the {@code org.apache.feature} package
to ESRI's API.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -51,7 +50,7 @@ final class ESRI extends Geometries<Geom
     }
 
     /**
-     * If the given object is a JTS geometry, returns a short string representation the class
name.
+     * If the given object is an ESRI geometry, returns a short string representation the
class name.
      */
     @Override
     final String tryGetLabel(Object geometry) {
@@ -147,7 +146,7 @@ final class ESRI extends Geometries<Geom
     /**
      * Merges a sequence of points or paths if the first instance is an implementation of
this library.
      *
-     * @throws ClassCastException if an element in the iterator is not a JTS geometry.
+     * @throws ClassCastException if an element in the iterator is not an ESRI geometry.
      */
     @Override
     final Geometry tryMergePolylines(Object next, final Iterator<?> polylines) {

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
[UTF-8] Fri Apr 13 18:45:24 2018
@@ -17,9 +17,13 @@
 package org.apache.sis.internal.feature;
 
 import java.util.Iterator;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
+import org.locationtech.jts.geom.Point;
+import org.locationtech.jts.geom.Polygon;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.LineString;
+import org.locationtech.jts.geom.Envelope;
 import org.apache.sis.geometry.GeneralEnvelope;
+import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.math.Vector;
 import org.apache.sis.util.Classes;
 
@@ -31,35 +35,16 @@ import org.apache.sis.util.Classes;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.7
  * @module
- *
- * @todo avoid use of reflection and use JTS API directly after JTS released
- *       a new version of the library under BSD-like license.
  */
-final class JTS extends Geometries<Object> {
-    /**
-     * Getter methods on JTS envelopes.
-     * Each methods take no argument and return a {@code double} value.
-     */
-    private final Method getEnvelopeInternal, getMinX, getMinY, getMaxX, getMaxY;
-
+final class JTS extends Geometries<Geometry> {
     /**
      * Creates the singleton instance.
      */
     JTS() throws ClassNotFoundException, NoSuchMethodException {
-        super(/*GeometryLibrary.JTS, */ null,                               // TODO
-              (Class) Class.forName("com.vividsolutions.jts.geom.Geometry"),    // TODO
-              Class.forName("com.vividsolutions.jts.geom.Point"),
-              Class.forName("com.vividsolutions.jts.geom.LineString"),
-              Class.forName("com.vividsolutions.jts.geom.Polygon"));
-        getEnvelopeInternal = rootClass.getMethod("getEnvelopeInternal", (Class[]) null);
-        final Class<?> envt = getEnvelopeInternal.getReturnType();
-        getMinX = envt.getMethod("getMinX", (Class[]) null);
-        getMinY = envt.getMethod("getMinY", (Class[]) null);
-        getMaxX = envt.getMethod("getMaxX", (Class[]) null);
-        getMaxY = envt.getMethod("getMaxY", (Class[]) null);
+        super(GeometryLibrary.JTS, Geometry.class, Point.class, LineString.class, Polygon.class);
     }
 
     /**
@@ -67,7 +52,7 @@ final class JTS extends Geometries<Objec
      */
     @Override
     final String tryGetLabel(Object geometry) {
-        return (rootClass.isInstance(geometry)) ? Classes.getShortClassName(geometry) : null;
+        return (geometry instanceof Geometry) ? Classes.getShortClassName(geometry) : null;
     }
 
     /**
@@ -80,31 +65,14 @@ final class JTS extends Geometries<Objec
      */
     @Override
     final GeneralEnvelope tryGetEnvelope(final Object geometry) {
-        final double xmin, ymin, xmax, ymax;
-        if (rootClass.isInstance(geometry)) {
-            try {
-                final Object env = getEnvelopeInternal.invoke(geometry, (Object[]) null);
-                xmin = (Double) getMinX.invoke(env, (Object[]) null);
-                ymin = (Double) getMinY.invoke(env, (Object[]) null);
-                xmax = (Double) getMaxX.invoke(env, (Object[]) null);
-                ymax = (Double) getMaxY.invoke(env, (Object[]) null);
-            } catch (ReflectiveOperationException e) {
-                if (e instanceof InvocationTargetException) {
-                    final Throwable cause = e.getCause();
-                    if (cause instanceof RuntimeException) {
-                        throw (RuntimeException) cause;
-                    }
-                    if (cause instanceof Error) {
-                        throw (Error) cause;
-                    }
-                }
-                // Should never happen unless JTS's API changed.
-                throw (Error) new IncompatibleClassChangeError(e.toString()).initCause(e);
-            }
+        if (geometry instanceof Geometry) {
+            final Envelope bounds = ((Geometry) geometry).getEnvelopeInternal();
             final GeneralEnvelope env = new GeneralEnvelope(2);
-            env.setRange(0, xmin, xmax);
-            env.setRange(1, ymin, ymax);
-            return env;
+            env.setRange(0, bounds.getMinX(), bounds.getMaxX());
+            env.setRange(1, bounds.getMinY(), bounds.getMaxY());
+            if (!env.isEmpty()) {
+                return env;
+            }
         }
         return null;
     }
@@ -132,7 +100,7 @@ final class JTS extends Geometries<Objec
      * The implementation returned by this method must be an instance of {@link #rootClass}.
      */
     @Override
-    public Object createPolyline(final int dimension, final Vector... ordinates) {
+    public Geometry createPolyline(final int dimension, final Vector... ordinates) {
         // TODO - see class javadoc
         throw unsupported(dimension);
     }
@@ -143,7 +111,7 @@ final class JTS extends Geometries<Objec
      * @throws ClassCastException if an element in the iterator is not a JTS geometry.
      */
     @Override
-    final Object tryMergePolylines(final Object first, final Iterator<?> polylines)
{
+    final Geometry tryMergePolylines(final Object first, final Iterator<?> polylines)
{
         throw unsupported(2);   // TODO - see class javadoc
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
[UTF-8] Fri Apr 13 18:45:24 2018
@@ -31,8 +31,7 @@ import org.apache.sis.util.Classes;
 
 /**
  * Centralizes usages of some (not all) Java2D geometry API by Apache SIS.
- * We use this class for isolating dependencies from the {@code org.apache.feature} package
- * to ESRI's API or to Java Topology Suite (JTS) API.
+ * We use this class for isolating dependencies from the {@code org.apache.feature} package
to Java2D API.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
[UTF-8] Fri Apr 13 18:45:24 2018
@@ -28,7 +28,7 @@ import org.opengis.metadata.acquisition.
  * All those libraries are optional.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  *
  * @see OptionKey#GEOMETRY_LIBRARY
  * @see org.apache.sis.feature.builder.FeatureTypeBuilder#addAttribute(GeometryType)
@@ -53,7 +53,7 @@ public enum GeometryLibrary {
      *
      * @see <a href="http://locationtech.github.io/jts/">JTS home page</a>
      */
-//  JTS,
+    JTS,
 
     /**
      * The ESRI geometry API library. This library can be used for spatial vector data processing.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java
[UTF-8] Fri Apr 13 18:45:24 2018
@@ -23,7 +23,7 @@
  * is created.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */

Modified: sis/branches/JDK8/ide-project/NetBeans/nbproject/project.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/nbproject/project.properties?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/nbproject/project.properties [ISO-8859-1] (original)
+++ sis/branches/JDK8/ide-project/NetBeans/nbproject/project.properties [ISO-8859-1] Fri Apr
13 18:45:24 2018
@@ -101,7 +101,8 @@ project.GeoAPI       = ../../../../GeoAP
 #
 jsr363.version       = 1.0
 jama.version         = 1.0.3
-geometry.version     = 2.0.0
+esri.api.version     = 2.1.0
+jts.version          = 1.15.0
 georss.version       = 0.9.8
 rome.version         = 0.9
 jdom1.version        = 1.0
@@ -130,7 +131,8 @@ endorsed.classpath=
 javac.classpath=\
     ${project.GeoAPI}/dist/geoapi.jar:\
     ${maven.repository}/javax/measure/unit-api/${jsr363.version}/unit-api-${jsr363.version}.jar:\
-    ${maven.repository}/com/esri/geometry/esri-geometry-api/${geometry.version}/esri-geometry-api-${geometry.version}.jar:\
+    ${maven.repository}/com/esri/geometry/esri-geometry-api/${esri.api.version}/esri-geometry-api-${esri.api.version}.jar:\
+    ${maven.repository}/org/locationtech/jts/jts-core/${jts.version}/jts-core-${jts.version}.jar:\
     ${maven.repository}/org/geonames/georss-rome/${georss.version}/georss-rome-${georss.version}.jar:\
     ${maven.repository}/rome/rome/${rome.version}/rome-${rome.version}.jar:\
     ${maven.repository}/jdom/jdom/${jdom1.version}/jdom-${jdom1.version}.jar:\

Modified: sis/branches/JDK8/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Fri Apr 13 18:45:24 2018
@@ -415,7 +415,13 @@
       <dependency>
         <groupId>com.esri.geometry</groupId>
         <artifactId>esri-geometry-api</artifactId>
-        <version>2.0.0</version>
+        <version>2.1.0</version>
+        <optional>true</optional>
+      </dependency>
+      <dependency>
+        <groupId>org.locationtech.jts</groupId>
+        <artifactId>jts-core</artifactId>
+        <version>1.15.0</version>
         <optional>true</optional>
       </dependency>
       <dependency>

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java?rev=1829094&r1=1829093&r2=1829094&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java
[UTF-8] Fri Apr 13 18:45:24 2018
@@ -67,6 +67,8 @@ public abstract class AbstractProvider e
      *     mimeForNameSpaces.put("http://www.isotc211.org/2005/gmd",      "application/vnd.iso.19139+xml");
      *     mimeForNameSpaces.put("http://www.opengis.net/cat/csw/2.0.2",  "application/vnd.ogc.csw_xml");
      * }</div>
+     *
+     * @todo replace by {@code Map.of(…)} on JDK9 branch.
      */
     protected final Map<String,String> mimeForNameSpaces;
 
@@ -78,6 +80,8 @@ public abstract class AbstractProvider e
      * public MyDataStore() {
      *     mimeForRootElements.put("MD_Metadata", "application/vnd.iso.19139+xml");
      * }</div>
+     *
+     * @todo replace by {@code Map.of(…)} on JDK9 branch.
      */
     protected final Map<String,String> mimeForRootElements;
 



Mime
View raw message