Author: desruisseaux
Date: Wed Feb 19 15:07:07 2014
New Revision: 1569779
URL: http://svn.apache.org/r1569779
Log:
WKT 2 formatting of CompoundCRS.
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java?rev=1569779&r1=1569778&r2=1569779&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] Wed Feb 19 15:07:07 2014
@@ -145,6 +145,7 @@ public enum Convention {
* <ul>
* <li>Map projections are shown as SIS stores them internally, i.e.
with the separation between
* linear and non-linear steps, rather than as a single
operation.</li>
+ * <li>{@code CompoundCRS} shows nested compound CRS if any (the
structure is not flattened).</li>
* <li>{@code Id} elements are formatted for child elements in addition
to the root one.</li>
* <li>{@code Id} element omits the {@code URI} sub-element if the later
is derived by Apache SIS
* from the {@code Id} properties.</li>
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java?rev=1569779&r1=1569778&r2=1569779&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
[UTF-8] Wed Feb 19 15:07:07 2014
@@ -40,6 +40,7 @@ import org.apache.sis.util.resources.Err
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.Workaround;
import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.io.wkt.Convention;
import static org.apache.sis.util.ArgumentChecks.*;
import static org.apache.sis.util.Utilities.deepEquals;
@@ -382,19 +383,34 @@ public class DefaultCompoundCRS extends
}
/**
- * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a>
element.
+ * Formats this CRS as a <cite>Well Known Text</cite> {@code
CompoundCRS[…]} element.
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type, which is {@code "COMPD_CS"}.
+ * {@section WKT validity}
+ * The WKT version 2 format restricts compound CRS to the following
components in that order:
+ *
+ * <ul>
+ * <li>A mandatory horizontal CRS (only one of two-dimensional {@code
GeographicCRS}
+ * or {@code ProjectedCRS} or {@code EngineeringCRS}).</li>
+ * <li>Optionally followed by a {@code VerticalCRS} or a {@code
ParametricCRS} (but not both).</li>
+ * <li>Optionally followed by a {@code TemporalCRS}.</li>
+ * </ul>
+ *
+ * SIS does not check if this CRS is compliant with the above-cited
restrictions.
+ *
+ * @return {@code "CompoundCRS"} (WKT 2) or {@code "Compd_CS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
WKTUtilities.appendName(this, formatter, null);
- for (final CoordinateReferenceSystem element : components) {
+ final Convention convention = formatter.getConvention();
+ final boolean isWKT1 = convention.versionOfWKT() == 1;
+ for (final CoordinateReferenceSystem element :
+ (isWKT1 || convention == Convention.INTERNAL) ? components :
singles)
+ {
formatter.newLine();
formatter.append(element);
}
formatter.newLine(); // For writing the ID[…] element on its own line.
- return "Compd_CS";
+ return isWKT1 ? "Compd_CS" : "CompoundCRS";
}
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1569779&r1=1569778&r2=1569779&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] Wed Feb 19 15:07:07 2014
@@ -211,6 +211,35 @@ public class DefaultGeocentricCRS extend
/**
* Formats this CRS as a <cite>Well Known Text</cite> {@code
GeodeticCRS[…]} element.
*
+ * <blockquote><font size="-1"><b>Example:</b> Well-Known Text (version 2)
+ * of a geocentric coordinate reference system using the WGS 84 datum.
+ *
+ * {@preformat wkt
+ * GeodeticCRS["Geocentric",
+ * Datum["World Geodetic System 1984",
+ * Ellipsoid["WGS84", 6378137.0, 298.257223563, LengthUnit["metre",
1]]],
+ * PrimeMeridian["Greenwich", 0.0, AngleUnit["degree",
0.017453292519943295]],
+ * CS["Cartesian", 3],
+ * Axis["(X)", geocentricX],
+ * Axis["(Y)", geocentricY],
+ * Axis["(Z)", geocentricZ],
+ * LengthUnit["metre", 1]]
+ * }
+ *
+ * <p>Same coordinate reference system using WKT 1. Note that axis
directions are totally different.</p>
+ *
+ * {@preformat wkt
+ * GEOCCS["Geocentric",
+ * DATUM["World Geodetic System 1984",
+ * SPHEROID["WGS84", 6378137.0, 298.257223563]],
+ * PRIMEM["Greenwich", 0.0],
+ * UNIT["metre", 1],
+ * AXIS["X", OTHER],
+ * AXIS["Y", EAST],
+ * AXIS["Z", NORTH]]
+ * }
+ * </font></blockquote>
+ *
* @return {@code "GeodeticCRS"} (WKT 2) or {@code "GeocCS"} (WKT 1).
*/
@Override
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java?rev=1569779&r1=1569778&r2=1569779&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
[UTF-8] Wed Feb 19 15:07:07 2014
@@ -22,13 +22,15 @@ import org.opengis.referencing.cs.Coordi
import org.apache.sis.referencing.cs.DefaultCompoundCS;
import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.cs.HardCodedAxes;
+import org.apache.sis.io.wkt.Convention;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
import static java.util.Collections.singletonMap;
import static org.opengis.referencing.cs.CoordinateSystem.NAME_KEY;
-import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.MetadataAssert.*;
/**
@@ -41,7 +43,8 @@ import static org.apache.sis.test.Assert
*/
@DependsOn({
SubTypesTest.class,
- DefaultGeographicCRSTest.class
+ DefaultGeographicCRSTest.class,
+ DefaultVerticalCRSTest.class
})
public final strictfp class DefaultCompoundCRSTest extends TestCase {
/**
@@ -139,4 +142,60 @@ public final strictfp class DefaultCompo
assertSame("Expected a no-op.", shifted,
shifted.forConvention(AxesConvention.POSITIVE_RANGE));
assertSame("Expected cached instance.", shifted, crs4
.forConvention(AxesConvention.POSITIVE_RANGE));
}
+
+ /**
+ * Tests WKT 1 formatting.
+ */
+ @Test
+ public void testWKT1() {
+ assertWktEquals(Convention.WKT1,
+ "COMPD_CS[“WGS 84 + height + time”,\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" +
+ " VERT_CS[“Gravity-related height”,\n" +
+ " VERT_DATUM[“Mean Sea Level”, 2005],\n" +
+ " UNIT[“metre”, 1],\n" +
+ " AXIS[“Gravity-related height”, UP]],\n" +
+ " TIMECRS[“Time”,\n" +
+ " TIMEDATUM[“UNIX”],\n" +
+ " UNIT[“day”, 86400],\n" +
+ " AXIS[“Time”, FUTURE]]]",
+ HardCodedCRS.GEOID_4D);
+ }
+
+ /**
+ * Tests WKT 2 formatting.
+ */
+ @Test
+ @DependsOnMethod("testWKT1")
+ public void testWKT2() {
+ assertWktEquals(Convention.WKT2,
+ "CompoundCRS[“WGS 84 + height + time”,\n" +
+ " GeodeticCRS[“WGS 84”,\n" +
+ " Datum[“World Geodetic System 1984”,\n" +
+ " 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 (λ)”, east],\n" +
+ " Axis[“Latitude (φ)”, north],\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" +
+ " LengthUnit[“metre”, 1]],\n" +
+ " TimeCRS[“Time”,\n" +
+ " TimeDatum[“UNIX”],\n" +
+ " CS[“temporal”, 1],\n" +
+ " Axis[“Time (t)”, future],\n" +
+ " TimeUnit[“day”, 86400]],\n" +
+ " Area[“World”],\n" +
+ " BBox[-90.00, -180.00, 90.00, 180.00]]",
+ HardCodedCRS.GEOID_4D);
+ }
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java?rev=1569779&r1=1569778&r2=1569779&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
[UTF-8] Wed Feb 19 15:07:07 2014
@@ -147,7 +147,7 @@ public final strictfp class HardCodedCRS
* This constant uses the "geoid" term as an approximation for the gravity
related height.
*/
public static final DefaultCompoundCRS GEOID_4D = new DefaultCompoundCRS(
- properties("WGS 84 + height + time"), GRAVITY_RELATED_HEIGHT,
TIME);
+ properties("WGS 84 + height + time"), WGS84,
GRAVITY_RELATED_HEIGHT, TIME);
/**
* A two-dimensional Cartesian coordinate reference system with (column,
row) axes.
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java?rev=1569779&r1=1569778&r2=1569779&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
[UTF-8] Wed Feb 19 15:07:07 2014
@@ -63,8 +63,16 @@ public final strictfp class HardCodedCRS
*/
@Test
public void testDimensions() {
- assertEquals("WGS84 2D", 2, WGS84
.getCoordinateSystem().getDimension());
- assertEquals("WGS84 3D", 3,
WGS84_3D.getCoordinateSystem().getDimension());
+ assertEquals("TIME", 1, TIME
.getCoordinateSystem().getDimension());
+ assertEquals("DEPTH", 1, DEPTH
.getCoordinateSystem().getDimension());
+ assertEquals("WGS84", 2, WGS84
.getCoordinateSystem().getDimension());
+ assertEquals("WGS84_φλ", 2, WGS84_φλ
.getCoordinateSystem().getDimension());
+ assertEquals("WGS84_3D", 3, WGS84_3D
.getCoordinateSystem().getDimension());
+ assertEquals("CARTESIAN_2D", 2,
CARTESIAN_2D.getCoordinateSystem().getDimension());
+ assertEquals("CARTESIAN_3D", 3,
CARTESIAN_3D.getCoordinateSystem().getDimension());
+ assertEquals("GEOCENTRIC", 3, GEOCENTRIC
.getCoordinateSystem().getDimension());
+ assertEquals("SPHERICAL", 3, SPHERICAL
.getCoordinateSystem().getDimension());
+ assertEquals("GEOID_4D", 4, GEOID_4D
.getCoordinateSystem().getDimension());
}
/**
@@ -74,5 +82,6 @@ public final strictfp class HardCodedCRS
public void testSerialization() {
assertSerializedEquals(WGS84);
assertSerializedEquals(WGS84_3D);
+ assertSerializedEquals(GEOID_4D);
}
}