Author: desruisseaux
Date: Thu Apr 21 13:44:05 2016
New Revision: 1740312
URL: http://svn.apache.org/viewvc?rev=1740312&view=rev
Log:
Fix a regression caused by previous commit: if operations to concatenate change
the number of dimensions, merge them in a single operation only if both of them
are the "Affine" operation.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java?rev=1740312&r1=1740311&r2=1740312&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
[UTF-8] Thu Apr 21 13:44:05 2016
@@ -923,7 +923,7 @@ public class CoordinateOperationFinder e
CoordinateOperation main = null;
final boolean isAxisChange1 = (step1.getName() == AXIS_CHANGES);
final boolean isAxisChange2 = (step2.getName() == AXIS_CHANGES);
- if (isAxisChange1 && isAxisChange2) {
+ if (isAxisChange1 && isAxisChange2 && isAffine(step1) &&
isAffine(step2)) {
main = step2; //
Arbitrarily take the last step.
} else {
if (isAxisChange1 && mt1.getSourceDimensions() ==
mt1.getTargetDimensions()) main = step2;
@@ -984,6 +984,18 @@ public class CoordinateOperationFinder e
}
/**
+ * Returns {@code true} if the given operation is non-null and use the
affine operation method.
+ */
+ private static boolean isAffine(final CoordinateOperation operation) {
+ if (operation instanceof SingleOperation) {
+ if (IdentifiedObjects.isHeuristicMatchForName(((SingleOperation)
operation).getMethod(), Constants.AFFINE)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Returns {@code true} if the specified operation is an identity
conversion.
* This method always returns {@code false} for transformations even if
their
* associated math transform is an identity one, because such
transformations
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java?rev=1740312&r1=1740311&r2=1740312&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java
[UTF-8] Thu Apr 21 13:44:05 2016
@@ -512,6 +512,44 @@ public final strictfp class CoordinateOp
//////////////////////////////////////////////////////////////////////////////////
/**
+ * Tests the conversion from a four-dimensional geographic CRS to a
two-dimensional geographic CRS.
+ * The vertical and temporal dimensions are simply dropped.
+ *
+ * @throws FactoryException if the operation can not be created.
+ * @throws TransformException if an error occurred while converting the
test points.
+ */
+ @Test
+ @DependsOnMethod("testGeographic3D_to_2D")
+ public void testGeographic4D_to_2D() throws FactoryException,
TransformException {
+ // NOTE: make sure that the 'sourceCRS' below is not equal to any
other 'sourceCRS' created in this class.
+ final CompoundCRS sourceCRS = compound("Test4D",
CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.UNIX.crs());
+ final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
+ final CoordinateOperation operation =
inference.createOperation(sourceCRS, targetCRS);
+ assertSame ("sourceCRS", sourceCRS,
operation.getSourceCRS());
+ assertSame ("targetCRS", targetCRS,
operation.getTargetCRS());
+
+ transform = operation.getMathTransform();
+ assertInstanceOf("transform", LinearTransform.class, transform);
+ assertEquals("sourceDimensions", 4, transform.getSourceDimensions());
+ assertEquals("targetDimensions", 2, transform.getTargetDimensions());
+ Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 5,
new double[] {
+ 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 1
+ }), ((LinearTransform) transform).getMatrix(), STRICT);
+
+ isInverseTransformSupported = false;
+ verifyTransform(new double[] {
+ 30, 10, 20, 1000,
+ 20, 30, -10, 3000
+ }, new double[] {
+ 30, 10,
+ 20, 30
+ });
+ validate();
+ }
+
+ /**
* Tests the conversion from a three-dimensional geographic CRS to a
two-dimensional geographic CRS.
* The vertical dimension is simply dropped.
*
@@ -647,6 +685,7 @@ public final strictfp class CoordinateOp
@Test
@DependsOnMethod("testGeographic3D_to_EllipsoidalHeight")
public void testGeographic4D_to_EllipsoidalHeight() throws
FactoryException, TransformException {
+ // NOTE: make sure that the 'sourceCRS' below is not equal to any
other 'sourceCRS' created in this class.
final CompoundCRS sourceCRS = compound("Test4D",
CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.JULIAN.crs());
final VerticalCRS targetCRS = CommonCRS.Vertical.ELLIPSOIDAL.crs();
final CoordinateOperation operation =
inference.createOperation(sourceCRS, targetCRS);
@@ -751,6 +790,7 @@ public final strictfp class CoordinateOp
@Test
@DependsOnMethod("testTemporalConversion")
public void testGeographic3D_to_4D() throws FactoryException,
TransformException {
+ // NOTE: make sure that the 'sourceCRS' below is not equal to any
other 'sourceCRS' created in this class.
final CompoundCRS sourceCRS = compound("Test3D",
CommonCRS.WGS84.geographic(), CommonCRS.Temporal.UNIX.crs());
final CompoundCRS targetCRS = compound("Test4D",
CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.MODIFIED_JULIAN.crs());
final CoordinateOperation operation =
inference.createOperation(sourceCRS, targetCRS);