sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1685934 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/test/java/org/apache/sis/referencing/crs/
Date Wed, 17 Jun 2015 08:02:44 GMT
Author: desruisseaux
Date: Wed Jun 17 08:02:44 2015
New Revision: 1685934

URL: http://svn.apache.org/r1685934
Log:
WKT 2: Unit keyword is inconditionally "TimeUnit" for temporal CRS.
This is because temporal CRS did not existed in WKT 1, so ISO 19162
does not make provision for backward compatibility in this case.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/WKTKeywords.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultTemporalCRSTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/WKTKeywords.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/WKTKeywords.java?rev=1685934&r1=1685933&r2=1685934&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/WKTKeywords.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/WKTKeywords.java
[UTF-8] Wed Jun 17 08:02:44 2015
@@ -66,11 +66,12 @@ public final class WKTKeywords extends S
      * Related to unit of measurements.
      */
     public static final String
-            Unit       = "Unit",
-            LengthUnit = "LengthUnit",
-            AngleUnit  = "AngleUnit",
-            ScaleUnit  = "ScaleUnit",
-            TimeUnit   = "TimeUnit";
+            Unit           = "Unit",
+            LengthUnit     = "LengthUnit",
+            AngleUnit      = "AngleUnit",
+            ScaleUnit      = "ScaleUnit",
+            TimeUnit       = "TimeUnit",
+            ParametricUnit = "ParametricUnit";
 
     /**
      * Related to {@link org.apache.sis.referencing.cs.AbstractCS}

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1685934&r1=1685933&r2=1685934&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Wed Jun 17 08:02:44 2015
@@ -1121,23 +1121,27 @@ public class Formatter implements Locali
      * Specialization is used in WKT 2 format except the <cite>simplified WKT 2</cite>
one.
      *
      * <div class="note"><b>Example:</b>
-     * {@code append(SI.KILOMETRE)} will append "{@code LENGTHUNIT["km", 1000]}" to the WKT.</div>
+     * {@code append(SI.KILOMETRE)} will append "{@code LengthUnit["km", 1000]}" to the WKT.</div>
      *
      * @param unit The unit to append to the WKT, or {@code null} if none.
+     *
+     * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#35">WKT
2 specification §7.4</a>
      */
     public void append(final Unit<?> unit) {
         if (unit != null) {
-            String keyword = WKTKeywords.Unit;
-            if (!convention.isSimplified()) {
-                if (Units.isLinear(unit)) {
-                    keyword = WKTKeywords.LengthUnit;
-                } else if (Units.isAngular(unit)) {
-                    keyword = WKTKeywords.AngleUnit;
-                } else if (Units.isScale(unit)) {
-                    keyword = WKTKeywords.ScaleUnit;
-                } else if (Units.isTemporal(unit)) {
-                    keyword = WKTKeywords.TimeUnit;
-                }
+            final boolean isSimplified = convention.isSimplified();
+            final Unit<?> base = unit.toSI();
+            final String keyword;
+            if (base.equals(SI.METRE)) {
+                keyword = isSimplified ? WKTKeywords.Unit : WKTKeywords.LengthUnit;
+            } else if (base.equals(SI.RADIAN)) {
+                keyword = isSimplified ? WKTKeywords.Unit : WKTKeywords.AngleUnit;
+            } else if (base.equals(Unit.ONE)) {
+                keyword = isSimplified ? WKTKeywords.Unit : WKTKeywords.ScaleUnit;
+            } else if (base.equals(SI.SECOND)) {
+                keyword = WKTKeywords.TimeUnit;  // "Unit" alone is not allowed for time
units according ISO 19162.
+            } else {
+                keyword = WKTKeywords.ParametricUnit;
             }
             openElement(false, keyword);
             setColor(ElementKind.UNIT);
@@ -1156,11 +1160,15 @@ public class Formatter implements Locali
             closeQuote(fromIndex);
             resetColor();
             final double conversion = Units.toStandardUnit(unit);
-            if (!(conversion > 0)) { // ISO 19162 requires the conversion factor to be
positive.
-                setInvalidWKT(Unit.class, null);
-            }
             appendExact(conversion);
             closeElement(false);
+            /*
+             * ISO 19162 requires the conversion factor to be positive.
+             * In addition, keywords other than "Unit" are not valid in WKt 1.
+             */
+            if (!(conversion > 0) || (keyword != WKTKeywords.Unit && convention.majorVersion()
== 1)) {
+                setInvalidWKT(Unit.class, null);
+            }
         }
     }
 

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=1685934&r1=1685933&r2=1685934&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 Jun 17 08:02:44 2015
@@ -38,7 +38,6 @@ import javax.measure.quantity.Duration;
 
 import org.opengis.util.Factory;
 import org.opengis.metadata.Identifier;
-import org.opengis.metadata.citation.Citation;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.ReferenceSystem;
@@ -91,7 +90,8 @@ final class GeodeticObjectParser extends
      */
     private static final String[] UNIT_KEYWORDS = {
         WKTKeywords.Unit,   // Ignored since it does not allow us to know the quantity dimension.
-        WKTKeywords.LengthUnit, WKTKeywords.AngleUnit, WKTKeywords.ScaleUnit, WKTKeywords.TimeUnit
+        WKTKeywords.LengthUnit, WKTKeywords.AngleUnit, WKTKeywords.ScaleUnit, WKTKeywords.TimeUnit,
+        WKTKeywords.ParametricUnit  // Ignored for the same reason than "Unit".
     };
 
     /**
@@ -561,9 +561,9 @@ final class GeodeticObjectParser extends
         }
         final String name   = element.pullString("name");
         final double factor = element.pullDouble("factor");
-        final int    index  = element.getKeywordIndex();
+        final int    index  = element.getKeywordIndex() - 1;
         parseMetadataAndClose(element, name);
-        if (index != 0) {
+        if (index >= 0 && index < BASE_UNITS.length) {
             return Units.multiply(BASE_UNITS[index - 1], factor);
         }
         // If we can not infer the base type, we have to rely on the name.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java?rev=1685934&r1=1685933&r2=1685934&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
[UTF-8] Wed Jun 17 08:02:44 2015
@@ -158,7 +158,7 @@ public final strictfp class DefaultCompo
                 "    AXIS[“Gravity-related height”, UP]],\n" +
                 "  TIMECRS[“Time”,\n" +
                 "    TIMEDATUM[“Modified Julian”, TIMEORIGIN[1858-11-17T00:00:00.0Z]],\n"
+
-                "    UNIT[“day”, 86400],\n" +
+                "    TIMEUNIT[“day”, 86400],\n" +
                 "    AXIS[“Time”, FUTURE]]]",
                 HardCodedCRS.GEOID_4D);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultTemporalCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultTemporalCRSTest.java?rev=1685934&r1=1685933&r2=1685934&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultTemporalCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultTemporalCRSTest.java
[UTF-8] Wed Jun 17 08:02:44 2015
@@ -41,7 +41,7 @@ public final strictfp class DefaultTempo
         assertWktEquals(Convention.WKT1,
                 "TIMECRS[“Time”,\n" +
                 "  TIMEDATUM[“Modified Julian”, TIMEORIGIN[1858-11-17T00:00:00.0Z]],\n"
+
-                "  UNIT[“day”, 86400],\n" +
+                "  TIMEUNIT[“day”, 86400],\n" +
                 "  AXIS[“Time”, FUTURE]]",
                 HardCodedCRS.TIME);
     }



Mime
View raw message