sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1714032 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/provider/ main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/internal/referencing/provider/ test/java/o...
Date Thu, 12 Nov 2015 12:50:08 GMT
Author: desruisseaux
Date: Thu Nov 12 12:50:08 2015
New Revision: 1714032

URL: http://svn.apache.org/viewvc?rev=1714032&view=rev
Log:
GeocentricAffineBetweenGeographic now create the Geographic/Geocentric steps directly instead
than through
the MathTransformFactory, for efficiency and also for robustness since the GeocentricTranslation
and other
operations created here are designed for working with the SIS implementation of Geographic/Geocentric
conversions.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffineBetweenGeographic.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricToGeographic.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicToGeocentric.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/GeocentricTranslationTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffineBetweenGeographic.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffineBetweenGeographic.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffineBetweenGeographic.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricAffineBetweenGeographic.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -26,6 +26,7 @@ import org.opengis.parameter.InvalidPara
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
+import org.apache.sis.referencing.operation.transform.EllipsoidToCentricTransform;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.parameter.ParameterBuilder;
 import org.apache.sis.internal.util.Constants;
@@ -147,30 +148,26 @@ public abstract class GeocentricAffineBe
         final MathTransform affine = super.createMathTransform(factory, pv);
         /*
          * Create a "Geographic to Geocentric" conversion with ellipsoid axis length units
converted to metres
-         * (the unit implied by SRC_SEMI_MAJOR) because it is the unit of Bursa-Wolf param.
that we created above.
+         * (the unit implied by SRC_SEMI_MAJOR) because it is the unit of Bursa-Wolf parameters
that we created above.
          */
-        Parameters step = Parameters.castOrWrap(factory.getDefaultParameters(GeographicToGeocentric.NAME));
-        step.getOrCreate(MapProjection.SEMI_MAJOR).setValue(pv.doubleValue(SRC_SEMI_MAJOR));
-        step.getOrCreate(MapProjection.SEMI_MINOR).setValue(pv.doubleValue(SRC_SEMI_MINOR));
-        MathTransform toGeocentric = factory.createParameterizedTransform(step);
-        MathTransform reduce = null;
-        if (getSourceDimensions() == 2) try {
-            reduce = factory.createParameterizedTransform(factory.getDefaultParameters(Geographic3Dto2D.NAME));
-            toGeocentric = factory.createConcatenatedTransform(reduce.inverse(), toGeocentric);
-        } catch (NoninvertibleTransformException e) {
-            throw new FactoryException(e);
-        }
+        MathTransform toGeocentric = EllipsoidToCentricTransform.createGeodeticConversion(factory,
+                pv.doubleValue(SRC_SEMI_MAJOR),
+                pv.doubleValue(SRC_SEMI_MINOR),
+                SI.METRE, getSourceDimensions() >= 3,
+                EllipsoidToCentricTransform.TargetType.CARTESIAN);
         /*
          * Create a "Geocentric to Geographic" conversion with ellipsoid axis length units
converted to metres
          * because this is the unit of the Geocentric CRS used above.
          */
-        step = Parameters.castOrWrap(factory.getDefaultParameters(GeocentricToGeographic.NAME));
-        step.getOrCreate(MapProjection.SEMI_MAJOR).setValue(pv.doubleValue(TGT_SEMI_MAJOR));
-        step.getOrCreate(MapProjection.SEMI_MINOR).setValue(pv.doubleValue(TGT_SEMI_MINOR));
-        MathTransform toGeographic = factory.createParameterizedTransform(step);
-        if (getTargetDimensions() == 2) {
-            // 'reduce' should not be null since we provide only "2 to 2" or "3 to 3" dimensions.
-            toGeographic = factory.createConcatenatedTransform(toGeographic, reduce);
+        MathTransform toGeographic = EllipsoidToCentricTransform.createGeodeticConversion(factory,
+                pv.doubleValue(TGT_SEMI_MAJOR),
+                pv.doubleValue(TGT_SEMI_MINOR),
+                SI.METRE, getTargetDimensions() >= 3,
+                EllipsoidToCentricTransform.TargetType.CARTESIAN);
+        try {
+            toGeographic = toGeographic.inverse();
+        } catch (NoninvertibleTransformException e) {
+            throw new FactoryException(e);  // Should never happen with SIS implementation.
         }
         /*
          * The  Geocentric → Affine → Geographic  chain.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricToGeographic.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricToGeographic.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricToGeographic.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeocentricToGeographic.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -22,9 +22,7 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
-import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.util.FactoryException;
-import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.metadata.iso.citation.Citations;
 
 
@@ -32,10 +30,6 @@ import org.apache.sis.metadata.iso.citat
  * The provider for the <strong>inverse</strong> of "<cite>Geographic/geocentric
conversions</cite>" (EPSG:9602).
  * This provider creates transforms from geocentric to geographic coordinate reference systems.
  *
- * <p>By default, this provider creates a transform to a three-dimensional ellipsoidal
coordinate system,
- * which is the behavior implied in OGC's WKT. However a SIS-specific {@code "dim"} parameter
allows to
- * transform to a two-dimensional ellipsoidal coordinate system instead.</p>
- *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.7
  * @version 0.7
@@ -66,26 +60,10 @@ public final class GeocentricToGeographi
     }
 
     /**
-     * The provider for the other number of dimensions (2D or 3D).
-     */
-    private final GeocentricToGeographic redimensioned;
-
-    /**
      * Constructs a provider for the 3-dimensional case.
      */
     public GeocentricToGeographic() {
         super(3, 3, PARAMETERS);
-        redimensioned = new GeocentricToGeographic(this);
-    }
-
-    /**
-     * Constructs a provider for the 2-dimensional case.
-     *
-     * @param redimensioned The three-dimensional case.
-     */
-    private GeocentricToGeographic(final GeocentricToGeographic redimensioned) {
-        super(3, 2, PARAMETERS);
-        this.redimensioned = redimensioned;
     }
 
     /**
@@ -118,18 +96,4 @@ public final class GeocentricToGeographi
         }
         return tr;
     }
-
-    /**
-     * Returns the same operation method, but for different number of dimensions.
-     *
-     * @param  sourceDimensions The desired number of input dimensions.
-     * @param  targetDimensions The desired number of output dimensions.
-     * @return The redimensioned operation method, or {@code this} if no change is needed.
-     */
-    @Override
-    public OperationMethod redimension(final int sourceDimensions, final int targetDimensions)
{
-        ArgumentChecks.ensureBetween("sourceDimensions", 3, 3, sourceDimensions);
-        ArgumentChecks.ensureBetween("targetDimensions", 2, 3, targetDimensions);
-        return (targetDimensions == getTargetDimensions()) ? this : redimensioned;
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -52,14 +52,10 @@ public final class Geographic3Dto2D exte
     private static final long serialVersionUID = -9103595336196565505L;
 
     /**
-     * The EPSG name used for this operation method.
-     */
-    static final String NAME = "Geographic3D to 2D conversion";
-
-    /**
      * The group of all parameters expected by this coordinate operation (in this case, none).
      */
-    static final ParameterDescriptorGroup PARAMETERS = builder().addIdentifier("9659").addName(NAME).createGroup();
+    static final ParameterDescriptorGroup PARAMETERS = builder()
+            .addIdentifier("9659").addName("Geographic3D to 2D conversion").createGroup();
 
     /**
      * The unique instance, created when first needed.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicToGeocentric.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicToGeocentric.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicToGeocentric.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicToGeocentric.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -24,22 +24,16 @@ import org.opengis.parameter.ParameterDe
 import org.opengis.parameter.ParameterValue;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.apache.sis.referencing.operation.transform.EllipsoidToCentricTransform;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.util.Constants;
-import org.apache.sis.util.ArgumentChecks;
 
 
 /**
  * The provider for <cite>"Geographic/geocentric conversions"</cite> (EPSG:9602).
  * This provider creates transforms from geographic to geocentric coordinate reference systems.
  *
- * <p>By default, this provider creates a transform from a three-dimensional ellipsoidal
coordinate system,
- * which is the behavior implied in OGC's WKT. However a SIS-specific {@code "dim"} parameter
allows to transform
- * from a two-dimensional ellipsoidal coordinate system instead.</p>
- *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.7
  * @version 0.7
@@ -73,26 +67,10 @@ public final class GeographicToGeocentri
     }
 
     /**
-     * The provider for the other number of dimensions (2D or 3D).
-     */
-    private final GeographicToGeocentric redimensioned;
-
-    /**
      * Constructs a provider for the 3-dimensional case.
      */
     public GeographicToGeocentric() {
         super(3, 3, PARAMETERS);
-        redimensioned = new GeographicToGeocentric(this);
-    }
-
-    /**
-     * Constructs a provider for the 2-dimensional case.
-     *
-     * @param redimensioned The three-dimensional case.
-     */
-    private GeographicToGeocentric(final GeographicToGeocentric redimensioned) {
-        super(2, 3, PARAMETERS);
-        this.redimensioned = redimensioned;
     }
 
     /**
@@ -133,18 +111,4 @@ public final class GeographicToGeocentri
                 values.parameter(Constants.SEMI_MINOR).doubleValue(unit), unit, true,
                 EllipsoidToCentricTransform.TargetType.CARTESIAN);
     }
-
-    /**
-     * Returns the same operation method, but for different number of dimensions.
-     *
-     * @param  sourceDimensions The desired number of input dimensions.
-     * @param  targetDimensions The desired number of output dimensions.
-     * @return The redimensioned operation method, or {@code this} if no change is needed.
-     */
-    @Override
-    public OperationMethod redimension(final int sourceDimensions, final int targetDimensions)
{
-        ArgumentChecks.ensureBetween("sourceDimensions", 2, 3, sourceDimensions);
-        ArgumentChecks.ensureBetween("targetDimensions", 3, 3, targetDimensions);
-        return (sourceDimensions == getSourceDimensions()) ? this : redimensioned;
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -111,7 +111,7 @@ public class EllipsoidToCentricTransform
      * <p><b>TODO:</b> The spherical case is not yet implemented.
      * We could also consider supporting the cylindrical case, but its usefulness is not
obvious.</p>
      *
-     * @author  Martin Desruisseaux (IRD, Geomatys)
+     * @author  Martin Desruisseaux (Geomatys)
      * @since   0.7
      * @version 0.7
      * @module

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/GeocentricTranslationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/GeocentricTranslationTest.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/GeocentricTranslationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/GeocentricTranslationTest.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -19,11 +19,13 @@ package org.apache.sis.internal.referenc
 import org.opengis.util.FactoryException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.test.ToleranceModifier;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.parameter.Parameters;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.operation.transform.CoordinateDomain;
 import org.apache.sis.referencing.operation.transform.LinearTransform;
@@ -128,9 +130,7 @@ public final strictfp class GeocentricTr
      */
     private void create(final GeocentricAffine method) throws FactoryException {
         final ParameterValueGroup values = method.getParameters().createValue();
-        values.parameter("X-axis translation").setValue( 84.87);
-        values.parameter("Y-axis translation").setValue( 96.49);
-        values.parameter("Z-axis translation").setValue(116.95);
+        setTranslation(values);
         if (method instanceof GeocentricAffineBetweenGeographic) {
             setEllipsoids(values, CommonCRS.WGS84.ellipsoid(), CommonCRS.ED50.ellipsoid());
         }
@@ -138,6 +138,31 @@ public final strictfp class GeocentricTr
     }
 
     /**
+     * Creates a "Geographic 2D to 3D → Geocentric → Affine → Geographic → Geographic
3D to 2D" chain
+     * using EPSG or OGC standard operation methods and parameters. This is used for integration
tests.
+     *
+     * @param  factory The math transform factory to use for creating and concatenating the
transform.
+     * @return The chain of transforms.
+     * @throws FactoryException if an error occurred while creating a transform.
+     */
+    public static MathTransform createDatumShiftForGeographic2D(final MathTransformFactory
factory) throws FactoryException {
+        final Parameters values = Parameters.castOrWrap(factory.getDefaultParameters("Geocentric
translations (geog2D domain)"));
+        setTranslation(values);
+        setEllipsoids(values, CommonCRS.WGS84.ellipsoid(), CommonCRS.ED50.ellipsoid());
+        return Geographic3Dto2DTest.createDatumShiftForGeographic2D(factory,
+                new GeocentricTranslation().createMathTransform(factory, values), values);
+    }
+
+    /**
+     * Sets the translation parameters in the given parameter value group.
+     */
+    private static void setTranslation(final ParameterValueGroup values) {
+        values.parameter("X-axis translation").setValue( 84.87);
+        values.parameter("Y-axis translation").setValue( 96.49);
+        values.parameter("Z-axis translation").setValue(116.95);
+    }
+
+    /**
      * Sets the source and target ellipsoid axes in the given parameter value group.
      */
     static void setEllipsoids(final ParameterValueGroup values, final Ellipsoid source, final
Ellipsoid target) {
@@ -218,6 +243,13 @@ public final strictfp class GeocentricTr
     @DependsOnMethod("testWKT3D")
     public void testWKT2D() throws FactoryException {
         create(new GeocentricTranslation2D());
+        verifyWKT2D();
+    }
+
+    /**
+     * Verifies the WKT formatting of current transform.
+     */
+    private void verifyWKT2D() {
         assertWktEquals("CONCAT_MT[\n" +
                         "  INVERSE_MT[PARAM_MT[“Geographic3D to 2D conversion”]],\n"
+
                         "  PARAM_MT[“Ellipsoid_To_Geocentric”,\n" +
@@ -292,4 +324,18 @@ public final strictfp class GeocentricTr
                 "    Parameter[“elt_1_1”, 57.29577951308232],\n" +
                 "    Parameter[“elt_2_2”, 6378388.0]]]");
     }
+
+    /**
+     * Tests "Geographic 2D to 3D → Geocentric → Affine → Geographic → Geographic
3D to 2D" chain
+     * created from a {@link MathTransformFactory}. Because this test involves a lot of steps,
+     * this is more an integration test than a unit test: a failure here may not be easy
to debug.
+     *
+     * @throws FactoryException if an error occurred while creating the transform.
+     */
+    @Test
+    @DependsOnMethod("testWKT2D")
+    public void testIntegration() throws FactoryException {
+        transform = createDatumShiftForGeographic2D(DefaultFactories.forBuildin(MathTransformFactory.class));
+        verifyWKT2D();
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -19,9 +19,11 @@ package org.apache.sis.internal.referenc
 import org.opengis.util.FactoryException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.parameter.Parameters;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -66,4 +68,49 @@ public final strictfp class Geographic3D
                 0, 0, 0,
                 0, 0, 1}), ((LinearTransform) mt.inverse()).getMatrix(), STRICT);
     }
+
+    /**
+     * Creates a "Geographic 2D to 3D → Geocentric → Affine → Geographic → Geographic
3D to 2D" chain.
+     * This method is used for integration tests.
+     *
+     * @param  factory The math transform factory to use for creating and concatenating the
transform.
+     * @param  affine  The math transform for the operation in geocentric Cartesian domain.
+     * @param  pv      The parameters for the operation in geographic coordinates.
+     * @return The chain of transforms.
+     * @throws FactoryException if an error occurred while creating a transform.
+     *
+     * @see GeocentricTranslationTest#createDatumShiftForGeographic2D(MathTransformFactory)
+     */
+    static MathTransform createDatumShiftForGeographic2D(final MathTransformFactory factory,
+            final MathTransform affine, final Parameters pv) throws FactoryException
+    {
+        /*
+         * Create a "Geographic to Geocentric" conversion with ellipsoid axis length units
converted to metres
+         * (the unit implied by SRC_SEMI_MAJOR) because it is the unit of Bursa-Wolf parameters
that we created above.
+         */
+        Parameters step = Parameters.castOrWrap(factory.getDefaultParameters(GeographicToGeocentric.NAME));
+        step.getOrCreate(MapProjection.SEMI_MAJOR).setValue(pv.doubleValue(GeocentricAffineBetweenGeographic.SRC_SEMI_MAJOR));
+        step.getOrCreate(MapProjection.SEMI_MINOR).setValue(pv.doubleValue(GeocentricAffineBetweenGeographic.SRC_SEMI_MINOR));
+        MathTransform toGeocentric = factory.createParameterizedTransform(step);
+        final MathTransform reduce = factory.createParameterizedTransform(factory.getDefaultParameters("Geographic3D
to 2D conversion"));
+        try {
+            toGeocentric = factory.createConcatenatedTransform(reduce.inverse(), toGeocentric);
+        } catch (NoninvertibleTransformException e) {
+            throw new FactoryException(e);
+        }
+        /*
+         * Create a "Geocentric to Geographic" conversion with ellipsoid axis length units
converted to metres
+         * because this is the unit of the Geocentric CRS used above.
+         */
+        step = Parameters.castOrWrap(factory.getDefaultParameters(GeocentricToGeographic.NAME));
+        step.getOrCreate(MapProjection.SEMI_MAJOR).setValue(pv.doubleValue(GeocentricAffineBetweenGeographic.TGT_SEMI_MAJOR));
+        step.getOrCreate(MapProjection.SEMI_MINOR).setValue(pv.doubleValue(GeocentricAffineBetweenGeographic.TGT_SEMI_MINOR));
+        MathTransform toGeographic = factory.createParameterizedTransform(step);
+        toGeographic = factory.createConcatenatedTransform(toGeographic, reduce);
+        /*
+         * The  Geocentric → Affine → Geographic  chain.
+         */
+        return factory.createConcatenatedTransform(toGeocentric,
+               factory.createConcatenatedTransform(affine, toGeographic));
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java?rev=1714032&r1=1714031&r2=1714032&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
[UTF-8] Thu Nov 12 12:50:08 2015
@@ -16,10 +16,12 @@
  */
 package org.apache.sis.referencing.operation.transform;
 
+import java.util.Iterator;
 import javax.measure.unit.SI;
 import org.opengis.util.FactoryException;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.internal.system.DefaultFactories;
@@ -227,6 +229,46 @@ public final strictfp class EllipsoidToC
     }
 
     /**
+     * Tests {@link EllipsoidToCentricTransform#concatenate(MathTransform, boolean, MathTransformFactory)}.
+     * The test creates <cite>"Geographic 3D to 2D conversion"</cite>, <cite>"Geographic/Geocentric
conversions"</cite>
+     * and <cite>"Geocentric translation"</cite> transforms, then concatenate
them.
+     *
+     * <p>Because this test involves a lot of steps, this is more an integration test
than a unit test:
+     * a failure here may not be easy to debug.</p>
+     *
+     * @throws FactoryException if an error occurred while creating a transform.
+     *
+     * @see GeocentricTranslationTest#testWKT2D()
+     */
+    @Test
+    public void testConcatenate() throws FactoryException {
+        transform = GeocentricTranslationTest.createDatumShiftForGeographic2D(
+                DefaultFactories.forBuildin(MathTransformFactory.class));
+        final Iterator<MathTransform> it = MathTransforms.getSteps(transform).iterator();
+        MathTransform step;
+
+        assertInstanceOf("Degrees to radians", LinearTransform.class, step = it.next());
+        assertEquals("sourceDimensions", 2, step.getSourceDimensions());
+        assertEquals("tourceDimensions", 2, step.getTargetDimensions());
+
+        assertInstanceOf("Ellipsoid to geocentric", EllipsoidToCentricTransform.class, step
= it.next());
+        assertEquals("sourceDimensions", 2, step.getSourceDimensions());
+        assertEquals("tourceDimensions", 3, step.getTargetDimensions());
+
+        assertInstanceOf("Datum shift", LinearTransform.class, step = it.next());
+        assertEquals("sourceDimensions", 3, step.getSourceDimensions());
+        assertEquals("tourceDimensions", 3, step.getTargetDimensions());
+
+        assertInstanceOf("Geocentric to ellipsoid", AbstractMathTransform.Inverse.class,
step = it.next());
+        assertEquals("sourceDimensions", 3, step.getSourceDimensions());
+        assertEquals("tourceDimensions", 2, step.getTargetDimensions());
+
+        assertInstanceOf("Degrees to radians", LinearTransform.class, step = it.next());
+        assertEquals("sourceDimensions", 2, step.getSourceDimensions());
+        assertEquals("tourceDimensions", 2, step.getTargetDimensions());
+    }
+
+    /**
      * Tests the standard Well Known Text (version 1) formatting for three-dimensional transforms.
      * The result is what we show to users, but is quite different than what SIS has in memory.
      *



Mime
View raw message