sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1732207 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/test/java/org/apache/sis/io/wkt/ sis-utility/src/main/java/org/apache/sis/measure/
Date Wed, 24 Feb 2016 19:18:49 GMT
Author: desruisseaux
Date: Wed Feb 24 19:18:49 2016
New Revision: 1732207

URL: http://svn.apache.org/viewvc?rev=1732207&view=rev
Log:
Fix a parsing error for UNIT["grade", ...] and for ID[authority, code, URI[...]].
Issues: SIS-309 and SIS-310.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java?rev=1732207&r1=1732206&r2=1732207&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
[UTF-8] Wed Feb 24 19:18:49 2016
@@ -294,7 +294,7 @@ abstract class AbstractParser implements
     final Unit<?> parseUnit(final String text) throws ParseException {
         if (unitFormat == null) {
             if (symbols.getLocale() == Locale.ROOT) {
-                return Units.valueOf(text); // Most common case, avoid the convolved code
below.
+                return Units.valueOf(text);             // Most common case, avoid the convolved
code below.
             }
             unitFormat = UnitFormat.getInstance(symbols.getLocale());
         }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java?rev=1732207&r1=1732206&r2=1732207&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java [UTF-8]
Wed Feb 24 19:18:49 2016
@@ -633,7 +633,7 @@ final class Element implements Serializa
         final Iterator<Object> iterator = list.iterator();
         while (iterator.hasNext()) {
             final Object object = iterator.next();
-            if (object != null) {
+            if (object != null && !(object instanceof Element)) {
                 iterator.remove();
                 return object;
             }
@@ -719,7 +719,7 @@ final class Element implements Serializa
         final Iterator<Object> iterator = list.iterator();
         while (iterator.hasNext()) {
             final Object object = iterator.next();
-            if (type.isInstance(object)) {
+            if (type.isInstance(object) && !(object instanceof Element)) {
                 iterator.remove();
                 return (T) object;
             }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java?rev=1732207&r1=1732206&r2=1732207&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] Wed Feb 24 19:18:49 2016
@@ -435,8 +435,8 @@ final class GeodeticObjectParser extends
         Element element;
         while ((element = parent.pullElement(OPTIONAL, ID_KEYWORDS)) != null) {
             final String   codeSpace = element.pullString("codeSpace");
-            final String   code      = element.pullObject("code").toString();   // Accepts
Integer as well as String.
-            final Object   version   = element.pullOptional(Object.class);      // Accepts
Number as well as String.
+            final String   code      = element.pullObject("code").toString();       // Accepts
Integer as well as String.
+            final Object   version   = element.pullOptional(Object.class);          // Accepts
Number as well as String.
             final Element  citation  = element.pullElement(OPTIONAL, WKTKeywords.Citation);
             final String   authority;
             if (citation != null) {

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java?rev=1732207&r1=1732206&r2=1732207&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] Wed Feb 24 19:18:49 2016
@@ -203,7 +203,7 @@ class MathTransformParser extends Abstra
         final Element element = parent.pullElement(OPTIONAL, ID_KEYWORDS);
         if (element != null) {
             final String codeSpace = element.pullString("codeSpace");
-            final Object code      = element.pullObject("code");   // Accepts Integer as
well as String.
+            final Object code      = element.pullObject("code");            // Accepts Integer
as well as String.
             element.close(ignoredElements);
             if (Constants.EPSG.equalsIgnoreCase(codeSpace)) try {
                 final int n;

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java?rev=1732207&r1=1732206&r2=1732207&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
[UTF-8] Wed Feb 24 19:18:49 2016
@@ -57,7 +57,7 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
 @DependsOn({
@@ -626,24 +626,16 @@ public final strictfp class GeodeticObje
                      "    DATUM[“Nouvelle Triangulation Française (Paris)”," +
                      "      SPHEROID[“Clarke 1880 (IGN)”, 6378249.2, 293.4660212936269],"
+
                      "      TOWGS84[-168,-60,320,0,0,0,0]]," +
-                     "    PRIMEM[“Paris”, 2.5969213, AUTHORITY[“EPSG”, “8903”]],"
+  // In grads.
+                     "    PRIMEM[“Paris”, 2.5969213, AUTHORITY[“EPSG”, “8903”]],"
+  // In grades.
                      "    UNIT[“grad”, 0.01570796326794897]]," +
                      "  PROJECTION[“Lambert Conformal Conic (1SP)”]," +  // Intentional
swapping of "Conformal" and "Conic".
-                     "  PARAMETER[“latitude_of_origin”, 52.0]," +        // In grads.
+                     "  PARAMETER[“latitude_of_origin”, 52.0]," +        // In grades.
                      "  PARAMETER[“scale_factor”, 0.99987742]," +
                      "  PARAMETER[“false_easting”, 600.0]," +
                      "  PARAMETER[“false_northing”, 2200.0]," +
-                     "  UNIT[“metre”,1000]]";
+                     "  UNIT[“km”,1000]]";
 
-        ProjectedCRS crs = parse(ProjectedCRS.class, wkt);
-        assertNameAndIdentifierEqual("NTF (Paris) / Lambert zone II", 0, crs);
-        verifyProjectedCS(crs.getCoordinateSystem(), SI.KILOMETRE);
-        PrimeMeridian pm = verifyNTF(crs.getDatum(), true);
-        assertEquals("angularUnit", NonSI.GRADE, pm.getAngularUnit());
-        assertEquals("greenwichLongitude", 2.5969213, pm.getGreenwichLongitude(), STRICT);
-        ParameterValue<?> param = verifyNTF(crs.getConversionFromBase().getParameterValues());
-        assertEquals("angularUnit", NonSI.GRADE, param.getUnit());
-        assertEquals("latitude_of_origin",  52.0, param.doubleValue(), STRICT);
+        validateParisFranceII(parse(ProjectedCRS.class, wkt), 0, true);
         /*
          * Parse again using Convention.WKT1_COMMON_UNITS and ignoring AXIS[…] elements.
          * See the comment in 'testGeographicWithParisMeridian' method for a discussion.
@@ -655,18 +647,69 @@ public final strictfp class GeodeticObje
         wkt = wkt.replace("600.0",     "600000");           // Convert unit in “false_easting”
parameter.
         wkt = wkt.replace("2200.0",    "2200000");          // Convert unit in “false_northing”
parameter.
         newParser(Convention.WKT1_IGNORE_AXES);
-        crs = parse(ProjectedCRS.class, wkt);
+        final ProjectedCRS crs = parse(ProjectedCRS.class, wkt);
         assertNameAndIdentifierEqual("NTF (Paris) / Lambert zone II", 0, crs);
         verifyProjectedCS(crs.getCoordinateSystem(), SI.KILOMETRE);
-        pm = verifyNTF(crs.getDatum(), true);
+        final PrimeMeridian pm = verifyNTF(crs.getDatum(), true);
         assertEquals("angularUnit", NonSI.DEGREE_ANGLE, pm.getAngularUnit());
         assertEquals("greenwichLongitude", 2.33722917, pm.getGreenwichLongitude(), STRICT);
-        param = verifyNTF(crs.getConversionFromBase().getParameterValues());
+        final ParameterValue<?> param = verifyNTF(crs.getConversionFromBase().getParameterValues());
         assertEquals("angularUnit", NonSI.DEGREE_ANGLE, param.getUnit());
         assertEquals("latitude_of_origin",  46.8, param.doubleValue(), STRICT);
     }
 
     /**
+     * Tests the same CRS than {@link #testProjectedWithGradUnits()}, but from a WKT 2 definition
+     * (except for inclusion of accented characters).
+     *
+     * @throws ParseException if the parsing failed.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-309">SIS-309</a>
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-310">SIS-310</a>
+     */
+    @Test
+    @DependsOnMethod("testProjectedWithGradUnits")
+    public void testProjectedFromWKT2() throws ParseException {
+        String wkt = "ProjectedCRS[“NTF (Paris) / Lambert zone II”,\n" +
+                     "  BaseGeodCRS[“NTF (Paris)”,\n" +
+                     "    Datum[“Nouvelle Triangulation Française (Paris)”,\n" +
+                     "      Ellipsoid[“Clarke 1880 (IGN)”, 6378249.2, 293.4660212936269]],\n"
+
+                     "      PrimeMeridian[“Paris”, 2.5969213, Unit[“grade”, 0.015707963267948967],
Id[“EPSG”, 8903]],\n" +
+                     "    AngleUnit[“degree”, 0.017453292519943295]],\n" +
+                     "  Conversion[“Lambert zone II”,\n" +
+                     "    Method[“Lambert Conic Conformal (1SP)”],\n" +
+                     "    Parameter[“Latitude of natural origin”, 52.0, AngleUnit[“grade”,
0.015707963267948967]],\n" +
+                     "    Parameter[“Longitude of natural origin”, 0.0],\n" +
+                     "    Parameter[“Scale factor at natural origin”, 0.99987742],\n"
+
+                     "    Parameter[“False easting”, 600.0],\n" +
+                     "    Parameter[“False northing”, 2200.0]],\n" +
+                     "  CS[Cartesian, 2],\n" +
+                     "    Axis[“Easting (E)”, east],\n" +
+                     "    Axis[“Northing (N)”, north],\n" +
+                     "    LengthUnit[“km”, 1000],\n" +
+                     "  Scope[“Large and medium scale topographic mapping and engineering
survey.”],\n" +
+                     "  Id[“EPSG”, 27572, URI[“urn:ogc:def:crs:EPSG::27572”]]]";
+
+        final ProjectedCRS crs = parse(ProjectedCRS.class, wkt);
+        validateParisFranceII(crs, 27572, false);
+        assertNull("Identifier shall not have a version.", getSingleton(crs.getIdentifiers()).getVersion());
+    }
+
+    /**
+     * Verifies the parameters of a “NTF (Paris) / Lambert zone II” projection.
+     */
+    private static void validateParisFranceII(final ProjectedCRS crs, final int identifier,
final boolean hasToWGS84) {
+        assertNameAndIdentifierEqual("NTF (Paris) / Lambert zone II", identifier, crs);
+        verifyProjectedCS(crs.getCoordinateSystem(), SI.KILOMETRE);
+        final PrimeMeridian pm = verifyNTF(crs.getDatum(), hasToWGS84);
+        assertEquals("angularUnit", NonSI.GRADE, pm.getAngularUnit());
+        assertEquals("greenwichLongitude", 2.5969213, pm.getGreenwichLongitude(), STRICT);
+        final ParameterValue<?> param = verifyNTF(crs.getConversionFromBase().getParameterValues());
+        assertEquals("angularUnit", NonSI.GRADE, param.getUnit());
+        assertEquals("latitude_of_origin",  52.0, param.doubleValue(), STRICT);
+    }
+
+    /**
      * Verifies the properties of a datum which is expected to be “Nouvelle Triangulation
Française (Paris)”.
      * This is used by the methods in this class which test a CRS using less frequently used
units and prime
      * meridian.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java?rev=1732207&r1=1732206&r2=1732207&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8]
Wed Feb 24 19:18:49 2016
@@ -415,6 +415,7 @@ public final class Units extends Static
              */
             if (uom.equals("°")                      || equalsIgnorePlural(uom, "decimal_degree"))
return NonSI.DEGREE_ANGLE;
             if (uom.equalsIgnoreCase("arcsec"))                                         
          return NonSI.SECOND_ANGLE;
+            if (equalsIgnorePlural(uom, "grade"))                                       
          return NonSI.GRADE;
             if (uom.equalsIgnoreCase("rad")          || equalsIgnorePlural(uom, "radian"))
        return SI.RADIAN;
             if (equalsIgnorePlural(uom, "kilometer") || equalsIgnorePlural(uom, "kilometre"))
     return SI.KILOMETRE;
             if (equalsIgnorePlural(uom, "meter")     || equalsIgnorePlural(uom, "metre"))
         return SI.METRE;



Mime
View raw message