Author: desruisseaux
Date: Sat Apr 14 12:54:01 2018
New Revision: 1829137

URL: http://svn.apache.org/viewvc?rev=1829137&view=rev
Log:
Complete the geometry factory backed by JTS and add tests.

Added:
    
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java
   (with props)
    
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
   (with props)
    
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
   (with props)
    
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java
   (with props)
Modified:
    
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/Geometries.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-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreFormat.java

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=1829137&r1=1829136&r2=1829137&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] Sat Apr 14 12:54:01 2018
@@ -23,6 +23,8 @@ import com.esri.core.geometry.MultiPath;
 import com.esri.core.geometry.Polyline;
 import com.esri.core.geometry.Polygon;
 import com.esri.core.geometry.Point;
+import com.esri.core.geometry.Point2D;
+import com.esri.core.geometry.Point3D;
 import com.esri.core.geometry.WktImportFlags;
 import com.esri.core.geometry.OperatorImportFromWkt;
 import org.apache.sis.geometry.GeneralEnvelope;
@@ -37,7 +39,7 @@ import org.apache.sis.util.Classes;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.7
  * @module
  */
@@ -50,7 +52,7 @@ final class ESRI extends Geometries<Geom
     }
 
     /**
-     * If the given object is an ESRI geometry, returns a short string 
representation the class name.
+     * If the given object is an ESRI geometry, returns a short string 
representation of the class name.
      */
     @Override
     final String tryGetLabel(Object geometry) {
@@ -99,6 +101,12 @@ final class ESRI extends Geometries<Geom
             coord[1] = pt.getY();
             coord[0] = pt.getX();
             return coord;
+        } else if (point instanceof Point2D) {
+            final Point2D pt = (Point2D) point;
+            return new double[] {pt.x, pt.y};
+        } else if (point instanceof Point3D) {
+            final Point3D pt = (Point3D) point;
+            return new double[] {pt.x, pt.y, pt.z};
         }
         return null;
     }
@@ -107,7 +115,8 @@ final class ESRI extends Geometries<Geom
      * Creates a two-dimensional point from the given coordinate.
      */
     @Override
-    public Object createPoint(double x, double y) {
+    public Object createPoint(final double x, final double y) {
+        // Need to explicitely set z to NaN because default value is 0.
         return new Point(x, y, Double.NaN);
     }
 
@@ -158,15 +167,18 @@ final class ESRI extends Geometries<Geom
         for (;; next = polylines.next()) {
             if (next != null) {
                 if (next instanceof Point) {
-                    final double x = ((Point) next).getX();
-                    final double y = ((Point) next).getY();
-                    if (Double.isNaN(x) || Double.isNaN(y)) {
+                    final Point pt = (Point) next;
+                    if (pt.isEmpty()) {
                         lineTo = false;
-                    } else if (lineTo) {
-                        path.lineTo(x, y);
                     } else {
-                        path.startPath(x, y);
-                        lineTo = true;
+                        final double x = ((Point) next).getX();
+                        final double y = ((Point) next).getY();
+                        if (lineTo) {
+                            path.lineTo(x, y);
+                        } else {
+                            path.startPath(x, y);
+                            lineTo = true;
+                        }
                     }
                 } else {
                     path.add((MultiPath) next, false);

Modified: 
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java?rev=1829137&r1=1829136&r2=1829137&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -37,7 +37,7 @@ import org.apache.sis.math.Vector;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.7
  * @module
  */
@@ -195,7 +195,7 @@ public abstract class Geometries<G> {
 
     /**
      * If the given geometry is the type supported by this {@code Geometries} 
instance,
-     * returns a short string representation the class name. Otherwise returns 
{@code null}.
+     * returns a short string representation of the class name. Otherwise 
returns {@code null}.
      */
     abstract String tryGetLabel(Object geometry);
 
@@ -288,8 +288,9 @@ public abstract class Geometries<G> {
      *
      * @param  wkt  the WKT to parse.
      * @return the geometry object for the given WKT.
+     * @throws Exception if the WKT can not be parsed. The exception sub-class 
depends on the implementation.
      */
-    public abstract Object parseWKT(String wkt);
+    public abstract Object parseWKT(String wkt) throws Exception;
 
     /**
      * Returns an error message for an unsupported geometry object.

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=1829137&r1=1829136&r2=1829137&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] Sat Apr 14 12:54:01 2018
@@ -16,12 +16,20 @@
  */
 package org.apache.sis.internal.feature;
 
+import java.util.List;
+import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Iterator;
+import org.locationtech.jts.geom.Coordinate;
 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.MultiLineString;
 import org.locationtech.jts.geom.Envelope;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.locationtech.jts.io.WKTReader;
+import org.locationtech.jts.io.ParseException;
 import org.apache.sis.geometry.GeneralEnvelope;
 import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.math.Vector;
@@ -41,14 +49,21 @@ import org.apache.sis.util.Classes;
  */
 final class JTS extends Geometries<Geometry> {
     /**
+     * The factory to use for creating JTS geometries. Currently set to a 
factory using
+     * double-precision floating point numbers and a spatial-reference ID of 0.
+     */
+    private final GeometryFactory factory;
+
+    /**
      * Creates the singleton instance.
      */
-    JTS() throws ClassNotFoundException, NoSuchMethodException {
+    JTS() {
         super(GeometryLibrary.JTS, Geometry.class, Point.class, 
LineString.class, Polygon.class);
+        factory = new GeometryFactory();            // Default to double 
precision and SRID of 0.
     }
 
     /**
-     * If the given object is a JTS geometry, returns a short string 
representation the class name.
+     * If the given object is a JTS geometry, returns a short string 
representation of the class name.
      */
     @Override
     final String tryGetLabel(Object geometry) {
@@ -83,15 +98,33 @@ final class JTS extends Geometries<Geome
      */
     @Override
     final double[] tryGetCoordinate(final Object point) {
-        return null;   // TODO - see class javadoc
+        final Coordinate pt;
+        if (point instanceof Point) {
+            pt = ((Point) point).getCoordinate();
+        } else if (point instanceof Coordinate) {
+            pt = (Coordinate) point;
+        } else {
+            return null;
+        }
+        final double z = pt.z;
+        final double[] coord;
+        if (Double.isNaN(z)) {
+            coord = new double[2];
+        } else {
+            coord = new double[3];
+            coord[2] = z;
+        }
+        coord[1] = pt.y;
+        coord[0] = pt.x;
+        return coord;
     }
 
     /**
      * Creates a two-dimensional point from the given coordinate.
      */
     @Override
-    public Object createPoint(double x, double y) {
-        throw unsupported(2);   // TODO - see class javadoc
+    public Object createPoint(final double x, final double y) {
+        return factory.createPoint(new Coordinate(x, y));
     }
 
     /**
@@ -101,8 +134,67 @@ final class JTS extends Geometries<Geome
      */
     @Override
     public Geometry createPolyline(final int dimension, final Vector... 
ordinates) {
-        // TODO - see class javadoc
-        throw unsupported(dimension);
+        final boolean is3D = (dimension == 3);
+        if (!is3D && dimension != 2) {
+            throw unsupported(dimension);
+        }
+        final List<Coordinate> coordinates = new ArrayList<>(32);
+        final List<LineString> lines = new ArrayList<>();
+        for (final Vector v : ordinates) {
+            if (v != null) {
+                final int size = v.size();
+                for (int i=0; i<size;) {
+                    final double x = v.doubleValue(i++);
+                    final double y = v.doubleValue(i++);
+                    if (!Double.isNaN(x) && !Double.isNaN(y)) {
+                        final Coordinate c;
+                        if (is3D) {
+                            c = new Coordinate(x, y, v.doubleValue(i++));
+                        } else {
+                            c = new Coordinate(x, y);
+                        }
+                        coordinates.add(c);
+                    } else {
+                        if (is3D) i++;
+                        toLineString(coordinates, lines);
+                        coordinates.clear();
+                    }
+                }
+            }
+        }
+        toLineString(coordinates, lines);
+        return toGeometry(lines);
+    }
+
+    /**
+     * Makes a line string or linear ring from the given coordinates, and add 
the line string to the given list.
+     * If the given coordinates array is empty, then this method does nothing.
+     * This method does not modify the given coordinates list.
+     */
+    private void toLineString(final List<Coordinate> coordinates, final 
List<LineString> addTo) {
+        final int s = coordinates.size();
+        if (s >= 2) {
+            final LineString line;
+            final Coordinate[] ca = coordinates.toArray(new Coordinate[s]);
+            if (ca[0].equals2D(ca[s-1])) {
+                line = factory.createLinearRing(ca);        // Throws an 
exception if s < 4.
+            } else {
+                line = factory.createLineString(ca);        // Throws an 
exception if contains duplicated point.
+            }
+            addTo.add(line);
+        }
+    }
+
+    /**
+     * Returns the given list of line string as a single geometry.
+     */
+    private Geometry toGeometry(final List<LineString> lines) {
+        final int s = lines.size();
+        switch (s) {
+            case 0:  return factory.createLinearRing((Coordinate[]) null);     
 // Creates an empty linear ring.
+            case 1:  return lines.get(0);
+            default: return factory.createMultiLineString(lines.toArray(new 
LineString[s]));
+        }
     }
 
     /**
@@ -111,15 +203,50 @@ final class JTS extends Geometries<Geome
      * @throws ClassCastException if an element in the iterator is not a JTS 
geometry.
      */
     @Override
-    final Geometry tryMergePolylines(final Object first, final Iterator<?> 
polylines) {
-        throw unsupported(2);   // TODO - see class javadoc
+    final Geometry tryMergePolylines(Object next, final Iterator<?> polylines) 
{
+        if (!(next instanceof MultiLineString || next instanceof LineString || 
next instanceof Point)) {
+            return null;
+        }
+        final List<Coordinate> coordinates = new ArrayList<>();
+        final List<LineString> lines = new ArrayList<>();
+        for (;; next = polylines.next()) {
+            if (next != null) {
+                if (next instanceof Point) {
+                    final Coordinate pt = ((Point) next).getCoordinate();
+                    if (!Double.isNaN(pt.x) && !Double.isNaN(pt.y)) {
+                        coordinates.add(pt);
+                    } else {
+                        toLineString(coordinates, lines);
+                        coordinates.clear();
+                    }
+                } else {
+                    final Geometry g = (Geometry) next;
+                    final int n = g.getNumGeometries();
+                    for (int i=0; i<n; i++) {
+                        final LineString ls = (LineString) g.getGeometryN(i);
+                        if (coordinates.isEmpty()) {
+                            lines.add(ls);
+                        } else {
+                            
coordinates.addAll(Arrays.asList(ls.getCoordinates()));
+                            toLineString(coordinates, lines);
+                            coordinates.clear();
+                        }
+                    }
+                }
+            }
+            if (!polylines.hasNext()) {         // Should be part of the 'for' 
instruction, but we need
+                break;                          // to skip this condition 
during the first iteration.
+            }
+        }
+        toLineString(coordinates, lines);
+        return toGeometry(lines);
     }
 
     /**
      * Parses the given WKT.
      */
     @Override
-    public Object parseWKT(final String wkt) {
-        throw unsupported(2);
+    public Object parseWKT(final String wkt) throws ParseException {
+        return new WKTReader(factory).read(wkt);
     }
 }

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=1829137&r1=1829136&r2=1829137&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] Sat Apr 14 12:54:01 2018
@@ -48,7 +48,7 @@ final class Java2D extends Geometries<Sh
     }
 
     /**
-     * If the given geometry is a Java2D geometry, returns a short string 
representation the class name,
+     * If the given geometry is a Java2D geometry, returns a short string 
representation of the class name,
      * ignoring the primitive type specialization. For example if the class is 
{@code Rectangle2D.Float},
      * then this method returns {@code "Rectangle2D"}.
      */

Added: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java?rev=1829137&view=auto
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java
 (added)
+++ 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.feature;
+
+import com.esri.core.geometry.Polyline;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link ESRI} implementation.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final strictfp class ESRITest extends GeometriesTestCase {
+    /**
+     * Creates a new test case.
+     */
+    public ESRITest() {
+        super(new ESRI());
+    }
+
+    /**
+     * Tests {@link ESRI#createPolyline(int, Vector...)}.
+     */
+    @Test
+    @Override
+    public void testCreatePolyline() {
+        super.testCreatePolyline();
+        final Polyline poly = (Polyline) geometry;
+        assertEquals("pathCount", 2, poly.getPathCount());
+    }
+
+    /**
+     * Tests {@link Geometries#tryMergePolylines(Object, Iterator)}.
+     */
+    @Test
+    @Override
+    public void testTryMergePolylines() {
+        super.testTryMergePolylines();
+        final Polyline poly = (Polyline) geometry;
+        assertEquals("pathCount", 3, poly.getPathCount());
+    }
+}

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/ESRITest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java?rev=1829137&view=auto
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
 (added)
+++ 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.feature;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import org.apache.sis.math.Vector;
+import org.apache.sis.geometry.GeneralEnvelope;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static java.lang.Double.NaN;
+import static org.junit.Assert.*;
+
+
+/**
+ * Base class of {@link Java2D}, {@link ESRI} and {@link JTS} implementation 
tests.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public abstract strictfp class GeometriesTestCase extends TestCase {
+    /**
+     * The factory to test.
+     */
+    private final Geometries<?> factory;
+
+    /**
+     * The geometry created by the test. Provided for allowing sub-classes to 
perform additional verifications.
+     */
+    Object geometry;
+
+    /**
+     * Creates a new test for the given factory.
+     */
+    GeometriesTestCase(final Geometries<?> factory) {
+        this.factory = factory;
+    }
+
+    /**
+     * Tests {@link Geometries#createPoint(double, double)} followed by {@link 
Geometries#tryGetCoordinate(Object)}.
+     */
+    @Test
+    public void testTryGetCoordinate() {
+        geometry = factory.createPoint(4, 5);
+        assertNotNull("createPoint", geometry);
+        assertArrayEquals("tryGetCoordinate", new double[] {4, 5}, 
factory.tryGetCoordinate(geometry), STRICT);
+    }
+
+    /**
+     * Tests {@link Geometries#createPolyline(int, Vector...)}.
+     * This method verifies the polylines by a call to {@link 
Geometries#tryGetEnvelope(Object)}.
+     * Subclasses should perform more extensive tests by verifying the {@link 
#geometry} field.
+     */
+    @Test
+    public void testCreatePolyline() {
+        geometry = factory.createPolyline(2, Vector.create(new double[] {
+                  4,   5,
+                  7,   9,
+                  9,   3,
+                  4,   5,
+                NaN, NaN,
+                 -3,  -2,
+                 -2,  -5,
+                 -1,  -6}, false));
+
+        final GeneralEnvelope env = factory.tryGetEnvelope(geometry);
+        assertEquals("xmin", -3, env.getLower(0), STRICT);
+        assertEquals("ymin", -6, env.getLower(1), STRICT);
+        assertEquals("xmax",  9, env.getUpper(0), STRICT);
+        assertEquals("ymax",  9, env.getUpper(1), STRICT);
+    }
+
+    /**
+     * Tests {@link Geometries#tryMergePolylines(Object, Iterator)}.
+     * This method verifies the polylines by a call to {@link 
Geometries#tryGetEnvelope(Object)}.
+     * Subclasses should perform more extensive tests by verifying the {@link 
#geometry} field.
+     */
+    @Test
+    public void testTryMergePolylines() {
+        final Iterator<Object> c1 = Arrays.asList(
+                factory.createPoint(  4,   5),
+                factory.createPoint(  7,   9),
+                factory.createPoint(  9,   3),
+                factory.createPoint(  4,   5),
+                factory.createPoint(NaN, NaN),
+                factory.createPoint( -3,  -2),
+                factory.createPoint( -2,  -5),
+                factory.createPoint( -1,  -6)).iterator();
+
+        final Iterator<Object> c2 = Arrays.asList(
+                factory.createPoint( 14,  12),
+                factory.createPoint( 15,  11),
+                factory.createPoint( 13,  10)).iterator();
+
+        final Object g1 = factory.tryMergePolylines(c1.next(), c1);
+        final Object g2 = factory.tryMergePolylines(c2.next(), c2);
+        geometry = factory.tryMergePolylines(g1, 
Arrays.asList(factory.createPoint(13, 11), g2).iterator());
+
+        final GeneralEnvelope env = factory.tryGetEnvelope(geometry);
+        assertEquals("xmin", -3, env.getLower(0), STRICT);
+        assertEquals("ymin", -6, env.getLower(1), STRICT);
+        assertEquals("xmax", 15, env.getUpper(0), STRICT);
+        assertEquals("ymax", 12, env.getUpper(1), STRICT);
+    }
+}

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java?rev=1829137&view=auto
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
 (added)
+++ 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.feature;
+
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.MultiLineString;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link JTS} implementation.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final strictfp class JTSTest extends GeometriesTestCase {
+    /**
+     * Creates a new test case.
+     */
+    public JTSTest() {
+        super(new JTS());
+    }
+
+    /**
+     * Tests {@link JTS#createPolyline(int, Vector...)}.
+     */
+    @Test
+    @Override
+    public void testCreatePolyline() {
+        super.testCreatePolyline();
+        final MultiLineString mp = (MultiLineString) geometry;
+        assertEquals("numGeometries", 2, mp.getNumGeometries());
+        verifyTwoFirstGeometries(mp);
+    }
+
+    /**
+     * Verifies the coordinates of the two first geometries of the given multi 
line string.
+     * If there is more than 2 geometries, it is caller responsibility to 
verify the other ones.
+     */
+    private static void verifyTwoFirstGeometries(final MultiLineString mp) {
+        assertArrayEquals(new Coordinate[] {
+                new Coordinate(4, 5),
+                new Coordinate(7, 9),
+                new Coordinate(9, 3),
+                new Coordinate(4, 5)}, mp.getGeometryN(0).getCoordinates());
+
+        assertArrayEquals(new Coordinate[] {
+                new Coordinate(-3, -2),
+                new Coordinate(-2, -5),
+                new Coordinate(-1, -6)}, mp.getGeometryN(1).getCoordinates());
+    }
+
+    /**
+     * Tests {@link Geometries#tryMergePolylines(Object, Iterator)}.
+     */
+    @Test
+    @Override
+    public void testTryMergePolylines() {
+        super.testTryMergePolylines();
+        final MultiLineString mp = (MultiLineString) geometry;
+        assertEquals("numGeometries", 3, mp.getNumGeometries());
+        verifyTwoFirstGeometries(mp);
+        assertArrayEquals(new Coordinate[] {
+                new Coordinate(13, 11),
+                new Coordinate(14, 12),
+                new Coordinate(15, 11),
+                new Coordinate(13, 10)}, mp.getGeometryN(2).getCoordinates());
+    }
+}

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/JTSTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java?rev=1829137&view=auto
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java
 (added)
+++ 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.feature;
+
+import java.awt.geom.Path2D;
+import org.junit.Test;
+
+import static org.opengis.test.Assert.*;
+
+
+/**
+ * Tests {@link Java2D} implementation.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final strictfp class Java2DTest extends GeometriesTestCase {
+    /**
+     * Creates a new test case.
+     */
+    public Java2DTest() {
+        super(new Java2D());
+    }
+
+    /**
+     * Tests {@link Java2D#createPolyline(int, Vector...)}.
+     */
+    @Test
+    @Override
+    public void testCreatePolyline() {
+        super.testCreatePolyline();
+        assertInstanceOf("geometry", Path2D.class, geometry);
+    }
+
+    /**
+     * Tests {@link Geometries#tryMergePolylines(Object, Iterator)}.
+     */
+    @Test
+    @Override
+    public void testTryMergePolylines() {
+        super.testTryMergePolylines();
+        assertInstanceOf("geometry", Path2D.class, geometry);
+    }
+}

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/Java2DTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java?rev=1829137&r1=1829136&r2=1829137&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.5
  * @module
  */
@@ -52,6 +52,9 @@ import org.junit.BeforeClass;
     org.apache.sis.filter.DefaultLiteralTest.class,
     org.apache.sis.filter.DefaultPropertyNameTest.class,
     org.apache.sis.internal.feature.AttributeConventionTest.class,
+    org.apache.sis.internal.feature.Java2DTest.class,
+    org.apache.sis.internal.feature.ESRITest.class,
+    org.apache.sis.internal.feature.JTSTest.class,
     org.apache.sis.feature.builder.CharacteristicTypeBuilderTest.class,
     org.apache.sis.feature.builder.AttributeTypeBuilderTest.class,
     org.apache.sis.feature.builder.AssociationRoleBuilderTest.class,

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=1829137&r1=1829136&r2=1829137&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] Sat Apr 14 12:54:01 2018
@@ -38,22 +38,24 @@ import org.opengis.metadata.acquisition.
  */
 public enum GeometryLibrary {
     /**
-     * The Java Topology Suite (JTS) library. This open source library 
provides an object model
-     * for Euclidean planar geometry together with a set of fundamental 
geometric functions.
-     * The library is licensed under Eclipse Distribution License.
+     * The Java 2D Graphics and Imaging library. This library does not provide 
as many topological operations
+     * than other libraries, but is available on most standard Java 
environments and constitute a reliable
+     * fallback when no other library is available.
      *
      * <table class="sis">
      *   <caption>Implementation classes</caption>
      *   <tr><th>Geometry type</th>               <th>Class name</th></tr>
-     *   <tr><td>Root geometry class</td>         <td>{@code 
org.locationtech.jts.geom.Geometry}</td></tr>
-     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code 
org.locationtech.jts.geom.Point}</td></tr>
-     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code 
org.locationtech.jts.geom.LineString}</td></tr>
-     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code 
org.locationtech.jts.geom.Polygon}</td></tr>
+     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code 
java.awt.geom.Point2D}</td></tr>
+     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code 
java.awt.Shape}</td></tr>
+     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code 
java.awt.Shape}</td></tr>
      * </table>
      *
-     * @see <a href="http://locationtech.github.io/jts/";>JTS home page</a>
+     * Note that contrarily to JTS and ESRI libraries,
+     * a point does not extend any root geometry class in Java2D.
+     *
+     * @see <a 
href="http://docs.oracle.com/javase/8/docs/technotes/guides/2d/index.html";>Java2D
 home page</a>
      */
-    JTS,
+    JAVA2D,
 
     /**
      * The ESRI geometry API library. This library can be used for spatial 
vector data processing.
@@ -74,22 +76,22 @@ public enum GeometryLibrary {
     ESRI,
 
     /**
-     * The Java 2D Graphics and Imaging library. This library does not provide 
as many topological operations
-     * than other libraries, but is available on most standard Java 
environments and constitute a reliable
-     * fallback when no other library is available.
+     * The Java Topology Suite (JTS) library. This open source library 
provides an object model
+     * for Euclidean planar geometry together with a set of fundamental 
geometric functions.
+     * The library is licensed under Eclipse Distribution License.
      *
      * <table class="sis">
      *   <caption>Implementation classes</caption>
      *   <tr><th>Geometry type</th>               <th>Class name</th></tr>
-     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code 
java.awt.geom.Point2D}</td></tr>
-     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code 
java.awt.Shape}</td></tr>
-     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code 
java.awt.Shape}</td></tr>
+     *   <tr><td>Root geometry class</td>         <td>{@code 
org.locationtech.jts.geom.Geometry}</td></tr>
+     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code 
org.locationtech.jts.geom.Point}</td></tr>
+     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code 
org.locationtech.jts.geom.LineString}</td></tr>
+     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code 
org.locationtech.jts.geom.Polygon}</td></tr>
      * </table>
      *
-     * Note that contrarily to JTS and ESRI libraries,
-     * a point does not extend any root geometry class in Java2D.
+     * @see <a href="http://locationtech.github.io/jts/";>JTS home page</a>
      *
-     * @see <a 
href="http://docs.oracle.com/javase/8/docs/technotes/guides/2d/index.html";>Java2D
 home page</a>
+     * @since 1.0
      */
-    JAVA2D
+    JTS
 }

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreFormat.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreFormat.java?rev=1829137&r1=1829136&r2=1829137&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreFormat.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreFormat.java
 [UTF-8] Sat Apr 14 12:54:01 2018
@@ -87,7 +87,7 @@ public final class StoreFormat extends W
                 envelope.setCoordinateReferenceSystem(parseCRS(crs, 
additionalCRS));
                 return new GeometryWrapper(obj, envelope);
             }
-        } catch (IllegalArgumentException | UnsupportedOperationException e) {
+        } catch (Exception e) {     // Implementation-specific exception (e.g. 
JTS has its own exception class).
             log(e);
         }
         return null;


Reply via email to