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/05/13 16:40:41 UTC
svn commit: r1679220 - in /sis/branches/JDK8/core/sis-referencing/src:
main/java/org/apache/sis/referencing/operation/
test/java/org/apache/sis/referencing/crs/
test/java/org/apache/sis/referencing/operation/
Author: desruisseaux
Date: Wed May 13 14:40:40 2015
New Revision: 1679220
URL: http://svn.apache.org/r1679220
Log:
Referencing: added tests for WKT formatting of DefaultDerivedCRS.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultDerivedCRSTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java?rev=1679220&r1=1679219&r2=1679220&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java [UTF-8] Wed May 13 14:40:40 2015
@@ -28,6 +28,7 @@ import org.opengis.referencing.operation
import org.opengis.referencing.operation.MathTransformFactory;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.crs.SingleCRS;
+import org.opengis.referencing.crs.GeneralDerivedCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.datum.Datum;
@@ -331,9 +332,24 @@ public class DefaultConversion extends A
{
if ((expected instanceof SingleCRS) && (actual instanceof SingleCRS)) {
final Datum datum = ((SingleCRS) expected).getDatum();
- if (datum != null && !Utilities.equalsIgnoreMetadata(datum, ((SingleCRS) actual).getDatum())) {
- throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleDatum_2, datum.getName(), param));
- }
+ if (datum != null) {
+ /*
+ * HACK: this method may be invoked indirectly by DefaultDerivedCRS and DefaultProjectedCRS constructors
+ * before their 'conversionFromBase' field is set. Since the Apache SIS implementations of those CRS map
+ * the datum to getConversionFromBase().getSourceCRS().getDatum(), invoking the actual.getDatum() method
+ * below result in a NullPointerException. To avoid this problem, we bypass this check if the given CRS
+ * is a derived CRS with a null conversion.
+ */
+ if (!(actual instanceof GeneralDerivedCRS) || ((GeneralDerivedCRS) actual).getConversionFromBase() != null) {
+ /*
+ * Now the real check.
+ */
+ if (!Utilities.equalsIgnoreMetadata(datum, ((SingleCRS) actual).getDatum())) {
+ throw new IllegalArgumentException(Errors.format(
+ Errors.Keys.IncompatibleDatum_2, datum.getName(), param));
+ }
+ }
+ }
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultDerivedCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultDerivedCRSTest.java?rev=1679220&r1=1679219&r2=1679220&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultDerivedCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultDerivedCRSTest.java [UTF-8] Wed May 13 14:40:40 2015
@@ -16,15 +16,24 @@
*/
package org.apache.sis.referencing.crs;
+import java.util.Collections;
import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.test.Validators;
+import org.apache.sis.io.wkt.Convention;
import org.apache.sis.internal.metadata.WKTKeywords;
+import org.apache.sis.referencing.operation.matrix.Matrix3;
+import org.apache.sis.referencing.operation.DefaultConversion;
+import org.apache.sis.referencing.operation.DefaultConversionTest;
+import org.apache.sis.referencing.operation.transform.MathTransforms;
import org.apache.sis.referencing.cs.HardCodedCS;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.apache.sis.test.MetadataAssert.*;
/**
@@ -36,7 +45,8 @@ import static org.junit.Assert.*;
* @module
*/
@DependsOn({
- DefaultProjectedCRSTest.class // Has many similarities with DerivedCRS, but is simpler.
+ DefaultProjectedCRSTest.class, // Has many similarities with DerivedCRS, but is simpler.
+ DefaultConversionTest.class
})
public final strictfp class DefaultDerivedCRSTest extends TestCase {
/**
@@ -77,4 +87,86 @@ public final strictfp class DefaultDeriv
assertEquals("Using illegal coordinate system type.", WKTKeywords.EngineeringCRS,
DefaultDerivedCRS.getType(HardCodedCRS.WGS84, HardCodedCS.GRAVITY_RELATED_HEIGHT));
}
+
+ /**
+ * Creates a dummy derived CRS defined by a longitude rotation from Paris to Greenwich prime meridian,
+ * and swapping the axis order. The result is equivalent to {@link HardCodedCRS#WGS84_φλ},
+ * which of course makes the returned {@code DerivedCRS} totally useless.
+ * Its purpose is only to perform easy tests.
+ */
+ private static DefaultDerivedCRS createLongitudeRotation() {
+ final DefaultConversion conversion = DefaultConversionTest.createLongitudeRotation();
+ return new DefaultDerivedCRS(Collections.singletonMap(DefaultDerivedCRS.NAME_KEY, "Back to WGS84"),
+ (SingleCRS) conversion.getSourceCRS(), conversion, HardCodedCS.GEODETIC_φλ);
+ }
+
+ /**
+ * Tests the construction of a {@link DefaultDerivedCRS}.
+ */
+ @Test
+ public void testConstruction() {
+ final DefaultDerivedCRS crs = createLongitudeRotation();
+ Validators.validate(crs);
+
+ assertEquals("name", "Back to WGS84", crs.getName().getCode());
+ assertEquals("baseCRS", "Paris", crs.getBaseCRS().getName().getCode());
+ assertEquals("datum", "Paris", crs.getDatum().getName().getCode());
+ assertSame ("coordinateSystem", HardCodedCS.GEODETIC_φλ, crs.getCoordinateSystem());
+
+ final Conversion conversion = crs.getConversionFromBase();
+ assertSame("sourceCRS", crs.getBaseCRS(), conversion.getSourceCRS());
+ assertSame("targetCRS", crs, conversion.getTargetCRS());
+ assertMatrixEquals("Longitude rotation", new Matrix3(
+ 0, 1, 0,
+ 1, 0, 2.33722917,
+ 0, 0, 1), MathTransforms.getMatrix(conversion.getMathTransform()), STRICT);
+ }
+
+ /**
+ * Tests the WKT 1 formatting.
+ * Note that in the particular case of {@code DerivedCRS}, WKT 1 and WKT 2 formats are very different.
+ */
+ @Test
+ @DependsOnMethod("testConstruction")
+ public void testWKT1() {
+ assertWktEquals(Convention.WKT1,
+ "FITTED_CS[“Back to WGS84”,\n" +
+ " PARAM_MT[“Affine”,\n" +
+ " PARAMETER[“elt_0_0”, 0.0],\n" +
+ " PARAMETER[“elt_0_1”, 1.0],\n" +
+ " PARAMETER[“elt_0_2”, -2.33722917],\n" +
+ " PARAMETER[“elt_1_0”, 1.0],\n" +
+ " PARAMETER[“elt_1_1”, 0.0]],\n" +
+ " GEOGCS[“Paris”,\n" +
+ " DATUM[“Paris”,\n" +
+ " SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+ " PRIMEM[“Paris”, 2.33722917],\n" +
+ " UNIT[“degree”, 0.017453292519943295],\n" +
+ " AXIS[“Longitude”, EAST],\n" +
+ " AXIS[“Latitude”, NORTH]]]",
+ createLongitudeRotation());
+ }
+
+ /**
+ * Tests the WKT 2 formatting.
+ * Note that in the particular case of {@code DerivedCRS}, WKT 1 and WKT 2 formats are very different.
+ */
+ @Test
+ @DependsOnMethod("testWKT1")
+ public void testWKT2() {
+ assertWktEquals(
+ "GeodeticCRS[“Back to WGS84”,\n" +
+ " BaseGeodCRS[“Paris”,\n" +
+ " Datum[“Paris”,\n" +
+ " Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”, 1]]],\n" +
+ " PrimeMeridian[“Paris”, 2.5969213, AngleUnit[“grade”, 0.015707963267948967]]],\n" +
+ " DerivingConversion[“Paris to Greenwich”,\n" +
+ " Method[“Longitude rotation”, Id[“EPSG”, 9601, Citation[“IOGP”]]],\n" +
+ " Parameter[“Longitude offset”, 2.33722917, Id[“EPSG”, 8602]]],\n" +
+ " CS[“ellipsoidal”, 2],\n" +
+ " Axis[“Latitude (B)”, north, Order[1]],\n" +
+ " Axis[“Longitude (L)”, east, Order[2]],\n" +
+ " AngleUnit[“degree”, 0.017453292519943295]]",
+ createLongitudeRotation());
+ }
}
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=1679220&r1=1679219&r2=1679220&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] Wed May 13 14:40:40 2015
@@ -45,7 +45,8 @@ import static org.apache.sis.test.Metada
* @module
*/
@DependsOn({
- DefaultGeographicCRSTest.class
+ DefaultGeographicCRSTest.class,
+ org.apache.sis.referencing.operation.DefaultConversionTest.class
})
public final strictfp class DefaultProjectedCRSTest extends XMLTestCase {
/**
@@ -80,7 +81,7 @@ public final strictfp class DefaultProje
@Test
public void testWKT1() throws FactoryException {
final ProjectedCRS crs = create();
- Validators.validate(crs);
+ Validators.validate(crs); // Opportunist check.
assertWktEquals(Convention.WKT1,
"PROJCS[“NTF (Paris) / Lambert zone II”,\n" +
" GEOGCS[“NTF (Paris)”,\n" +
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java?rev=1679220&r1=1679219&r2=1679220&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java [UTF-8] Wed May 13 14:40:40 2015
@@ -85,8 +85,11 @@ public final strictfp class DefaultConve
/**
* Creates a very simple conversion performing a longitude rotation between two-dimensional normalized CRS.
* The source CRS uses the Paris prime meridian and the target CRS uses the Greenwich prime meridian.
+ * Both CRS use the WGS84 datum.
+ *
+ * @return A simple conversion performing a longitude rotation on the WGS84 geodetic datum.
*/
- private static DefaultConversion createLongitudeRotation() {
+ public static DefaultConversion createLongitudeRotation() {
return createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_2D), HardCodedCRS.WGS84, null);
}
@@ -114,7 +117,7 @@ public final strictfp class DefaultConve
final int targetDim = targetCRS.getCoordinateSystem().getDimension();
final OperationMethod method = DefaultOperationMethodTest.create(
"Longitude rotation", "9601", "EPSG guidance note #7-2", sourceDim,
- DefaultParameterDescriptorTest.createEPSG("Longitude offset", (short) 9601));
+ DefaultParameterDescriptorTest.createEPSG("Longitude offset", (short) 8602));
final ParameterValueGroup pg = method.getParameters().createValue();
pg.parameter("Longitude offset").setValue(OFFSET);
final Matrix rotation = Matrices.createDiagonal(