sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1702046 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/datum/AbstractDatum.java test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java test/java/org/apache/sis/io/wkt/WKTFormatTest.java
Date Wed, 09 Sep 2015 16:10:58 GMT
Author: desruisseaux
Date: Wed Sep  9 16:10:57 2015
New Revision: 1702046

URL: http://svn.apache.org/r1702046
Log:
Add WKT test for Transverse Mercator.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
    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/io/wkt/WKTFormatTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java?rev=1702046&r1=1702045&r2=1702046&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] Wed Sep  9 16:10:57 2015
@@ -26,6 +26,7 @@ import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.datum.Datum;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -34,6 +35,8 @@ import org.apache.sis.util.ComparisonMod
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.internal.metadata.MetadataUtilities;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.io.wkt.Formatter;
 
 import static org.apache.sis.util.Utilities.deepEquals;
 import static org.apache.sis.util.collection.Containers.property;
@@ -61,7 +64,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  *
  * @see org.apache.sis.referencing.cs.AbstractCS
@@ -411,6 +414,31 @@ public class AbstractDatum extends Abstr
         return super.computeHashCode() + Objects.hash(anchorDefinition, realizationEpoch,
domainOfValidity, scope);
     }
 
+    /**
+     * Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation
for this datum.
+     * See {@link AbstractIdentifiedObject#formatTo(Formatter)} for more information.
+     *
+     * @param  formatter The formatter where to format the inner content of this WKT element.
+     * @return The {@linkplain org.apache.sis.io.wkt.KeywordCase#CAMEL_CASE CamelCase} keyword
+     *         for the WKT element, or {@code null} if unknown.
+     */
+    @Override
+    protected String formatTo(final Formatter formatter) {
+        final Citation authority = formatter.getNameAuthority();
+        String name = IdentifiedObjects.getName(this, authority);
+        if (name == null) {
+            name = IdentifiedObjects.getName(this, null);
+            if (name == null) { // Should never happen, but be safe.
+                return super.formatTo(formatter);
+            }
+            if ("ESRI".equalsIgnoreCase(Citations.getCodeSpace(authority)) && !name.startsWith(ESRI_PREFIX))
{
+                name = ESRI_PREFIX + name;
+            }
+        }
+        formatter.append(name, ElementKind.DATUM);
+        return null;
+    }
+
 
 
 

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=1702046&r1=1702045&r2=1702046&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] Wed Sep  9 16:10:57 2015
@@ -513,6 +513,100 @@ public final strictfp class GeodeticObje
     }
 
     /**
+     * Tests the parsing of a projected CRS from a WKT 1 string with authority and Bursa-Wolf
parameters.
+     *
+     * @throws ParseException if the parsing failed.
+     */
+    @Test
+    @DependsOnMethod("testProjectedCRS")
+    public void testProjectedWithID() throws ParseException {
+        final ProjectedCRS crs = parse(ProjectedCRS.class,
+               "PROJCS[“OSGB 1936 / British National Grid”,\n" +
+               "  GEOGCS[“OSGB 1936”,\n" +
+               "    DATUM[“OSGB_1936”,\n" +
+               "      SPHEROID[“Airy 1830”, 6377563.396, 299.3249646, AUTHORITY[“EPSG”,
“7001”]],\n" +
+               "      TOWGS84[375.0, -111.0, 431.0, 0.0, 0.0, 0.0, 0.0],\n" +
+               "      AUTHORITY[“EPSG”, “6277”]],\n" +
+               "      PRIMEM[“Greenwich”,0.0, AUTHORITY[“EPSG”, “8901”]],\n"
+
+               "    UNIT[“DMSH”,0.0174532925199433],\n" +
+               "    AXIS[“Lat”,NORTH],AXIS[“Long”,EAST], AUTHORITY[“EPSG”, “4277”]],\n"
+
+               "  PROJECTION[“Transverse_Mercator”],\n" +
+               "  PARAMETER[“latitude_of_origin”, 49.0],\n" +
+               "  PARAMETER[“central_meridian”, -2.0],\n" +
+               "  PARAMETER[“scale_factor”, 0.999601272],\n" +
+               "  PARAMETER[“false_easting”, 400000.0],\n" +
+               "  PARAMETER[“false_northing”, -100000.0],\n" +
+               "  UNIT[“metre”, 1.0, AUTHORITY[“EPSG”, “9001”]],\n" +
+               "  AXIS[“E”,EAST],\n" +
+               "  AXIS[“N”,NORTH],\n" +
+               "  AUTHORITY[“EPSG”, “27700”]]");
+
+        assertNameAndIdentifierEqual("OSGB 1936 / British National Grid", 27700, crs);
+        assertNameAndIdentifierEqual("OSGB 1936", 4277, crs.getBaseCRS());
+        assertNameAndIdentifierEqual("OSGB_1936", 6277, crs.getDatum());
+        verifyProjectedCS(crs.getCoordinateSystem(), SI.METRE);
+
+        final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
+        assertEquals("Transverse Mercator", crs.getConversionFromBase().getMethod().getName().getCode());
+        assertEquals("semi_major",   6377563.396, param.parameter("semi_major"        ).doubleValue(),
1E-4);
+        assertEquals("semi_minor",   6356256.909, param.parameter("semi_minor"        ).doubleValue(),
1E-3);
+        assertEquals("latitude_of_origin",  49.0, param.parameter("latitude_of_origin").doubleValue(),
1E-8);
+        assertEquals("central_meridian",    -2.0, param.parameter("central_meridian"  ).doubleValue(),
1E-8);
+        assertEquals("scale_factor",      0.9996, param.parameter("scale_factor"      ).doubleValue(),
1E-5);
+        assertEquals("false_easting",   400000.0, param.parameter("false_easting"     ).doubleValue(),
1E-4);
+        assertEquals("false_northing", -100000.0, param.parameter("false_northing"    ).doubleValue(),
1E-4);
+
+        final BursaWolfParameters[] bwp = ((DefaultGeodeticDatum) crs.getDatum()).getBursaWolfParameters();
+        assertEquals("BursaWolfParameters", 1, bwp.length);
+        assertArrayEquals("BursaWolfParameters", new double[] {375, -111, 431}, bwp[0].getValues(),
STRICT);
+    }
+
+    /**
+     * Tests the parsing of a projected CRS with feet units.
+     *
+     * @throws ParseException if the parsing failed.
+     */
+    @Test
+    @DependsOnMethod("testProjectedCRS")
+    public void testProjectedWithFeetUnits() throws ParseException {
+        final ProjectedCRS crs = parse(ProjectedCRS.class,
+               "PROJCS[“TransverseMercator”,\n" +
+               "  GEOGCS[“Sphere”,\n" +
+               "    DATUM[“Sphere”,\n" +
+               "      SPHEROID[“Sphere”, 6370997.0, 0.0],\n" +
+               "      TOWGS84[0, 0, 0, 0, 0, 0, 0]],\n" +
+               "      PRIMEM[“Greenwich”, 0.0],\n" +
+               "    UNIT[“degree”, 0.017453292519943295],\n" +
+               "    AXIS[“Longitude”, EAST],\n" +
+               "    AXIS[“Latitude”, NORTH]],\n" +
+               "  PROJECTION[“Transverse_Mercator”,\n" +
+               "    AUTHORITY[“OGC”, “Transverse_Mercator”]],\n" +
+               "  PARAMETER[“central_meridian”, 170.0],\n" +
+               "  PARAMETER[“latitude_of_origin”, 50.0],\n" +
+               "  PARAMETER[“scale_factor”, 0.95],\n" +
+               "  PARAMETER[“false_easting”, 0.0],\n" +
+               "  PARAMETER[“false_northing”, 0.0],\n" +
+               "  UNIT[“feet”, 0.304800609601219],\n" +
+               "  AXIS[“E”, EAST],\n" +
+               "  AXIS[“N”, NORTH]]");
+
+        assertNameAndIdentifierEqual("TransverseMercator", 0, crs);
+        assertNameAndIdentifierEqual("Sphere", 0, crs.getBaseCRS());
+        assertNameAndIdentifierEqual("Sphere", 0, crs.getDatum());
+        verifyProjectedCS(crs.getCoordinateSystem(), NonSI.FOOT_SURVEY_US);
+
+        final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
+        assertEquals("Transverse Mercator", crs.getConversionFromBase().getMethod().getName().getCode());
+        assertEquals("semi_major",     6370997.0, param.parameter("semi_major"        ).doubleValue(),
1E-5);
+        assertEquals("semi_minor",     6370997.0, param.parameter("semi_minor"        ).doubleValue(),
1E-5);
+        assertEquals("latitude_of_origin",  50.0, param.parameter("latitude_of_origin").doubleValue(),
1E-8);
+        assertEquals("central_meridian",   170.0, param.parameter("central_meridian"  ).doubleValue(),
1E-8);
+        assertEquals("scale_factor",        0.95, param.parameter("scale_factor"      ).doubleValue(),
1E-8);
+        assertEquals("false_easting",        0.0, param.parameter("false_easting"     ).doubleValue(),
1E-8);
+        assertEquals("false_northing",       0.0, param.parameter("false_northing"    ).doubleValue(),
1E-8);
+    }
+
+    /**
      * Tests the parsing of a projected CRS using angular values in grades instead than degrees
      * and in lengths in kilometres instead than metres.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/WKTFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/WKTFormatTest.java?rev=1702046&r1=1702045&r2=1702046&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/WKTFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/WKTFormatTest.java
[UTF-8] Wed Sep  9 16:10:57 2015
@@ -20,6 +20,8 @@ import java.util.Collections;
 import java.text.ParseException;
 import javax.measure.unit.NonSI;
 import org.opengis.referencing.crs.VerticalCRS;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.referencing.crs.DefaultProjectedCRS;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
@@ -234,6 +236,143 @@ public final strictfp class WKTFormatTes
     }
 
     /**
+     * Tests the formatting using the name of different authorities.
+     * This test uses WKT 1 for parsing and formatting.
+     *
+     * @throws ParseException if the parsing failed.
+     */
+    @Test
+    public void testVariousConventions() throws ParseException {
+        final Symbols symbols = new Symbols(Symbols.SQUARE_BRACKETS);
+        symbols.setPairedQuotes("“”");
+        parser = format = new WKTFormat(null, null);
+        format.setSymbols(symbols);
+        final DefaultProjectedCRS crs = (DefaultProjectedCRS) parser.parseObject(
+            "PROJCS[“OSGB 1936 / British National Grid”,\n" +
+            "  GEOGCS[“OSGB 1936”,\n" +
+            "    DATUM[“OSGB_1936”,\n" +
+            "      SPHEROID[“Airy 1830”, 6377563.396, 299.3249646],\n" +
+            "      TOWGS84[375.0, -111.0, 431.0, 0.0, 0.0, 0.0, 0.0]],\n" +
+            "      PRIMEM[“Greenwich”,0.0],\n" +
+            "    UNIT[“DMSH”,0.0174532925199433],\n" +
+            "    AXIS[“Lat”,NORTH],AXIS[“Long”,EAST]],\n" +
+            "  PROJECTION[“Transverse_Mercator”],\n" +
+            "  PARAMETER[“latitude_of_origin”, 49.0],\n" +
+            "  PARAMETER[“central_meridian”, -2.0],\n" +
+            "  PARAMETER[“scale_factor”, 0.999601272],\n" +
+            "  PARAMETER[“false_easting”, 400000.0],\n" +
+            "  PARAMETER[“false_northing”, -100000.0],\n" +
+            "  UNIT[“metre”, 1],\n" +
+            "  AXIS[“E”,EAST],\n" +
+            "  AXIS[“N”,NORTH]]");
+        /*
+         * Formats using OGC identifiers. Use of OGC identifiers is implicit with Convention.WKT1,
unless we
+         * set explicitely another authority. The result should be the same than the above
string, except:
+         *
+         *   - The TOWGS84 parameters have been trimmed to 3 values.
+         *   - The AUTHORITY elements has been inferred for the PROJECTION element.
+         *   - "Latitude of origin" parameter is before "central meridian" parameter.
+         */
+        format.setConvention(Convention.WKT1);
+        assertMultilinesEquals(
+            "PROJCS[“OSGB 1936 / British National Grid”,\n" +
+            "  GEOGCS[“OSGB 1936”,\n" +
+            "    DATUM[“OSGB_1936”,\n" +
+            "      SPHEROID[“Airy 1830”, 6377563.396, 299.3249646],\n" +
+            "      TOWGS84[375.0, -111.0, 431.0]],\n" +                             // Trimmed
to 3 parameters.
+            "      PRIMEM[“Greenwich”, 0.0],\n" +
+            "    UNIT[“degree”, 0.017453292519943295],\n" +
+            "    AXIS[“Latitude”, NORTH],\n" +
+            "    AXIS[“Longitude”, EAST]],\n" +
+            "  PROJECTION[“Transverse_Mercator”, AUTHORITY[“EPSG”, “9807”]],\n"
+   // AUTHORITY code automatically found.
+            "  PARAMETER[“latitude_of_origin”, 49.0],\n" +                          //
Sorted before central meridian.
+            "  PARAMETER[“central_meridian”, -2.0],\n" +
+            "  PARAMETER[“scale_factor”, 0.999601272],\n" +
+            "  PARAMETER[“false_easting”, 400000.0],\n" +
+            "  PARAMETER[“false_northing”, -100000.0],\n" +
+            "  UNIT[“metre”, 1],\n" +
+            "  AXIS[“Easting”, EAST],\n" +
+            "  AXIS[“Northing”, NORTH]]",
+            format.format(crs));
+        /*
+         * Formats using GeoTiff identifiers. We should get different strings in PROJECTION[...]
+         * and PARAMETER[...] elements, but the other ones (especially DATUM[...]) are unchanged.
+         */
+        format.setNameAuthority(Citations.GEOTIFF);
+        assertMultilinesEquals(
+            "PROJCS[“OSGB 1936 / British National Grid”,\n" +
+            "  GEOGCS[“OSGB 1936”,\n" +
+            "    DATUM[“OSGB_1936”,\n" +
+            "      SPHEROID[“Airy 1830”, 6377563.396, 299.3249646],\n" +
+            "      TOWGS84[375.0, -111.0, 431.0]],\n" +
+            "      PRIMEM[“Greenwich”, 0.0],\n" +
+            "    UNIT[“degree”, 0.017453292519943295],\n" +
+            "    AXIS[“Latitude”, NORTH],\n" +
+            "    AXIS[“Longitude”, EAST]],\n" +
+            "  PROJECTION[“CT_TransverseMercator”, AUTHORITY[“GeoTIFF”, “1”]],\n"
+
+            "  PARAMETER[“NatOriginLat”, 49.0],\n" +
+            "  PARAMETER[“NatOriginLong”, -2.0],\n" +
+            "  PARAMETER[“ScaleAtNatOrigin”, 0.999601272],\n" +
+            "  PARAMETER[“FalseEasting”, 400000.0],\n" +
+            "  PARAMETER[“FalseNorthing”, -100000.0],\n" +
+            "  UNIT[“metre”, 1],\n" +
+            "  AXIS[“Easting”, EAST],\n" +
+            "  AXIS[“Northing”, NORTH]]",
+            format.format(crs));
+        /*
+         * Formats using ESRI identifiers. The most important change we are looking for is
+         * the name inside DATUM[...].
+         */
+        format.setNameAuthority(Citations.ESRI);
+        format.setConvention(Convention.WKT1_COMMON_UNITS);
+        assertMultilinesEquals(
+            "PROJCS[“OSGB 1936 / British National Grid”,\n" +
+            "  GEOGCS[“OSGB 1936”,\n" +
+            "    DATUM[“D_OSGB_1936”,\n" +
+            "      SPHEROID[“Airy 1830”, 6377563.396, 299.3249646],\n" +
+            "      TOWGS84[375.0, -111.0, 431.0]],\n" +
+            "      PRIMEM[“Greenwich”, 0.0],\n" +
+            "    UNIT[“degree”, 0.017453292519943295],\n" +
+            "    AXIS[“Latitude”, NORTH],\n" +
+            "    AXIS[“Longitude”, EAST]],\n" +
+            "  PROJECTION[“Transverse_Mercator”, AUTHORITY[“EPSG”, “9807”]],\n"
+
+            "  PARAMETER[“Latitude_Of_Origin”, 49.0],\n" +
+            "  PARAMETER[“Central_Meridian”, -2.0],\n" +
+            "  PARAMETER[“Scale_Factor”, 0.999601272],\n" +
+            "  PARAMETER[“False_Easting”, 400000.0],\n" +
+            "  PARAMETER[“False_Northing”, -100000.0],\n" +
+            "  UNIT[“meter”, 1],\n" +
+            "  AXIS[“Easting”, EAST],\n" +
+            "  AXIS[“Northing”, NORTH]]",
+            format.format(crs));
+        /*
+         * Formats using EPSG identifiers. We expect different names in
+         * DATUM[...], PROJECTION[...] and PARAMETER[...].
+         */
+        format.setNameAuthority(Citations.EPSG);
+        assertMultilinesEquals(
+            "PROJCS[“OSGB 1936 / British National Grid”,\n" +
+            "  GEOGCS[“OSGB 1936”,\n" +
+            "    DATUM[“OSGB_1936”,\n" +
+            "      SPHEROID[“Airy 1830”, 6377563.396, 299.3249646],\n" +
+            "      TOWGS84[375.0, -111.0, 431.0]],\n" +
+            "      PRIMEM[“Greenwich”, 0.0],\n" +
+            "    UNIT[“degree”, 0.017453292519943295],\n" +
+            "    AXIS[“Latitude”, NORTH],\n" +
+            "    AXIS[“Longitude”, EAST]],\n" +
+            "  PROJECTION[“Transverse Mercator”, AUTHORITY[“EPSG”, “9807”]],\n"
+
+            "  PARAMETER[“Latitude of natural origin”, 49.0],\n" +
+            "  PARAMETER[“Longitude of natural origin”, -2.0],\n" +
+            "  PARAMETER[“Scale factor at natural origin”, 0.999601272],\n" +
+            "  PARAMETER[“False easting”, 400000.0],\n" +
+            "  PARAMETER[“False northing”, -100000.0],\n" +
+            "  UNIT[“meter”, 1],\n" +
+            "  AXIS[“Easting”, EAST],\n" +
+            "  AXIS[“Northing”, NORTH]]",
+            format.format(crs));
+    }
+
+    /**
      * Tests the production of a warning messages when the WKT contains unformattable elements.
      *
      * @throws ParseException if the parsing (tested after formatting) failed.



Mime
View raw message