sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1679180 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/geometry/ main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/ main/java/org/apache/sis/referencing/operation/ test/java/org...
Date Wed, 13 May 2015 11:29:53 GMT
Author: desruisseaux
Date: Wed May 13 11:29:53 2015
New Revision: 1679180

URL: http://svn.apache.org/r1679180
Log:
Referencing: test and debug the support of "InterpolationCRS" in DefaultConversion.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
    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/operation/AbstractSingleOperationTest.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/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1679180&r1=1679179&r2=1679180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] Wed May 13 11:29:53 2015
@@ -197,7 +197,7 @@ public abstract class AbstractEnvelope i
     static CoordinateSystemAxis getAxis(final CoordinateReferenceSystem crs, final int dimension)
{
         if (crs != null) {
             final CoordinateSystem cs = crs.getCoordinateSystem();
-            if (cs != null) {
+            if (cs != null) {   // Paranoiac check (should never be null).
                 return cs.getAxis(dimension);
             }
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1679180&r1=1679179&r2=1679180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] Wed May 13 11:29:53 2015
@@ -121,11 +121,13 @@ public final class ReferencingUtilities
         if (cs != null) {
             for (int i = cs.getDimension(); --i>=0;) {
                 final CoordinateSystemAxis axis = cs.getAxis(i);
-                final Unit<?> candidate = axis.getUnit();
-                if (Units.isAngular(candidate)) {
-                    unit = candidate.asType(Angle.class);
-                    if (AxisDirection.EAST.equals(AxisDirections.absolute(axis.getDirection())))
{
-                        break; // Found the longitude axis.
+                if (axis != null) {  // Paranoiac check.
+                    final Unit<?> candidate = axis.getUnit();
+                    if (Units.isAngular(candidate)) {
+                        unit = candidate.asType(Angle.class);
+                        if (AxisDirection.EAST.equals(AxisDirections.absolute(axis.getDirection())))
{
+                            break; // Found the longitude axis.
+                        }
                     }
                 }
             }
@@ -149,7 +151,7 @@ public final class ReferencingUtilities
         if (cs != null) {
             for (int i=cs.getDimension(); --i>=0;) {
                 final CoordinateSystemAxis axis = cs.getAxis(i);
-                if (axis != null) { // Paranoiac check.
+                if (axis != null) {  // Paranoiac check.
                     final Unit<?> candidate = axis.getUnit();
                     if (candidate != null) {
                         if (unit == null) {
@@ -165,6 +167,24 @@ public final class ReferencingUtilities
     }
 
     /**
+     * Returns the number of dimensions of the given CRS, or 0 if {@code null}.
+     *
+     * @param  crs The CRS from which to get the number of dimensions, or {@code null}.
+     * @return The number of dimensions, or 0 if the given CRS or its coordinate system is
null.
+     *
+     * @since 0.6
+     */
+    public static int getDimension(final CoordinateReferenceSystem crs) {
+        if (crs != null) {
+            final CoordinateSystem cs = crs.getCoordinateSystem();
+            if (cs != null) {  // Paranoiac check.
+                return cs.getDimension();
+            }
+        }
+        return 0;
+    }
+
+    /**
      * Copies all {@link SingleCRS} components from the given source to the given collection.
      * For each {@link CompoundCRS} element found in the iteration, this method replaces
the
      * {@code CompoundCRS} by its {@linkplain CompoundCRS#getComponents() components}, which

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1679180&r1=1679179&r2=1679180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] Wed May 13 11:29:53 2015
@@ -433,15 +433,14 @@ public final class CRS extends Static {
      *
      * <ul>
      *   <li>If the given {@code crs} is {@code null}, then this method returns {@code
null}.</li>
-     *   <li>Otherwise if {@code lower} is 0 and {@code upper} if the number of CRS
dimensions,
+     *   <li>Otherwise if {@code lower} is 0 and {@code upper} is the number of CRS
dimensions,
      *       then this method returns the given CRS unchanged.</li>
      *   <li>Otherwise if the given CRS is an instance of {@link CompoundCRS}, then
this method
      *       searches for a {@linkplain CompoundCRS#getComponents() component} where:
      *       <ul>
-     *         <li>The {@linkplain CoordinateSystem#getDimension() number of dimensions}
is
-     *             equals to {@code upper - lower};</li>
-     *         <li>The sum of the number of dimensions of all previous CRS is equals
to
-     *             {@code lower}.</li>
+     *         <li>The {@linkplain org.apache.sis.referencing.cs.AbstractCS#getDimension()
number of dimensions}
+     *             is equals to {@code upper - lower};</li>
+     *         <li>The sum of the number of dimensions of all previous CRS is equals
to {@code lower}.</li>
      *       </ul>
      *       If such component is found, then it is returned.</li>
      *   <li>Otherwise (i.e. no component match), this method returns {@code null}.</li>
@@ -462,28 +461,26 @@ public final class CRS extends Static {
      * @see org.apache.sis.geometry.GeneralEnvelope#subEnvelope(int, int)
      */
     public static CoordinateReferenceSystem getComponentAt(CoordinateReferenceSystem crs,
int lower, int upper) {
-        if (crs != null) {
-            int dimension = crs.getCoordinateSystem().getDimension();
-            ArgumentChecks.ensureValidIndexRange(dimension, lower, upper);
-check:      while (lower != 0 || upper != dimension) {
-                if (crs instanceof CompoundCRS) {
-                    final List<CoordinateReferenceSystem> components = ((CompoundCRS)
crs).getComponents();
-                    final int size = components.size();
-                    for (int i=0; i<size; i++) {
-                        crs = components.get(i);
-                        dimension = crs.getCoordinateSystem().getDimension();
-                        if (lower < dimension) {
-                            // The requested dimensions may intersect the dimension of this
CRS.
-                            // The outer loop will perform the verification, and eventually
go
-                            // down again in the tree of sub-components.
-                            continue check;
-                        }
-                        lower -= dimension;
-                        upper -= dimension;
+        int dimension = ReferencingUtilities.getDimension(crs);
+        ArgumentChecks.ensureValidIndexRange(dimension, lower, upper);
+check:  while (lower != 0 || upper != dimension) {
+            if (crs instanceof CompoundCRS) {
+                final List<CoordinateReferenceSystem> components = ((CompoundCRS) crs).getComponents();
+                final int size = components.size();
+                for (int i=0; i<size; i++) {
+                    crs = components.get(i);
+                    dimension = crs.getCoordinateSystem().getDimension();
+                    if (lower < dimension) {
+                        // The requested dimensions may intersect the dimension of this CRS.
+                        // The outer loop will perform the verification, and eventually go
+                        // down again in the tree of sub-components.
+                        continue check;
                     }
+                    lower -= dimension;
+                    upper -= dimension;
                 }
-                return null;
             }
+            return null;
         }
         return crs;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1679180&r1=1679179&r2=1679180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Wed May 13 11:29:53 2015
@@ -39,13 +39,13 @@ import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.Classes;
-import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.UnsupportedImplementationException;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.referencing.OperationMethods;
 import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.metadata.WKTKeywords;
@@ -322,18 +322,29 @@ public class AbstractCoordinateOperation
      */
     private void checkDimensions() {
         if (transform != null) {
-            int sourceDim = transform.getSourceDimensions();
-            int targetDim = transform.getTargetDimensions();
-            if (interpolationCRS != null) {
-                final int dim = interpolationCRS.getCoordinateSystem().getDimension();
-                sourceDim -= dim;
-                targetDim -= dim;
-                if (sourceDim <= 0 || targetDim <= 0) {
-                    throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingInterpolationOrdinates));
+            final int interpDim = ReferencingUtilities.getDimension(interpolationCRS);
+check:      for (int isTarget=0; ; isTarget++) {        // 0 == source check; 1 == target
check.
+                final CoordinateReferenceSystem crs;    // Will determine the expected dimensions.
+                int actual;                             // The MathTransform number of dimensions.
+                switch (isTarget) {
+                    case 0: crs = sourceCRS; actual = transform.getSourceDimensions(); break;
+                    case 1: crs = targetCRS; actual = transform.getTargetDimensions(); break;
+                    default: break check;
+                }
+                int expected = ReferencingUtilities.getDimension(crs);
+                if (interpDim != 0) {
+                    if (actual == expected || actual < interpDim) {
+                        // This check is not strictly necessary as the next check below would
catch the error,
+                        // but we provide here a hopefully more helpful error message for
a common mistake.
+                        throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingInterpolationOrdinates));
+                    }
+                    expected += interpDim;
+                }
+                if (crs != null && actual != expected) {
+                    throw new IllegalArgumentException(Errors.format(
+                            Errors.Keys.MismatchedTransformDimension_3, isTarget, expected,
actual));
                 }
             }
-            ArgumentChecks.ensureDimensionMatches("sourceCRS", sourceDim, sourceCRS);
-            ArgumentChecks.ensureDimensionMatches("targetCRS", targetDim, targetCRS);
         }
     }
 
@@ -450,7 +461,7 @@ public class AbstractCoordinateOperation
     /**
      * Returns the interpolation CRS of the given coordinate operation, or {@code null} if
none.
      */
-    private static CoordinateReferenceSystem getInterpolationCRS(final CoordinateOperation
operation) {
+    static CoordinateReferenceSystem getInterpolationCRS(final CoordinateOperation operation)
{
         return (operation instanceof AbstractCoordinateOperation)
                ? ((AbstractCoordinateOperation) operation).getInterpolationCRS() : null;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java?rev=1679180&r1=1679179&r2=1679180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] Wed May 13 11:29:53 2015
@@ -31,6 +31,7 @@ import org.apache.sis.parameter.Paramete
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.referencing.OperationMethods;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.util.collection.Containers;
@@ -100,7 +101,7 @@ class AbstractSingleOperation extends Ab
         super(properties, sourceCRS, targetCRS, interpolationCRS, transform);
         ArgumentChecks.ensureNonNull("method",    method);
         ArgumentChecks.ensureNonNull("transform", transform);
-        checkDimensions(method, transform, properties);
+        checkDimensions(method, ReferencingUtilities.getDimension(interpolationCRS), transform,
properties);
         this.method = method;
         /*
          * Undocumented property, because SIS usually infers the parameters from the MathTransform.
@@ -124,7 +125,7 @@ class AbstractSingleOperation extends Ab
         super(properties, null, null, null, transform);
         ArgumentChecks.ensureNonNull("method", method);
         if (transform != null) {
-            checkDimensions(method, transform, properties);
+            checkDimensions(method, 0, transform, properties);
         } else if (parameters == null) {
             throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedParameterValues));
         }
@@ -186,16 +187,17 @@ class AbstractSingleOperation extends Ab
      * </ul>
      *
      * @param  method     The operation method to compare to the math transform.
+     * @param  interpDim  The number of interpolation dimension, or 0 if none.
      * @param  transform  The math transform to compare to the operation method.
      * @param  properties Properties of the caller object being constructed, used only for
formatting error message.
      * @throws IllegalArgumentException if the number of dimensions are incompatible.
      */
-    static void checkDimensions(final OperationMethod method, MathTransform transform,
+    static void checkDimensions(final OperationMethod method, final int interpDim, MathTransform
transform,
             final Map<String,?> properties) throws IllegalArgumentException
     {
         int actual = transform.getSourceDimensions();
         Integer expected = method.getSourceDimensions();
-        if (expected != null && actual > expected) {
+        if (expected != null && actual > expected + interpDim) {
             /*
              * The given MathTransform uses more dimensions than the OperationMethod.
              * Try to locate one and only one sub-transform, ignoring axis swapping and scaling.
@@ -218,16 +220,17 @@ class AbstractSingleOperation extends Ab
         }
         /*
          * Now verify if the MathTransform dimensions are equal to the OperationMethod ones,
-         * ignoring null java.lang.Integer instances.
+         * ignoring null java.lang.Integer instances.  We do not specify whether the method
+         * dimensions should include the interpolation dimensions or not, so we accept both.
          */
-        byte isTarget = 0; // false: wrong dimension is the source one.
-        if (expected == null || actual == expected) {
+        int isTarget = 0;   // 0 == false: the wrong dimension is the source one.
+        if (expected == null || (actual == expected) || (actual == expected + interpDim))
{
             actual = transform.getTargetDimensions();
             expected = method.getTargetDimensions();
-            if (expected == null || actual == expected) {
+            if (expected == null || (actual == expected) || (actual == expected + interpDim))
{
                 return;
             }
-            isTarget = 1; // true: wrong dimension is the target one.
+            isTarget = 1;   // 1 == true: the wrong dimension is the target one.
         }
         /*
          * At least one dimension does not match.  In principle this is an error, but we
make an exception for the

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=1679180&r1=1679179&r2=1679180&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 11:29:53 2015
@@ -33,6 +33,8 @@ import org.opengis.referencing.cs.Coordi
 import org.opengis.referencing.datum.Datum;
 import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory;
+import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Workaround;
@@ -347,6 +349,7 @@ public class DefaultConversion extends A
             final CoordinateReferenceSystem targetCRS,
             final MathTransformFactory factory) throws FactoryException
     {
+        final int interpDim = ReferencingUtilities.getDimension(getInterpolationCRS(definition));
         MathTransform mt = definition.getMathTransform();
         if (mt == null) {
             /*
@@ -382,10 +385,14 @@ public class DefaultConversion extends A
                  * math transform may not be normalized), then we fallback on a simpler swapAndScaleAxes(…)
                  * method defined in this class. This is needed for AbstractCRS.forConvention(AxisConvention).
                  */
-                mt = swapAndScaleAxes(mt, sourceCRS, mtSource, true,  factory);
-                mt = swapAndScaleAxes(mt, mtTarget, targetCRS, false, factory);
+                mt = swapAndScaleAxes(mt, sourceCRS, mtSource, interpDim, true,  factory);
+                mt = swapAndScaleAxes(mt, mtTarget, targetCRS, interpDim, false, factory);
+                return mt;  // Skip createPassThroughTransform(…) since it was handled
by swapAndScaleAxes(…).
             }
         }
+        if (interpDim != 0) {
+            mt = factory.createPassThroughTransform(interpDim, mt, 0);
+        }
         return mt;
     }
 
@@ -398,18 +405,23 @@ public class DefaultConversion extends A
      * @param transform The transform to which to concatenate axis changes.
      * @param sourceCRS The first CRS of the pair for which to check for axes changes.
      * @param targetCRS The second CRS of the pair for which to check for axes changes.
+     * @param interpDim The number of dimensions of the interpolation CRS, or 0 if none.
      * @param isSource  {@code true} for pre-concatenating the changes, or {@code false}
for post-concatenating.
      * @param factory   The factory to use for performing axis changes.
      */
     private static MathTransform swapAndScaleAxes(MathTransform transform,
             final CoordinateReferenceSystem sourceCRS,
             final CoordinateReferenceSystem targetCRS,
-            final boolean isSource, final MathTransformFactory factory) throws FactoryException
+            final int interpDim, final boolean isSource,
+            final MathTransformFactory factory) throws FactoryException
     {
         if (sourceCRS != null && targetCRS != null && sourceCRS != targetCRS)
try {
-            final Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(),
-                                                                targetCRS.getCoordinateSystem());
+            Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(),
+                                                          targetCRS.getCoordinateSystem());
             if (!m.isIdentity()) {
+                if (interpDim != 0) {
+                    m = Matrices.createPassThrough(interpDim, m, 0);
+                }
                 final MathTransform s = factory.createAffineTransform(m);
                 transform = factory.createConcatenatedTransform(isSource ? s : transform,
                                                                 isSource ? transform : s);

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java?rev=1679180&r1=1679179&r2=1679180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java
[UTF-8] Wed May 13 11:29:53 2015
@@ -55,23 +55,24 @@ public final strictfp class AbstractSing
     }
 
     /**
-     * Tests {@link AbstractSingleOperation#checkDimensions(OperationMethod, MathTransform,
Map)}.
+     * Tests {@link AbstractSingleOperation#checkDimensions(OperationMethod, MathTransform,
Map)}
+     * without interpolation dimension.
      */
     @Test
     public void testCheckDimensions() {
         final Map<String,?> properties = Collections.singletonMap(DefaultOperationMethod.LOCALE_KEY,
Locale.ENGLISH);
         final MathTransform tr = MathTransformsTest.createConcatenateAndPassThrough();
-        AbstractSingleOperation.checkDimensions(createOperationMethod(3, 3), tr, properties);
-        AbstractSingleOperation.checkDimensions(createOperationMethod(1, 1), tr, properties);
+        AbstractSingleOperation.checkDimensions(createOperationMethod(3, 3), 0, tr, properties);
+        AbstractSingleOperation.checkDimensions(createOperationMethod(1, 1), 0, tr, properties);
         try {
-            AbstractSingleOperation.checkDimensions(createOperationMethod(2, 2), tr, properties);
+            AbstractSingleOperation.checkDimensions(createOperationMethod(2, 2), 0, tr, properties);
             fail("MathTransform.sourceDimension == 3 shall be considered incompatible.");
         } catch (IllegalArgumentException e) {
             // This is the expected exception.
             assertEquals(e.getMessage(), "The transform has 1 source dimension, while 2 was
expected.");
         }
         try {
-            AbstractSingleOperation.checkDimensions(createOperationMethod(3, 1), tr, properties);
+            AbstractSingleOperation.checkDimensions(createOperationMethod(3, 1), 0, tr, properties);
             fail("MathTransform.targetDimension == 3 shall be considered incompatible.");
         } catch (IllegalArgumentException e) {
             // This is the expected exception.

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=1679180&r1=1679179&r2=1679180&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 11:29:53 2015
@@ -23,12 +23,14 @@ import org.opengis.util.FactoryException
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.cs.EllipsoidalCS;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.OperationMethod;
 import org.apache.sis.internal.referencing.OperationMethods;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.datum.HardCodedDatum;
@@ -85,7 +87,7 @@ public final strictfp class DefaultConve
      * The source CRS uses the Paris prime meridian and the target CRS uses the Greenwich
prime meridian.
      */
     private static DefaultConversion createLongitudeRotation() {
-        return createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_2D), HardCodedCRS.WGS84);
+        return createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_2D), HardCodedCRS.WGS84,
null);
     }
 
     /**
@@ -95,8 +97,11 @@ public final strictfp class DefaultConve
      *
      * @param sourceCRS A CRS using the Paris prime meridian.
      * @param targetCRS A CRS using the Greenwich prime meridian.
+     * @param interpolationCRS A dummy interpolation CRS, or {@code null} if none.
      */
-    private static DefaultConversion createLongitudeRotation(final GeographicCRS sourceCRS,
final GeographicCRS targetCRS) {
+    private static DefaultConversion createLongitudeRotation(final GeographicCRS sourceCRS,
+            final GeographicCRS targetCRS, final TemporalCRS interpolationCRS)
+    {
         /*
          * The following code fills the parameter values AND creates itself the MathTransform
instance
          * (indirectly, through the matrix). The later step is normally not our business,
since we are
@@ -104,15 +109,18 @@ public final strictfp class DefaultConve
          * from the parameters. But we don't do the normal steps here because this class
is a unit test:
          * we want to test DefaultConversion in isolation of MathTransformFactory.
          */
-        final int srcDim = sourceCRS.getCoordinateSystem().getDimension();
-        final int tgtDim = targetCRS.getCoordinateSystem().getDimension();
+        final int interpDim = ReferencingUtilities.getDimension(interpolationCRS);
+        final int sourceDim = sourceCRS.getCoordinateSystem().getDimension();
+        final int targetDim = targetCRS.getCoordinateSystem().getDimension();
         final OperationMethod method = DefaultOperationMethodTest.create(
-                "Longitude rotation", "9601", "EPSG guidance note #7-2", srcDim,
+                "Longitude rotation", "9601", "EPSG guidance note #7-2", sourceDim,
                 DefaultParameterDescriptorTest.createEPSG("Longitude offset", (short) 9601));
         final ParameterValueGroup pg = method.getParameters().createValue();
         pg.parameter("Longitude offset").setValue(OFFSET);
-        final Matrix rotation = Matrices.createDiagonal(tgtDim + 1, srcDim + 1);
-        rotation.setElement(0, srcDim, OFFSET);
+        final Matrix rotation = Matrices.createDiagonal(
+                targetDim + interpDim + 1,      // Number of rows.
+                sourceDim + interpDim + 1);     // Number of columns.
+        rotation.setElement(interpDim, interpDim + sourceDim, OFFSET);
         /*
          * In theory we should not need to provide the parameters explicitly to the constructor
since
          * we are supposed to be able to find them from the MathTransform. But in this simple
test we
@@ -122,7 +130,8 @@ public final strictfp class DefaultConve
         final Map<String, Object> properties = new HashMap<>(4);
         properties.put(DefaultTransformation.NAME_KEY, "Paris to Greenwich");
         properties.put(OperationMethods.PARAMETERS_KEY, pg);
-        return new DefaultConversion(properties, sourceCRS, targetCRS, null, method, MathTransforms.linear(rotation));
+        return new DefaultConversion(properties, sourceCRS, targetCRS, interpolationCRS,
+                method, MathTransforms.linear(rotation));
     }
 
     /**
@@ -163,6 +172,10 @@ public final strictfp class DefaultConve
 
     /**
      * Creates a defining conversion and tests {@link DefaultConversion#specialize DefaultConversion.specialize(…)}.
+     * This test includes a swapping of axis order in the <em>source</em> CRS.
+     *
+     * <div class="note"><b>Note:</b>
+     * By contrast, {@link #testSpecialize()} will test swapping axis order in the <em>target</em>
CRS.</div>
      *
      * @throws FactoryException Should not happen in this test.
      */
@@ -198,6 +211,10 @@ public final strictfp class DefaultConve
 
     /**
      * Tests {@link DefaultConversion#specialize DefaultConversion.specialize(…)} with
new source and target CRS.
+     * This test attempts to swap axis order and change the number of dimensions of the <em>target</em>
CRS.
+     *
+     * <div class="note"><b>Note:</b>
+     * By contrast, {@link #testDefiningConversion()} tested swapping axis order in the <em>source</em>
CRS.</div>
      *
      * @throws FactoryException Should not happen in this test.
      */
@@ -205,7 +222,7 @@ public final strictfp class DefaultConve
     @DependsOnMethod("testDefiningConversion")
     public void testSpecialize() throws FactoryException {
         final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
-        DefaultConversion op = createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_3D),
HardCodedCRS.WGS84_3D);
+        DefaultConversion op = createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_3D),
HardCodedCRS.WGS84_3D, null);
         assertMatrixEquals("Longitude rotation of a three-dimensional CRS", new Matrix4(
                 1, 0, 0, OFFSET,
                 0, 1, 0, 0,
@@ -226,6 +243,45 @@ public final strictfp class DefaultConve
                 0, 0, 0, 1}), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
     }
 
+
+    /**
+     * Tests {@link DefaultConversion#specialize DefaultConversion.specialize(…)} with
an interpolation CRS.
+     * In this test, we invent an imaginary scenario where the longitude rotation to apply
varies with time
+     * (a "moving prime meridian").
+     *
+     * <div class="note"><b>Note:</b>
+     * from some point of view, this scenario is not as weird as it may look like. The Greenwich
prime meridian
+     * was initially the meridian passing through the telescope of the Greenwich observatory.
But when a new
+     * more powerful telescopes was built, is was installed a few metres far from the old
one. So if we were
+     * staying to a strict interpretation like "the meridian passing through the main telescope",
+     * that meridian would indeed more with time.</div>
+     *
+     * @throws FactoryException Should not happen in this test.
+     */
+    @Test
+    @DependsOnMethod("testDefiningConversion")
+    public void testWithInterpolationCRS() throws FactoryException {
+        DefaultConversion op = createLongitudeRotation(
+                createParisCRS(HardCodedCS.GEODETIC_2D), HardCodedCRS.WGS84, HardCodedCRS.TIME);
+        assertMatrixEquals("Longitude rotation of a time-varying CRS", new Matrix4(
+                1, 0, 0, 0,
+                0, 1, 0, OFFSET,
+                0, 0, 1, 0,
+                0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
+
+        op = op.specialize(
+                DefaultConversion.class,    // In normal use, this would be 'Conversion.class'.
+                op.getSourceCRS(),          // Keep the same source CRS.
+                HardCodedCRS.WGS84_φλ,      // Swap axis order.
+                DefaultFactories.forBuildin(MathTransformFactory.class));
+
+        assertMatrixEquals("Longitude rotation of a time-varying CRS", new Matrix4(
+                1, 0, 0, 0,
+                0, 0, 1, 0,
+                0, 1, 0, OFFSET,
+                0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
+    }
+
     /**
      * Ensures that {@link DefaultConversion#specialize DefaultConversion.specialize(…)}
verifies the datum.
      *



Mime
View raw message