sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1684198 - in /sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis: io/wkt/GeodeticObjectParserTest.java referencing/crs/DefaultGeographicCRSTest.java referencing/crs/DefaultProjectedCRSTest.java
Date Mon, 08 Jun 2015 14:39:37 GMT
Author: desruisseaux
Date: Mon Jun  8 14:39:37 2015
New Revision: 1684198

URL: http://svn.apache.org/r1684198
Log:
WKT: added tests.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.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/DefaultProjectedCRSTest.java

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=1684198&r1=1684197&r2=1684198&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] Mon Jun  8 14:39:37 2015
@@ -79,6 +79,14 @@ public final strictfp class GeodeticObje
     }
 
     /**
+     * Uses a new parser for the given convention.
+     */
+    private void setConvention(final Convention convention, final boolean isAxisIgnored)
{
+        final GeodeticObjectParser p = parser;
+        parser = new GeodeticObjectParser(p.symbols, convention, isAxisIgnored, p.errorLocale,
null);
+    }
+
+    /**
      * Asserts that the name and (optionally) the EPSG identifier of the given object
      * are equal to the given strings.
      *
@@ -196,6 +204,8 @@ public final strictfp class GeodeticObje
      * Tests the parsing of a geographic CRS from a WKT 1 string that does not declare explicitly
the axes.
      *
      * @throws ParseException if the parsing failed.
+     *
+     * @see #testImplicitAxesInSeconds()
      */
     @Test
     @DependsOnMethod("testGeographicCRS")
@@ -286,6 +296,72 @@ public final strictfp class GeodeticObje
     }
 
     /**
+     * Tests parsing of a CRS using a prime meridian other than Greenwich. The result depends
on whether
+     * the parsing is standard compliant or if the parsing use {@link Convention#WKT1_COMMON_UNITS}.
+     *
+     * @throws ParseException if the parsing failed.
+     */
+    @Test
+    @DependsOnMethod("testGeographicCRS")
+    public void testNonGreenwichMeridian() throws ParseException {
+        String wkt = "GEOGCS[“NTF (Paris)”,\n" +
+                     "  DATUM[“Nouvelle Triangulation Française (Paris)”,\n" +
+                     "    SPHEROID[“Clarke 1880 (IGN)”, 6378249.2, 293.4660212936269]],\n"
+
+                     "    PRIMEM[“Paris”, 2.5969213, AUTHORITY[“EPSG”, “8903”]],\n"
+
+                     "  UNIT[“grade”, 0.015707963267948967],\n" +
+                     "  AXIS[“Latitude”, NORTH],\n" +
+                     "  AXIS[“Longitude”, EAST]]";
+
+        GeographicCRS crs = parse(GeographicCRS.class, wkt);
+        assertNameAndIdentifierEqual("NTF (Paris)", 0, crs);
+        PrimeMeridian pm = verifyNTF(crs.getDatum());
+        assertEquals("angularUnit", NonSI.GRADE, pm.getAngularUnit());
+        assertEquals("greenwichLongitude", 2.5969213, pm.getGreenwichLongitude(), STRICT);
+        EllipsoidalCS cs = crs.getCoordinateSystem();
+        assertEquals("dimension", 2, cs.getDimension());
+        assertAxisEquals(AxisNames.GEODETIC_LATITUDE,  "φ", AxisDirection.NORTH, -100, +100,
NonSI.GRADE, RangeMeaning.EXACT,      cs.getAxis(0));
+        assertAxisEquals(AxisNames.GEODETIC_LONGITUDE, "λ", AxisDirection.EAST,  -200, +200,
NonSI.GRADE, RangeMeaning.WRAPAROUND, cs.getAxis(1));
+        /*
+         * Parse again using Convention.WKT1_COMMON_UNITS and ignoring AXIS[…] elements
(but not the UNIT[…] element,
+         * which still apply to the axes). When using this convention, the parser does not
apply the angular units to
+         * the Greenwich longitude value in PRIMEM[…] elements. Instead, the longitude
is unconditionally interpreted
+         * as a value in degrees, which is why we convert "2.5969213" grade to "2.33722917"
degrees in the WKT before
+         * to run the test (but we do NOT change the UNIT[…] element since the purpose
of this test is to verify that
+         * those units are ignored).
+         *
+         * This is a violation of both OGC 01-009 and ISO 19162 standards, but this is what
GDAL does.
+         * So we allow this interpretation in Convention.WKT1_COMMON_UNITS for compatibility
reasons.
+         */
+        wkt = wkt.replace("2.5969213", "2.33722917");
+        setConvention(Convention.WKT1_COMMON_UNITS, true);
+        crs = parse(GeographicCRS.class, wkt);
+        assertNameAndIdentifierEqual("NTF (Paris)", 0, crs);
+        pm = verifyNTF(crs.getDatum());
+        assertEquals("angularUnit", NonSI.DEGREE_ANGLE, pm.getAngularUnit());
+        assertEquals("greenwichLongitude", 2.33722917, pm.getGreenwichLongitude(), STRICT);
+        cs = crs.getCoordinateSystem();
+        assertEquals("dimension", 2, cs.getDimension());
+        assertAxisEquals(AxisNames.GEODETIC_LONGITUDE, "λ", AxisDirection.EAST,  -200, +200,
NonSI.GRADE, RangeMeaning.WRAPAROUND, cs.getAxis(0));
+        assertAxisEquals(AxisNames.GEODETIC_LATITUDE,  "φ", AxisDirection.NORTH, -100, +100,
NonSI.GRADE, RangeMeaning.EXACT,      cs.getAxis(1));
+    }
+
+    /**
+     * Verifies some invariant of the CRS parsed by {@link #testNonGreenwichMeridian()}.
+     */
+    private static PrimeMeridian verifyNTF(final GeodeticDatum datum) {
+        assertNameAndIdentifierEqual("Nouvelle Triangulation Française (Paris)", 0, datum);
+
+        final Ellipsoid ellipsoid = datum.getEllipsoid();
+        assertNameAndIdentifierEqual("Clarke 1880 (IGN)", 0, ellipsoid);
+        assertEquals("semiMajor", 6378249.2, ellipsoid.getSemiMajorAxis(), STRICT);
+        assertEquals("inverseFlattening", 293.4660212936269, ellipsoid.getInverseFlattening(),
STRICT);
+
+        final PrimeMeridian pm = datum.getPrimeMeridian();
+        assertNameAndIdentifierEqual("Paris", 8903, pm);
+        return pm;
+    }
+
+    /**
      * Tests the parsing of a compound CRS from a WKT 1 string, except the time dimension
which is WKT 2.
      *
      * @throws ParseException if the parsing failed.
@@ -341,4 +417,50 @@ public final strictfp class GeodeticObje
         assertUnboundedAxisEquals("Gravity-related height", "H", AxisDirection.UP, SI.METRE,
cs.getAxis(2));
         assertUnboundedAxisEquals("Time", "t", AxisDirection.FUTURE, NonSI.DAY, cs.getAxis(3));
     }
+
+    /**
+     * Tests parsing geographic CRS with implicit axes in seconds instead of degrees.
+     *
+     * @throws ParseException if the parsing failed.
+     *
+     * @see #testImplicitAxes()
+     */
+    @Test
+    @DependsOnMethod("testImplicitAxes")
+    public void testImplicitAxesInSeconds() throws ParseException {
+        final GeographicCRS crs = parse(GeographicCRS.class,
+                "GEOGCS[“NAD83 / NFIS Seconds”," +
+                "DATUM[“North_American_Datum_1983”,\n" +
+                "SPHEROID[“GRS 1980”, 6378137, 298.257222101]],\n" +
+                "PRIMEM[“Greenwich”, 0],\n" +
+                "UNIT[“Decimal_Second”, 4.84813681109536e-06],\n" +
+                "AUTHORITY[“EPSG”, “100001”]]");
+
+        assertNameAndIdentifierEqual("NAD83 / NFIS Seconds", 100001, crs);
+
+        final GeodeticDatum datum = crs.getDatum();
+        assertNameAndIdentifierEqual("North_American_Datum_1983", 0, datum);
+        assertNameAndIdentifierEqual("Greenwich", 0, datum.getPrimeMeridian());
+
+        final Ellipsoid ellipsoid = datum.getEllipsoid();
+        assertNameAndIdentifierEqual("GRS 1980", 0, ellipsoid);
+        assertEquals("semiMajor", 6378137, ellipsoid.getSemiMajorAxis(), STRICT);
+        assertEquals("inverseFlattening", 298.257222101, ellipsoid.getInverseFlattening(),
STRICT);
+
+        final EllipsoidalCS cs = crs.getCoordinateSystem();
+        final double secondsIn90 = 90*60*60;
+        CoordinateSystemAxis axis = cs.getAxis(0);
+        assertEquals("name", AxisNames.GEODETIC_LONGITUDE, axis.getName().getCode());
+        assertEquals("abbreviation", "λ",                  axis.getAbbreviation());
+        assertEquals("direction",    AxisDirection.EAST,   axis.getDirection());
+        assertEquals("minimumValue", -secondsIn90*2,       axis.getMinimumValue(), 1E-9);
+        assertEquals("maximumValue", +secondsIn90*2,       axis.getMaximumValue(), 1E-9);
+
+        axis = cs.getAxis(1);
+        assertEquals("name", AxisNames.GEODETIC_LATITUDE,  axis.getName().getCode());
+        assertEquals("abbreviation", "φ",                  axis.getAbbreviation());
+        assertEquals("direction",    AxisDirection.NORTH,  axis.getDirection());
+        assertEquals("minimumValue", -secondsIn90,         axis.getMinimumValue(), 1E-9);
+        assertEquals("maximumValue", +secondsIn90,         axis.getMaximumValue(), 1E-9);
+    }
 }

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=1684198&r1=1684197&r2=1684198&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 Jun  8 14:39:37 2015
@@ -205,4 +205,45 @@ public final strictfp class DefaultGeogr
                 "  BBox[-90.00, -180.00, 90.00, 180.00]]",
                 HardCodedCRS.WGS84);
     }
+
+    /**
+     * Tests WKT 2 formatting on a CRS using a prime meridian other than Greenwich.
+     *
+     * <p>This CRS used in this test is equivalent to {@code EPSG:4807} except for
axis order and units
+     * of measurement, since EPSG defines (<var>latitude</var>, <var>longitude</var>)
in grades.</p>
+     */
+    @Test
+    @DependsOnMethod("testWKT2")
+    public void testWKT2_ForNonGreenwich() {
+        assertWktEquals(Convention.WKT2_SIMPLIFIED,
+                "GeodeticCRS[“NTF (Paris)”,\n" +
+                "  Datum[“Nouvelle Triangulation Francaise”,\n" +           // Formatter
should replace "ç" by "c".
+                "    Ellipsoid[“NTF”, 6378249.2, 293.4660212936269]],\n" +
+                "    PrimeMeridian[“Paris”, 2.5969213, Unit[“grade”, 0.015707963267948967]],\n"
+
+                "  CS[“ellipsoidal”, 2],\n" +
+                "    Axis[“Longitude (L)”, east],\n" +                      // See method
javadoc.
+                "    Axis[“Latitude (B)”, north],\n" +
+                "    Unit[“degree”, 0.017453292519943295]]",                // See method
javadoc.
+                HardCodedCRS.NTF);
+    }
+
+    /**
+     * Tests WKT 1 formatting using {@link Convention#WKT1_COMMON_UNITS}. That convention
ignores the unit of
+     * measurement in {@code PRIMEM} element, and rather unconditionally interpret the angle
unit as degrees.
+     * In order to avoid ambiguity, SIS in {@code WKT1_COMMON_UNITS} mode should declare
explicitely that the
+     * units are degrees.
+     */
+    @Test
+    @DependsOnMethod("testWKT2_ForNonGreenwich")
+    public void testWKT1_WithCommonUnits() {
+        assertWktEquals(Convention.WKT1_COMMON_UNITS,
+                "GEOGCS[“NTF (Paris)”,\n" +
+                "  DATUM[“Nouvelle Triangulation Francaise”,\n" +   // Formatter should
replace "ç" by "c".
+                "    SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],\n" +
+                "    PRIMEM[“Paris”, 2.33722917],\n" +
+                "  UNIT[“degree”, 0.017453292519943295],\n" +       // Formatter should
replace "grade" by "degree".
+                "  AXIS[“Longitude”, EAST],\n" +
+                "  AXIS[“Latitude”, NORTH]]",
+                HardCodedCRS.NTF);
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java?rev=1684198&r1=1684197&r2=1684198&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
[UTF-8] Mon Jun  8 14:39:37 2015
@@ -135,6 +135,85 @@ public final strictfp class DefaultProje
     }
 
     /**
+     * Tests WKT 1 formatting of a pseudo-projection with explicit {@code "semi-major"} and
{@code "semi-minor"}
+     * parameter values. This was a way to define the Google pseudo-projection using standard
projection method
+     * name before EPSG introduced the <cite>"Popular Visualisation Pseudo Mercator"</cite>
projection method.
+     * The approach tested in this method is now deprecated at least for the Google projection
(while it may
+     * still be useful for other projections), but we still test it for compatibility reasons.
+     *
+     * @throws FactoryException if the CRS creation failed.
+     */
+    @Test
+    @DependsOnMethod("testWKT1")
+    public void testWKT1_WithExplicitAxisLength() throws FactoryException {
+        final ProjectedCRS crs = new GeodeticObjectBuilder()
+                .setConversionMethod("Mercator (variant A)")
+                .setConversionName("Popular Visualisation Pseudo-Mercator")
+                .setParameter("semi-major", 6378137, SI.METRE)
+                .setParameter("semi-minor", 6378137, SI.METRE)
+                .addName("WGS 84 / Pseudo-Mercator")
+                .createProjectedCRS(HardCodedCRS.WGS84, HardCodedCS.PROJECTED);
+
+        assertWktEquals(Convention.WKT1,
+                "PROJCS[“WGS 84 / Pseudo-Mercator”,\n" +
+                "  GEOGCS[“WGS 84”,\n" +
+                "    DATUM[“World Geodetic System 1984”,\n" +
+                "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+                "      PRIMEM[“Greenwich”, 0.0],\n" +
+                "    UNIT[“degree”, 0.017453292519943295],\n" +
+                "    AXIS[“Longitude”, EAST],\n" +
+                "    AXIS[“Latitude”, NORTH]],\n" +
+                "  PROJECTION[“Mercator_1SP”, AUTHORITY[“EPSG”, “9804”]],\n"
+
+                "  PARAMETER[“semi_minor”, 6378137.0],\n" +     // Non-standard: appears
because its value is different than the ellipsoid value.
+                "  PARAMETER[“latitude_of_origin”, 0.0],\n" +
+                "  PARAMETER[“central_meridian”, 0.0],\n" +
+                "  PARAMETER[“scale_factor”, 1.0],\n" +
+                "  PARAMETER[“false_easting”, 0.0],\n" +
+                "  PARAMETER[“false_northing”, 0.0],\n" +
+                "  UNIT[“metre”, 1],\n" +
+                "  AXIS[“Easting”, EAST],\n" +
+                "  AXIS[“Northing”, NORTH]]",
+                crs);
+    }
+
+    /**
+     * Tests formatting of “Equidistant Cylindrical (Spherical)” projected CRS. This
one is a special case
+     * because it is simplified to an affine transform. The referencing module should be
able to find the
+     * original projection parameters.
+     *
+     * @throws FactoryException if the CRS creation failed.
+     */
+    @Test
+    @DependsOnMethod("testWKT2")
+    public void testWKT2_ForEquirectangular() throws FactoryException {
+        final ProjectedCRS crs = new GeodeticObjectBuilder()
+                .setConversionMethod("Equirectangular")
+                .setConversionName("Equidistant Cylindrical (Spherical)")
+                .setParameter("False easting",  1000, SI.METRE)
+                .setParameter("False northing", 2000, SI.METRE)
+                .addName("Equidistant Cylindrical (Spherical)")
+                .createProjectedCRS(HardCodedCRS.WGS84, HardCodedCS.PROJECTED);
+
+        assertWktEquals(Convention.WKT2_SIMPLIFIED,
+                "ProjectedCRS[“Equidistant Cylindrical (Spherical)”,\n" +
+                "  BaseGeodCRS[“WGS 84”,\n" +
+                "    Datum[“World Geodetic System 1984”,\n" +
+                "      Ellipsoid[“WGS84”, 6378137.0, 298.257223563]],\n" +
+                "    Unit[“degree”, 0.017453292519943295]],\n" +
+                "  Conversion[“Equidistant Cylindrical (Spherical)”,\n" +
+                "    Method[“Equidistant Cylindrical (Spherical)”],\n" +
+                "    Parameter[“Latitude of 1st standard parallel”, 0.0],\n" +
+                "    Parameter[“Longitude of natural origin”, 0.0],\n" +
+                "    Parameter[“False easting”, 1000.0, Unit[“metre”, 1]],\n" +
+                "    Parameter[“False northing”, 2000.0, Unit[“metre”, 1]]],\n" +
+                "  CS[“Cartesian”, 2],\n" +
+                "    Axis[“Easting (E)”, east],\n" +
+                "    Axis[“Northing (N)”, north],\n" +
+                "    Unit[“metre”, 1]]",
+                crs);
+    }
+
+    /**
      * Tests (un)marshalling of a projected coordinate reference system.
      *
      * @throws FactoryException if the CRS creation failed.



Mime
View raw message