sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1676236 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/referencing/cs/ sis-referencing/src/test/java/org/apache/sis/referencing/crs/
Date Mon, 27 Apr 2015 10:10:31 GMT
Author: desruisseaux
Date: Mon Apr 27 10:10:30 2015
New Revision: 1676236

URL: http://svn.apache.org/r1676236
Log:
Referencing WKT: added support for ORDER[...] element inside AXIS[...] element.
https://issues.apache.org/jira/browse/SIS-163

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.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/DefaultGeocentricCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultTemporalCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java?rev=1676236&r1=1676235&r2=1676236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] Mon Apr 27 10:10:30 2015
@@ -55,13 +55,7 @@ import org.apache.sis.metadata.iso.citat
 public enum Convention {
     /**
      * The ISO 19162 format, also known as “WKT 2”.
-     * This convention follows the ISO recommendations with the following exceptions:
-     *
-     * <ul>
-     *   <li>{@code Axis} element omits the {@code Order} sub-element.</li>
-     * </ul>
-     *
-     * Since the {@code Order} element is optional, the WKT is still valid.
+     * This convention follows the ISO recommendations.
      *
      * <p>Unless otherwise specified by {@link WKTFormat#setNameAuthority(Citation)},
projections
      * and parameters formatted with this convention will use the {@linkplain Citations#EPSG
EPSG}
@@ -77,6 +71,7 @@ public enum Convention {
      * to the {@link #WKT2} convention except for the following aspects:
      *
      * <ul>
+     *   <li>{@code Axis} element omits the {@code Order} sub-element.</li>
      *   <li>{@code VerticalExtent} element omits the {@code LengthUnit} sub-element
      *       if the unit is {@link javax.measure.unit.SI#METRE}.</li>
      *   <li>{@code Ellipsoid} element omits the {@code LengthUnit} sub-element

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1676236&r1=1676235&r2=1676236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] Mon Apr 27 10:10:30 2015
@@ -53,6 +53,7 @@ import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.io.wkt.ElementKind;
 import org.apache.sis.io.wkt.CharEncoding;
+import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 
 import static java.lang.Double.doubleToLongBits;
@@ -806,8 +807,12 @@ public class DefaultCoordinateSystemAxis
          * The specification also suggests to write only the abbreviation (e.g. "(X)") in
the
          * special case of Geocentric axis, and disallows Greek letters.
          */
-        if (!isWKT1) {
-            final String a = formatter.getCharEncoding().getAbbreviation(getEnclosingCS(formatter),
this);
+        final CoordinateSystem cs;
+        if (isWKT1) {
+            cs = null;
+        } else {
+            cs = getEnclosingCS(formatter);
+            final String a = formatter.getCharEncoding().getAbbreviation(cs, this);
             if (a != null && !a.equals(name)) {
                 final StringBuilder buffer = new StringBuilder();
                 if (name != null) {
@@ -838,9 +843,66 @@ public class DefaultCoordinateSystemAxis
          * If the enclosing CRS provided a contextual unit, then it is assumed to apply
          * to all axes (we do not verify).
          */
-        if (!isWKT1 && !formatter.hasContextualUnit(1)) {
-            formatter.append(getUnit());
+        if (!isWKT1) {
+            if (convention == Convention.WKT2 && cs != null) {
+                final Order order = Order.create(cs, this);
+                if (order != null) {
+                    formatter.append(order);
+                } else {
+                    formatter.setInvalidWKT(cs, null);
+                }
+            }
+            if (!formatter.hasContextualUnit(1)) {
+                formatter.append(getUnit());
+            }
         }
         return "Axis";
     }
+
+    /**
+     * The {@code ORDER[…]} element to be formatted inside {@code AXIS[…]} element.
+     * This is an element of WKT 2 only.
+     */
+    private static final class Order extends FormattableObject {
+        /**
+         * The sequence number to format inside the {@code ORDER[…]} element.
+         */
+        private final int index;
+
+        /**
+         * Creates a new {@code ORDER[…]} element for the given axis in the given coordinate
system.
+         * If this method does not found exactly one instance of the given axis in the given
coordinate system,
+         * then returns {@code null}. It will be caller's responsibility to declare the WKT
as invalid.
+         */
+        static Order create(final CoordinateSystem cs, final DefaultCoordinateSystemAxis
axis) {
+            Order order = null;
+            final int dimension = cs.getDimension();
+            for (int i=0; i<dimension;) {
+                if (cs.getAxis(i++) == axis) {
+                    if (order == null) {
+                        order = new Order(i);
+                    } else {
+                        return null;
+                    }
+                }
+            }
+            return order;
+        }
+
+        /**
+         * Creates new {@code ORDER[…]} element for the given sequential number.
+         */
+        private Order(final int index) {
+            this.index = index;
+        }
+
+        /**
+         * Formats the {@code ORDER[…]} element.
+         */
+        @Override
+        protected String formatTo(final Formatter formatter) {
+            formatter.append(index);
+            return "Order";
+        }
+    }
 }

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=1676236&r1=1676235&r2=1676236&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] Mon Apr 27 10:10:30 2015
@@ -181,18 +181,18 @@ public final strictfp class DefaultCompo
                 "      Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”,
1]]],\n" +
                 "      PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
                 "    CS[“ellipsoidal”, 2],\n" +
-                "      Axis[“Longitude (L)”, east],\n" +
-                "      Axis[“Latitude (B)”, north],\n" +
+                "      Axis[“Longitude (L)”, east, Order[1]],\n" +
+                "      Axis[“Latitude (B)”, north, Order[2]],\n" +
                 "      AngleUnit[“degree”, 0.017453292519943295]],\n" +
                 "  VerticalCRS[“Gravity-related height”,\n" +
                 "    VerticalDatum[“Mean Sea Level”],\n" +
                 "    CS[“vertical”, 1],\n" +
-                "      Axis[“Gravity-related height (H)”, up],\n" +
+                "      Axis[“Gravity-related height (H)”, up, Order[1]],\n" +
                 "      LengthUnit[“metre”, 1]],\n" +
                 "  TimeCRS[“Time”,\n" +
                 "    TimeDatum[“Modified Julian”, TimeOrigin[1858-11-17T00:00:00.0Z]],\n"
+
                 "    CS[“temporal”, 1],\n" +
-                "      Axis[“Time (t)”, future],\n" +
+                "      Axis[“Time (t)”, future, Order[1]],\n" +
                 "      TimeUnit[“day”, 86400]],\n" +
                 "  Area[“World”],\n" +
                 "  BBox[-90.00, -180.00, 90.00, 180.00]]",

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java?rev=1676236&r1=1676235&r2=1676236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
[UTF-8] Mon Apr 27 10:10:30 2015
@@ -71,9 +71,9 @@ public final strictfp class DefaultGeoce
                 "    Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”,
1]]],\n" +
                 "    PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
                 "  CS[“Cartesian”, 3],\n" +
-                "    Axis[“(X)”, geocentricX],\n" +
-                "    Axis[“(Y)”, geocentricY],\n" +
-                "    Axis[“(Z)”, geocentricZ],\n" +
+                "    Axis[“(X)”, geocentricX, Order[1]],\n" +
+                "    Axis[“(Y)”, geocentricY, Order[2]],\n" +
+                "    Axis[“(Z)”, geocentricZ, Order[3]],\n" +
                 "    LengthUnit[“metre”, 1]]",
                 HardCodedCRS.GEOCENTRIC);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java?rev=1676236&r1=1676235&r2=1676236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
[UTF-8] Mon Apr 27 10:10:30 2015
@@ -162,8 +162,8 @@ public final strictfp class DefaultGeogr
                 "    Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”,
1]]],\n" +
                 "    PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
                 "  CS[“ellipsoidal”, 2],\n" +
-                "    Axis[“Longitude (L)”, east],\n" +
-                "    Axis[“Latitude (B)”, north],\n" +
+                "    Axis[“Longitude (L)”, east, Order[1]],\n" +
+                "    Axis[“Latitude (B)”, north, Order[2]],\n" +
                 "    AngleUnit[“degree”, 0.017453292519943295],\n" +
                 "  Area[“World”],\n" +
                 "  BBox[-90.00, -180.00, 90.00, 180.00]]",

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=1676236&r1=1676235&r2=1676236&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] Mon Apr 27 10:10:30 2015
@@ -55,7 +55,7 @@ public final strictfp class DefaultTempo
                 "TimeCRS[“Time”,\n" +
                 "  TimeDatum[“Modified Julian”, TimeOrigin[1858-11-17T00:00:00.0Z]],\n"
+
                 "  CS[“temporal”, 1],\n" +
-                "    Axis[“Time (t)”, future],\n" +
+                "    Axis[“Time (t)”, future, Order[1]],\n" +
                 "    TimeUnit[“day”, 86400]]",
                 HardCodedCRS.TIME);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java?rev=1676236&r1=1676235&r2=1676236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
[UTF-8] Mon Apr 27 10:10:30 2015
@@ -56,7 +56,7 @@ public final strictfp class DefaultVerti
                 "VerticalCRS[“Depth”,\n" +
                 "  VerticalDatum[“Mean Sea Level”],\n" +
                 "  CS[“vertical”, 1],\n" +
-                "    Axis[“Depth (D)”, down],\n" +
+                "    Axis[“Depth (D)”, down, Order[1]],\n" +
                 "    LengthUnit[“metre”, 1]]",
                 HardCodedCRS.DEPTH);
     }



Mime
View raw message