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/06/10 15:23:34 UTC
svn commit: r1684670 - in /sis/branches/JDK8/core/sis-referencing/src:
main/java/org/apache/sis/internal/referencing/
test/java/org/apache/sis/referencing/crs/
Author: desruisseaux
Date: Wed Jun 10 13:23:33 2015
New Revision: 1684670
URL: http://svn.apache.org/r1684670
Log:
WKT: conversion of geocentric coordinate system axes between ISO 19111 and legacy OGC 01-009 shall preserve linear units of measurement.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java?rev=1684670&r1=1684669&r2=1684670&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java [UTF-8] Wed Jun 10 13:23:33 2015
@@ -17,12 +17,14 @@
package org.apache.sis.internal.referencing;
import javax.measure.unit.SI;
+import javax.measure.unit.Unit;
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.cs.CartesianCS;
import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.referencing.cs.AxisFilter;
+import org.apache.sis.referencing.cs.CoordinateSystems;
import org.apache.sis.referencing.cs.DefaultCartesianCS;
import org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis;
-import org.apache.sis.util.Static;
import static java.util.Collections.singletonMap;
import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
@@ -32,12 +34,15 @@ import static org.opengis.referencing.Id
* Utilities related to version 1 of Well Known Text format.
* Defined in a separated classes for reducing classes loading when not necessary.
*
+ * <p>This class implements the {@link AxisFilter} interface for opportunistic reasons.
+ * Callers should ignore this implementation detail.</p>
+ *
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*/
-public final class Legacy extends Static {
+public final class Legacy implements AxisFilter {
/**
* A three-dimensional Cartesian CS with the legacy set of geocentric axes.
* OGC 01-009 defines the default geocentric axes as:
@@ -56,16 +61,13 @@ public final class Legacy extends Static
new DefaultCoordinateSystemAxis(singletonMap(NAME_KEY, "Z"), "Z", AxisDirection.NORTH, SI.METRE));
/**
- * Do not allow instantiation of this class.
- */
- private Legacy() {
- }
-
- /**
* The standard three-dimensional Cartesian CS as defined by ISO 19111.
+ *
+ * @param unit The linear unit of the desired coordinate system, or {@code null} for metres.
+ * @return The ISO 19111 coordinate system.
*/
- private static CartesianCS standard() {
- return (CartesianCS) CommonCRS.WGS84.geocentric().getCoordinateSystem();
+ public static CartesianCS standard(final Unit<?> unit) {
+ return replaceUnit((CartesianCS) CommonCRS.WGS84.geocentric().getCoordinateSystem(), unit);
}
/**
@@ -79,7 +81,7 @@ public final class Legacy extends Static
* or {@code cs} if the CS axes should be used as-is.
*/
public static CartesianCS forGeocentricCRS(final CartesianCS cs, final boolean toLegacy) {
- final CartesianCS check = toLegacy ? standard() : LEGACY;
+ final CartesianCS check = toLegacy ? standard(null) : LEGACY;
final int dimension = check.getDimension();
if (cs.getDimension() != dimension) {
return cs;
@@ -89,6 +91,47 @@ public final class Legacy extends Static
return cs;
}
}
- return toLegacy ? LEGACY : standard();
+ final Unit<?> unit = ReferencingUtilities.getUnit(cs);
+ return toLegacy ? replaceUnit(LEGACY, unit) : standard(unit);
+ }
+
+ /**
+ * Returns the coordinate system of a geocentric CRS using axes in the given unit of measurement.
+ * This method presume that the given {@code cs} uses {@link SI#METRE} (this is not verified).
+ *
+ * @param cs The coordinate system for which to perform the unit replacement.
+ * @param unit The unit of measurement for the geocentric CRS axes.
+ * @return The coordinate system for a geocentric CRS with axes using the given unit of measurement.
+ *
+ * @since 0.6
+ */
+ public static CartesianCS replaceUnit(CartesianCS cs, final Unit<?> unit) {
+ if (unit != null && !unit.equals(SI.METRE)) {
+ cs = (CartesianCS) CoordinateSystems.replaceAxes(cs, new Legacy(unit));
+ }
+ return cs;
+ }
+
+ /**
+ * For internal usage by {@link #replaceUnit(CartesianCS, Unit)} only.
+ */
+ private Legacy(final Unit<?> unit) {
+ this.unit = unit;
+ }
+
+ /**
+ * The value to be returned by {@link #getUnitReplacement(Unit)}.
+ */
+ private final Unit<?> unit;
+
+ /**
+ * For internal usage by {@link #replaceUnit(CartesianCS, Unit)} only.
+ *
+ * @param unit ignored.
+ * @return The unit of the new coordinate system.
+ */
+ @Override
+ public Unit<?> getUnitReplacement(final Unit<?> unit) {
+ return this.unit;
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java?rev=1684670&r1=1684669&r2=1684670&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java [UTF-8] Wed Jun 10 13:23:33 2015
@@ -20,7 +20,6 @@ import java.util.Map;
import java.util.Iterator;
import java.util.Collection;
import java.util.Collections;
-import javax.measure.unit.SI;
import javax.measure.unit.Unit;
import javax.measure.quantity.Length;
@@ -57,8 +56,6 @@ import org.apache.sis.referencing.Common
import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.referencing.AbstractIdentifiedObject;
import org.apache.sis.referencing.cs.AbstractCS;
-import org.apache.sis.referencing.cs.AxisFilter;
-import org.apache.sis.referencing.cs.CoordinateSystems;
import org.apache.sis.referencing.crs.DefaultDerivedCRS;
import org.apache.sis.referencing.crs.DefaultTemporalCRS;
import org.apache.sis.referencing.datum.BursaWolfParameters;
@@ -470,15 +467,7 @@ public final class ServicesForMetadata e
*/
@Override
public CartesianCS getGeocentricCS(final Unit<Length> linearUnit) {
- CartesianCS cs = (CartesianCS) CommonCRS.WGS84.geocentric().getCoordinateSystem();
- if (!SI.METRE.equals(linearUnit)) {
- cs = (CartesianCS) CoordinateSystems.replaceAxes(cs, new AxisFilter() {
- @Override public Unit<?> getUnitReplacement(final Unit<?> unit) {
- return linearUnit;
- }
- });
- }
- return cs;
+ return Legacy.standard(linearUnit);
}
/**
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=1684670&r1=1684669&r2=1684670&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 Jun 10 13:23:33 2015
@@ -16,7 +16,11 @@
*/
package org.apache.sis.referencing.crs;
+import javax.measure.unit.SI;
+import org.opengis.referencing.cs.CartesianCS;
import org.apache.sis.io.wkt.Convention;
+import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.internal.referencing.Legacy;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestCase;
@@ -30,7 +34,7 @@ import static org.apache.sis.test.Metada
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*/
@DependsOn({
@@ -57,6 +61,30 @@ public final strictfp class DefaultGeoce
}
/**
+ * Tests WKT 1 formatting using axes in kilometres. The intend of this test is to verify that
+ * the coordinate system replacement documented in {@link #testWKT1()} preserves the axis units.
+ *
+ * @since 0.6
+ */
+ @Test
+ @DependsOnMethod("testWKT1")
+ public void testWKT1_kilometres() {
+ DefaultGeocentricCRS crs = HardCodedCRS.GEOCENTRIC;
+ crs = new DefaultGeocentricCRS(IdentifiedObjects.getProperties(crs), crs.getDatum(),
+ Legacy.replaceUnit((CartesianCS) crs.getCoordinateSystem(), SI.KILOMETRE));
+ assertWktEquals(Convention.WKT1,
+ "GEOCCS[“Geocentric”,\n" +
+ " DATUM[“World Geodetic System 1984”,\n" +
+ " SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+ " PRIMEM[“Greenwich”, 0.0],\n" +
+ " UNIT[“km”, 1000],\n" +
+ " AXIS[“X”, OTHER],\n" +
+ " AXIS[“Y”, EAST],\n" +
+ " AXIS[“Z”, NORTH]]",
+ crs);
+ }
+
+ /**
* Tests WKT 2 formatting.
*
* <div class="section">Note on axis names</div>