sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1688613 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-referencing/src/test/java/o...
Date Wed, 01 Jul 2015 10:31:08 GMT
Author: desruisseaux
Date: Wed Jul  1 10:31:07 2015
New Revision: 1688613

URL: http://svn.apache.org/r1688613
Log:
WKT 2: be careful about sexagesimal units. Convert them to degrees when possible.
Note that this is possible for parameters and prime meridian, but not fox axes
(and consequently not for the unit that apply to a CoordinateSystem as a whole)
because axis units apply to numbers outside the CRS definition.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.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/cs/DefaultCoordinateSystemAxisTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.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/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=1688613&r1=1688612&r2=1688613&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 Jul  1 10:31:07 2015
@@ -47,6 +47,7 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.referencing.operation.MathTransform;
@@ -1154,24 +1155,20 @@ public class Formatter implements Locali
             appendExact(conversion);
             /*
              * The EPSG code in UNIT elements is generally not recommended.
-             * But we make an exception for unit that have no exact representation in WKT.
+             * But we make an exception for sexagesimal units (EPSG:9108, 9110 and 9111)
+             * because they can not be represented by a simple scale factor in WKT.
              */
-            final Integer code = Units.getEpsgCode(unit, false);
-            if (code != null) {
-                final int n = code;
-                switch (n) {
-                    case Constants.EPSG_DM:
-                    case Constants.EPSG_DMS:
-                    case Constants.EPSG_DMSH: {
-                        openElement(false, isWKT1 ? WKTKeywords.Authority : WKTKeywords.Id);
-                        append(Constants.EPSG, null);
-                        if (isWKT1) {
-                            append(Integer.toString(n), null);
-                        } else {
-                            append(n);
-                        }
-                        closeElement(false);
+            if (convention == Convention.INTERNAL || PatchedUnitFormat.toFormattable(unit)
!= unit) {
+                final Integer code = Units.getEpsgCode(unit, getEnclosingElement(1) instanceof
CoordinateSystemAxis);
+                if (code != null) {
+                    openElement(false, isWKT1 ? WKTKeywords.Authority : WKTKeywords.Id);
+                    append(Constants.EPSG, null);
+                    if (isWKT1) {
+                        append(code.toString(), null);
+                    } else {
+                        append(code);
                     }
+                    closeElement(false);
                 }
             }
             closeElement(false);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -35,6 +35,7 @@ import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.io.wkt.ElementKind;
 import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.metadata.WKTKeywords;
+import org.apache.sis.internal.util.PatchedUnitFormat;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.ComparisonMode;
@@ -241,7 +242,7 @@ public class DefaultParameterValue<T> ex
         if (value instanceof Boolean) {
             return (Boolean) value;
         }
-        throw incompatibleValue(value);
+        throw missingOrIncompatibleValue(value);
     }
 
     /**
@@ -268,7 +269,7 @@ public class DefaultParameterValue<T> ex
                 return integer;
             }
         }
-        throw incompatibleValue(value);
+        throw missingOrIncompatibleValue(value);
     }
 
     /**
@@ -292,7 +293,7 @@ public class DefaultParameterValue<T> ex
         if (value instanceof int[]) {
             return ((int[]) value).clone();
         }
-        throw incompatibleValue(value);
+        throw missingOrIncompatibleValue(value);
     }
 
     /**
@@ -318,7 +319,7 @@ public class DefaultParameterValue<T> ex
         if (value instanceof Number) {
             return ((Number) value).doubleValue();
         }
-        throw incompatibleValue(value);
+        throw missingOrIncompatibleValue(value);
     }
 
     /**
@@ -343,7 +344,7 @@ public class DefaultParameterValue<T> ex
         if (value instanceof double[]) {
             return ((double[]) value).clone();
         }
-        throw incompatibleValue(value);
+        throw missingOrIncompatibleValue(value);
     }
 
     /**
@@ -438,7 +439,7 @@ public class DefaultParameterValue<T> ex
         if (value instanceof CharSequence) {
             return value.toString();
         }
-        throw incompatibleValue(value);
+        throw missingOrIncompatibleValue(value);
     }
 
     /**
@@ -490,7 +491,7 @@ public class DefaultParameterValue<T> ex
     /**
      * Returns the exception to throw when an incompatible method is invoked for the value
type.
      */
-    private IllegalStateException incompatibleValue(final Object value) {
+    private IllegalStateException missingOrIncompatibleValue(final Object value) {
         final String name = Verifier.getName(descriptor);
         if (value != null) {
             return new InvalidParameterTypeException(getClassTypeError(), name);
@@ -877,45 +878,70 @@ public class DefaultParameterValue<T> ex
     protected String formatTo(final Formatter formatter) {
         final ParameterDescriptor<T> descriptor = getDescriptor();  // Gives to users
a chance to override this property.
         WKTUtilities.appendName(descriptor, formatter, ElementKind.PARAMETER);
-        final Unit<?> targetUnit = formatter.toContextualUnit(descriptor.getUnit());
         final Convention convention = formatter.getConvention();
         final boolean isWKT1 = convention.majorVersion() == 1;
-        /*
-         * In the WKT 1 specification, the unit of measurement is given by the context.
-         * If this parameter value does not use the same unit, then we must convert it.
-         * Otherwise we can write the value as-is.
-         */
-        final T       value = getValue();   // Gives to users a chance to override this property.
-        final Unit<?> unit  = getUnit();    // Gives to users a chance to override
this property.
-        double convertedValue = Double.NaN;
-        boolean sameUnit = Objects.equals(unit, targetUnit);
-        if (!sameUnit) try {
-            convertedValue = doubleValue(targetUnit);
-            sameUnit = (value instanceof Number) && ((Number) value).doubleValue()
== convertedValue;
-        } catch (IllegalStateException exception) {
-            // May happen if a parameter is mandatory (e.g. "semi-major")
-            // but no value has been set for this parameter.
-            formatter.setInvalidWKT(descriptor, exception);
-        }
-        if (isWKT1 && !sameUnit) {
-            formatter.append(convertedValue);
-        } else if (!isWKT1 && (unit == null) && isFile(value)) {
-            formatter.append(value.toString(), null);
-            return WKTKeywords.ParameterFile;
+        Unit<?> unit = getUnit();   // Gives to users a chance to override this property.
+        if (unit == null) {
+            final T value = getValue();   // Gives to users a chance to override this property.
+            if (!isWKT1 && isFile(value)) {
+                formatter.append(value.toString(), null);
+                return WKTKeywords.ParameterFile;
+            } else {
+                formatter.appendAny(value);
+            }
         } else {
-            formatter.appendAny(value);
-        }
-        /*
-         * In the WKT 2 specification, the unit and the identifier are optional but recommended.
-         * We follow that recommendation in strict WKT2 mode, but omit them in non-strict
modes.
-         * The only exception is when the parameter unit is not the same than the contextual
unit,
-         * in which case we have no choice: we must format that unit, unless the numerical
value
-         * is identical in both units (typically the 0 value).
-         */
-        if (!isWKT1 && (!sameUnit || !convention.isSimplified() || !hasContextualUnit(formatter)))
{
-            formatter.append(unit);
-            // ID will be added by the Formatter itself.
+            /*
+             * In the WKT 1 specification, the unit of measurement is given by the context.
+             * If this parameter value does not use the same unit, we will need to convert
it.
+             * Otherwise we can write the value as-is.
+             *
+             * Note that we take the descriptor unit as a starting point instead than this
parameter unit
+             * in order to give precedence to the descriptor units in Convention.WKT1_COMMON_UNITS
mode.
+             */
+            Unit<?> contextualUnit = descriptor.getUnit();
+            if (contextualUnit == null) { // Should be very rare (probably a buggy descriptor),
but we try to be safe.
+                contextualUnit = unit;
+            }
+            contextualUnit = formatter.toContextualUnit(contextualUnit);
+            boolean ignoreUnits;
+            if (isWKT1) {
+                unit = contextualUnit;
+                ignoreUnits = true;
+            } else {
+                if (convention != Convention.INTERNAL) {
+                    unit = PatchedUnitFormat.toFormattable(unit);
+                }
+                ignoreUnits = unit.equals(contextualUnit);
+            }
+            double value;
+            try {
+                value = doubleValue(unit);
+            } catch (IllegalStateException exception) {
+                // May happen if a parameter is mandatory (e.g. "semi-major")
+                // but no value has been set for this parameter.
+                formatter.setInvalidWKT(descriptor, exception);
+                value = Double.NaN;
+            }
+            formatter.append(value);
+            /*
+             * In the WKT 2 specification, the unit and the identifier are optional but recommended.
+             * We follow that recommendation in strict WKT2 mode, but omit them in non-strict
modes.
+             * The only exception is when the parameter unit is not the same than the contextual
unit,
+             * in which case we have no choice: we must format that unit, unless the numerical
value
+             * is identical in both units (typically the 0 value).
+             */
+            if (!ignoreUnits && !Double.isNaN(value)) {
+                ignoreUnits = Numerics.equals(value, doubleValue(contextualUnit));
+            }
+            if (!ignoreUnits || !convention.isSimplified() || !hasContextualUnit(formatter))
{
+                if (!isWKT1) {
+                    formatter.append(unit);
+                } else if (!ignoreUnits) {
+                    formatter.setInvalidWKT(descriptor, null);
+                }
+            }
         }
+        // ID will be added by the Formatter itself.
         return WKTKeywords.Parameter;
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -29,6 +29,7 @@ import org.opengis.metadata.Identifier;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.internal.util.PatchedUnitFormat;
 import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.internal.jaxb.gco.Measure;
 import org.apache.sis.internal.util.Numerics;
@@ -235,11 +236,11 @@ public class DefaultPrimeMeridian extend
      *     double longitudeInDegrees = primeMeridian.getGreenwichLongitude(NonSI.DEGREE_ANGLE);
      * }
      *
-     * @param targetUnit The unit in which to express longitude.
+     * @param unit The unit in which to express longitude.
      * @return The Greenwich longitude in the given units.
      */
-    public double getGreenwichLongitude(final Unit<Angle> targetUnit) {
-        return getAngularUnit().getConverterTo(targetUnit).convert(getGreenwichLongitude());
+    public double getGreenwichLongitude(final Unit<Angle> unit) {
+        return getAngularUnit().getConverterTo(unit).convert(getGreenwichLongitude());
     }
 
     /**
@@ -384,8 +385,8 @@ public class DefaultPrimeMeridian extend
      * below the {@code PRIMEM[…]} one, which happen if we are inside a base CRS.
      * See {@link #isElementOfBaseCRS(Formatter)} for more discussion.
      */
-    private static boolean beConservative(final Formatter formatter, final Unit<Angle>
targetUnit) {
-        return !targetUnit.equals(NonSI.DEGREE_ANGLE) && !isElementOfBaseCRS(formatter);
+    private static boolean beConservative(final Formatter formatter, final Unit<Angle>
contextualUnit) {
+        return !contextualUnit.equals(NonSI.DEGREE_ANGLE) && !isElementOfBaseCRS(formatter);
     }
 
     /**
@@ -398,16 +399,22 @@ public class DefaultPrimeMeridian extend
     @Override
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
-        final Convention convention = formatter.getConvention();
-        final boolean isWKT1 = convention.majorVersion() == 1;
-        final Unit<Angle> targetUnit = formatter.toContextualUnit(NonSI.DEGREE_ANGLE);
-        formatter.append(isWKT1 ? getGreenwichLongitude(targetUnit) : getGreenwichLongitude());
+        final Convention  convention = formatter.getConvention();
+        final boolean     isWKT1 = (convention.majorVersion() == 1);
+        final Unit<Angle> contextualUnit = formatter.toContextualUnit(NonSI.DEGREE_ANGLE);
+        Unit<Angle> unit = contextualUnit;
+        if (!isWKT1) {
+            unit = getAngularUnit();
+            if (convention != Convention.INTERNAL) {
+                unit = PatchedUnitFormat.toFormattable(unit);
+            }
+        }
+        formatter.append(getGreenwichLongitude(unit));
         if (isWKT1) {
             return WKTKeywords.PrimeM;
         }
-        final Unit<Angle> angularUnit = getAngularUnit();   // Gives to users a chance
to override properties.
-        if (!convention.isSimplified() || !targetUnit.equals(angularUnit) || beConservative(formatter,
targetUnit)) {
-            formatter.append(angularUnit);
+        if (!convention.isSimplified() || !contextualUnit.equals(unit) || beConservative(formatter,
contextualUnit)) {
+            formatter.append(unit);
         }
         return WKTKeywords.PrimeMeridian;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -26,6 +26,7 @@ import org.opengis.parameter.InvalidPara
 import org.opengis.parameter.InvalidParameterValueException;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.io.wkt.Convention;
+import org.apache.sis.measure.Units;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -596,6 +597,22 @@ public final strictfp class DefaultParam
     }
 
     /**
+     * Tests WKT formatting of a parameter with sexagesimal units.
+     * Since those units can not be formatted in a {@code UNIT["name", scale]} element,
+     * the formatter should convert them to a formattable unit like degrees.
+     *
+     * @since 0.6
+     */
+    @Test
+    @DependsOnMethod("testWKT")
+    public void testWKT_withUnformattableUnit() {
+        final DefaultParameterValue<Double> p = create("Angle", 10.3, Units.valueOfEPSG(9111));
+        assertWktEquals(Convention.WKT1,     "PARAMETER[“Angle”, 10.3]", p);  // 10.3
DM  ==  10.5°
+        assertWktEquals(Convention.WKT2,     "Parameter[“Angle”, 10.5, AngleUnit[“degree”,
0.017453292519943295]]", p);
+        assertWktEquals(Convention.INTERNAL, "Parameter[“Angle”, 10.3, Unit[“D.M”,
0.017453292519943295, Id[“EPSG”, 9111]]]", p);
+    }
+
+    /**
      * Tests WKT formatting of a parameter having an identifier.
      *
      * @since 0.6

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=1688613&r1=1688612&r2=1688613&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] Wed Jul  1 10:31:07 2015
@@ -143,7 +143,7 @@ public final strictfp class DefaultGeoce
                 "    Axis[“Geocentric X (X)”, geocentricX],\n" +
                 "    Axis[“Geocentric Y (Y)”, geocentricY],\n" +
                 "    Axis[“Geocentric Z (Z)”, geocentricZ],\n" +
-                "    Unit[“metre”, 1]]",
+                "    Unit[“metre”, 1, Id[“EPSG”, 9001]]]",
                 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=1688613&r1=1688612&r2=1688613&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] Wed Jul  1 10:31:07 2015
@@ -200,7 +200,7 @@ public final strictfp class DefaultGeogr
                 "  CS[“ellipsoidal”, 2],\n" +
                 "    Axis[“Geodetic longitude (λ)”, east],\n" +
                 "    Axis[“Geodetic latitude (φ)”, north],\n" +
-                "    Unit[“degree”, 0.017453292519943295],\n" +
+                "    Unit[“degree”, 0.017453292519943295, Id[“EPSG”, 9102]],\n" +
                 "  Area[“World”],\n" +
                 "  BBox[-90.00, -180.00, 90.00, 180.00]]",
                 HardCodedCRS.WGS84);

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxisTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxisTest.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxisTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxisTest.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -104,10 +104,10 @@ public final strictfp class DefaultCoord
         assertWktEquals(Convention.WKT1,     "AXIS[“x”, EAST]",  X);
         assertWktEquals(Convention.WKT1,     "AXIS[“y”, NORTH]", Y);
         assertWktEquals(Convention.WKT1,     "AXIS[“z”, UP]",    Z);
-        assertWktEquals(Convention.INTERNAL, "Axis[“Geodetic longitude (λ)”, east, Unit[“degree”,
0.017453292519943295]]",   GEODETIC_LONGITUDE);
-        assertWktEquals(Convention.INTERNAL, "Axis[“Spherical longitude (θ)”, east,
Unit[“degree”, 0.017453292519943295]]",  SPHERICAL_LONGITUDE);
-        assertWktEquals(Convention.INTERNAL, "Axis[“Geodetic latitude (φ)”, north, Unit[“degree”,
0.017453292519943295]]",   GEODETIC_LATITUDE);
-        assertWktEquals(Convention.INTERNAL, "Axis[“Spherical latitude (φ′)”, north,
Unit[“degree”, 0.017453292519943295]]", SPHERICAL_LATITUDE);
+        assertWktEquals(Convention.INTERNAL, "Axis[“Geodetic longitude (λ)”, east, Unit[“degree”,
0.017453292519943295, Id[“EPSG”, 9102]]]",   GEODETIC_LONGITUDE);
+        assertWktEquals(Convention.INTERNAL, "Axis[“Spherical longitude (θ)”, east,
Unit[“degree”, 0.017453292519943295, Id[“EPSG”, 9102]]]",  SPHERICAL_LONGITUDE);
+        assertWktEquals(Convention.INTERNAL, "Axis[“Geodetic latitude (φ)”, north, Unit[“degree”,
0.017453292519943295, Id[“EPSG”, 9102]]]",   GEODETIC_LATITUDE);
+        assertWktEquals(Convention.INTERNAL, "Axis[“Spherical latitude (φ′)”, north,
Unit[“degree”, 0.017453292519943295, Id[“EPSG”, 9102]]]", SPHERICAL_LATITUDE);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.datum;
 
 import javax.measure.unit.NonSI;
+import javax.measure.quantity.Angle;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
@@ -24,6 +25,7 @@ import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.util.CharSequences;
+import org.apache.sis.measure.Units;
 import org.apache.sis.internal.jaxb.LegacyNamespaces;
 import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.test.XMLTestCase;
@@ -31,6 +33,7 @@ import org.apache.sis.test.DependsOnMeth
 import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
+import static java.util.Collections.singletonMap;
 import static org.apache.sis.test.MetadataAssert.*;
 import static org.apache.sis.referencing.GeodeticObjectVerifier.*;
 import static org.apache.sis.test.mock.PrimeMeridianMock.GREENWICH;
@@ -62,6 +65,41 @@ public final strictfp class DefaultPrime
     }
 
     /**
+     * Tests WKT formatting of a prime meridian in grad units.
+     *
+     * @since 0.6
+     */
+    @Test
+    @DependsOnMethod("testToWKT")
+    public void testWKT_inGrads() {
+        final DefaultPrimeMeridian pm = HardCodedDatum.PARIS;
+        assertWktEquals(Convention.WKT1, "PRIMEM[“Paris”, 2.33722917, AUTHORITY[“EPSG”,
“8903”]]", pm);
+        assertWktEquals(Convention.WKT2_SIMPLIFIED, "PrimeMeridian[“Paris”, 2.5969213,
Unit[“grade”, 0.015707963267948967],"
+                + " Id[“EPSG”, 8903, URI[“urn:ogc:def:meridian:EPSG::8903”]]]", pm);
+    }
+
+    /**
+     * Tests WKT formatting of a prime meridian with sexagesimal units.
+     * Since those units can not be formatted in a {@code UNIT["name", scale]} element,
+     * the formatter should convert them to a formattable unit like degrees.
+     *
+     * @since 0.6
+     */
+    @Test
+    @DependsOnMethod("testWKT_inGrads")
+    public void testWKT_withUnformattableUnit() {
+        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(singletonMap(DefaultPrimeMeridian.NAME_KEY,
"Test"),
+                10.3, Units.valueOfEPSG(9111).asType(Angle.class));
+        /*
+         * In WKT 1 format, if there is no contextual unit (which is the case of this test),
+         * the formatter default to decimal degrees. In WKT 2 format it depends on the PM
unit.
+         */
+        assertWktEquals(Convention.WKT1,            "PRIMEM[“Test”, 10.5]", pm);  //
10.3 DM  ==  10.5°
+        assertWktEquals(Convention.WKT2,     "PrimeMeridian[“Test”, 10.5, AngleUnit[“degree”,
0.017453292519943295]]", pm);
+        assertWktEquals(Convention.INTERNAL, "PrimeMeridian[“Test”, 10.3, Unit[“D.M”,
0.017453292519943295, Id[“EPSG”, 9111]]]", pm);
+    }
+
+    /**
      * Returns a XML representation of Greenwich prime meridian using the given GML namespace
URI.
      *
      * @param  namespace The GML namespace.
@@ -140,7 +178,7 @@ public final strictfp class DefaultPrime
      * @throws JAXBException If an error occurred during unmarshalling.
      */
     @Test
-    @DependsOnMethod({"testUnmarshall", "testMarshall"})
+    @DependsOnMethod({"testUnmarshall", "testMarshall", "testWKT_inGrads"})
     public void testParisMeridian() throws JAXBException {
         final DefaultPrimeMeridian pm = unmarshalFile(DefaultPrimeMeridian.class, "Paris.xml");
         assertIsParis(pm);
@@ -152,7 +190,7 @@ public final strictfp class DefaultPrime
         assertWktEquals(Convention.WKT2,
                 "PrimeMeridian[“Paris”, 2.5969213, AngleUnit[“grade”, 0.015707963267948967],
Id[“EPSG”, 8903, URI[“urn:ogc:def:meridian:EPSG::8903”]]]", pm);
         assertWktEquals(Convention.INTERNAL,
-                "PrimeMeridian[“Paris”, 2.5969213, Unit[“grade”, 0.015707963267948967],
Id[“EPSG”, 8903],\n" +
+                "PrimeMeridian[“Paris”, 2.5969213, Unit[“grade”, 0.015707963267948967,
Id[“EPSG”, 9105]], Id[“EPSG”, 8903],\n" +
                 "  Remark[“Equivalent to 2°20′14.025″.”]]", pm);
         assertXmlEquals(
                 "<gml:PrimeMeridian xmlns:gml=\"" + Namespaces.GML + "\">\n" +

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -151,23 +151,6 @@ public final class Constants extends Sta
     public static final short EPSG_B0 = 8639;
 
     /**
-     * The EPSG code of the "degree minute second hemisphere" pseudo-unit.
-     * Different symbol sets (º ' ") may be in use as field separators.
-     * Ends with hemisphere abbreviation (single character N S E or W).
-     */
-    public static final short EPSG_DMSH = 9108;
-
-    /**
-     * The EPSG code of the "sexagesimal DMS" pseudo-unit.
-     */
-    public static final short EPSG_DMS = 9110;
-
-    /**
-     * The EPSG code of the "sexagesimal DM" pseudo-unit.
-     */
-    public static final short EPSG_DM = 9111;
-
-    /**
      * Do not allow instantiation of this class.
      */
     private Constants() {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java?rev=1688613&r1=1688612&r2=1688613&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java
[UTF-8] Wed Jul  1 10:31:07 2015
@@ -25,6 +25,7 @@ import javax.measure.unit.NonSI;
 import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
 import javax.measure.unit.UnitFormat;
+import javax.measure.quantity.Quantity;
 import org.apache.sis.measure.Units;
 import org.apache.sis.util.Workaround;
 
@@ -96,6 +97,24 @@ public final class PatchedUnitFormat ext
     }
 
     /**
+     * If the given unit is one of the unit that can not be formatted without ambiguity in
WKT format,
+     * return a proposed replacement. Otherwise returns {@code unit} unchanged.
+     *
+     * @param  <Q> The unit dimension.
+     * @param  unit The unit to test.
+     * @return The replacement to format, or {@code unit} if not needed.
+     */
+    @SuppressWarnings("unchecked")
+    public static <Q extends Quantity> Unit<Q> toFormattable(Unit<Q> unit)
{
+        final Map<Unit<?>,String> symbols = SYMBOLS;
+        if (symbols != null && symbols.containsKey(unit)) {
+            assert Units.isAngular(unit);
+            unit = (Unit<Q>) NonSI.DEGREE_ANGLE;
+        }
+        return unit;
+    }
+
+    /**
      * Returns the string representation of the given unit, or {@code null} if none.
      * This method is used as a workaround for a bug in JSR-275, which sometime throws
      * an exception in the {@link Unit#toString()} method.

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=1688613&r1=1688612&r2=1688613&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 Jul  1 10:31:07 2015
@@ -559,9 +559,9 @@ public final class Units extends Static
             case 9105: return NonSI.GRADE;
             case 9109: return SI.MetricPrefix.MICRO(SI.RADIAN);
             case 9107: // Fall through
-            case Constants.EPSG_DMSH: return SexagesimalConverter.DMS_SCALED;
-            case Constants.EPSG_DM:   return SexagesimalConverter.DM;
-            case Constants.EPSG_DMS:  return SexagesimalConverter.DMS;
+            case 9108: return SexagesimalConverter.DMS_SCALED;
+            case 9110: return SexagesimalConverter.DMS;
+            case 9111: return SexagesimalConverter.DM;
             case 9203: // Fall through
             case 9201: return Unit .ONE;
             case 9202: return Units.PPM;



Mime
View raw message