You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/07/01 19:12:42 UTC

svn commit: r1688693 [2/2] - in /sis/trunk: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ core/sis-referencing/src/main/java/org/apache/sis/parameter/ core/sis-referencing/sr...

Modified: sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java [UTF-8] Wed Jul  1 17:12:42 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/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java [UTF-8] Wed Jul  1 17:12:42 2015
@@ -107,10 +107,9 @@ public final strictfp class DefaultVerti
         assertIsMeanSeaLevel(datum, true);
         /*
          * Following attribute does not exist in GML 3.2, so it has been inferred.
-         * Our datum name is "Mean Sea Level", which for now is not yet mapped to
-         * the geoidal type (this could change in any future SIS version).
+         * Our datum name is "Mean Sea Level", which is mapped to the geoidal type.
          */
-        assertEquals("vertDatumType", VerticalDatumType.OTHER_SURFACE, datum.getVerticalDatumType());
+        assertEquals("vertDatumType", VerticalDatumType.GEOIDAL, datum.getVerticalDatumType());
         /*
          * Values in the following tests are specific to our XML file.
          * The actual texts in the EPSG database are more descriptive.

Modified: sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java [UTF-8] Wed Jul  1 17:12:42 2015
@@ -162,7 +162,7 @@ public final strictfp class DefaultTrans
                 "    Datum[“Tokyo 1918”,\n" +
                 "      Ellipsoid[“Bessel 1841”, 6377397.155, 299.1528128, LengthUnit[“metre”, 1]]],\n" +
                 "      PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n" +
-                "    CS[“Cartesian”, 3],\n" +
+                "    CS[Cartesian, 3],\n" +
                 "      Axis[“(X)”, geocentricX, Order[1]],\n" +
                 "      Axis[“(Y)”, geocentricY, Order[2]],\n" +
                 "      Axis[“(Z)”, geocentricZ, Order[3]],\n" +
@@ -171,7 +171,7 @@ public final strictfp class DefaultTrans
                 "    Datum[“Japanese Geodetic Datum 2000”,\n" +
                 "      Ellipsoid[“GRS 1980”, 6378137.0, 298.257222101, LengthUnit[“metre”, 1]]],\n" +
                 "      PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n" +
-                "    CS[“Cartesian”, 3],\n" +
+                "    CS[Cartesian, 3],\n" +
                 "      Axis[“(X)”, geocentricX, Order[1]],\n" +
                 "      Axis[“(Y)”, geocentricY, Order[2]],\n" +
                 "      Axis[“(Z)”, geocentricZ, Order[3]],\n" +
@@ -186,7 +186,7 @@ public final strictfp class DefaultTrans
                 "  SourceCRS[GeodeticCRS[“Tokyo 1918”,\n" +
                 "    Datum[“Tokyo 1918”,\n" +
                 "      Ellipsoid[“Bessel 1841”, 6377397.155, 299.1528128]],\n" +
-                "    CS[“Cartesian”, 3],\n" +
+                "    CS[Cartesian, 3],\n" +
                 "      Axis[“(X)”, geocentricX],\n" +
                 "      Axis[“(Y)”, geocentricY],\n" +
                 "      Axis[“(Z)”, geocentricZ],\n" +
@@ -194,7 +194,7 @@ public final strictfp class DefaultTrans
                 "  TargetCRS[GeodeticCRS[“JGD2000”,\n" +
                 "    Datum[“Japanese Geodetic Datum 2000”,\n" +
                 "      Ellipsoid[“GRS 1980”, 6378137.0, 298.257222101]],\n" +
-                "    CS[“Cartesian”, 3],\n" +
+                "    CS[Cartesian, 3],\n" +
                 "      Axis[“(X)”, geocentricX],\n" +
                 "      Axis[“(Y)”, geocentricY],\n" +
                 "      Axis[“(Z)”, geocentricZ],\n" +

Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/Constants.java [UTF-8] Wed Jul  1 17:12:42 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/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/PatchedUnitFormat.java [UTF-8] Wed Jul  1 17:12:42 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/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] Wed Jul  1 17:12:42 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;

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java?rev=1688693&r1=1688692&r2=1688693&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java [UTF-8] Wed Jul  1 17:12:42 2015
@@ -28,11 +28,13 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.metadata.citation.OnLineFunction;
 import org.opengis.metadata.content.ImagingCondition;
 import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.PixelInCell;
 import org.opengis.referencing.cs.AxisDirection;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.opengis.test.Assert.*;
+import static org.apache.sis.test.Assert.PENDING_NEXT_GEOAPI_RELEASE;
 
 
 /**
@@ -40,7 +42,7 @@ import static org.opengis.test.Assert.*;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public final strictfp class TypesTest extends TestCase {
@@ -129,6 +131,16 @@ public final strictfp class TypesTest ex
         assertSame(ImagingCondition.SEMI_DARKNESS, Types.forCodeName(ImagingCondition.class, "semi darkness", false));
         assertSame(ImagingCondition.SEMI_DARKNESS, Types.forCodeName(ImagingCondition.class, "semi-darkness", false));
         assertNull(Types.forCodeName(ImagingCondition.class, "darkness", false));
+
+        assertSame(PixelInCell.CELL_CORNER, Types.forCodeName(PixelInCell.class, "cell corner", false));
+        assertSame(PixelInCell.CELL_CORNER, Types.forCodeName(PixelInCell.class, "cellCorner",  false));
+        assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cell center", false));
+        assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cellCenter",  false));
+
+        if (PENDING_NEXT_GEOAPI_RELEASE) {
+            assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cell centre", false));
+            assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cellCentre",  false));
+        }
     }
 
     /**