sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1737702 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/cs/ main/java/org/apache/sis/referencing/factory/ main/java/org/apache/sis/referencing/operation/...
Date Mon, 04 Apr 2016 16:18:23 GMT
Author: desruisseaux
Date: Mon Apr  4 16:18:23 2016
New Revision: 1737702

URL: http://svn.apache.org/viewvc?rev=1737702&view=rev
Log:
First draft of a GeodeticCRS to VerticalCRS. Does not yet take geoidal height in account,
but the first block are in place with the definition of an interpolation CRS.

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/referencing/cs/CoordinateSystems.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedAxes.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedCS.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.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=1737702&r1=1737701&r2=1737702&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] Mon Apr  4 16:18:23 2016
@@ -18,9 +18,9 @@ package org.apache.sis.internal.referenc
 
 import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
 import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CartesianCS;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.cs.AxisFilter;
 import org.apache.sis.referencing.cs.CoordinateSystems;
@@ -40,10 +40,10 @@ import static org.opengis.referencing.Id
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.6
+ * @version 0.7
  * @module
  */
-public final class Legacy implements AxisFilter {
+public final class Legacy {
     /**
      * A three-dimensional Cartesian CS with the legacy set of geocentric axes.
      * OGC 01-009 defines the default geocentric axes as:
@@ -62,6 +62,12 @@ public final class Legacy implements Axi
             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.
@@ -108,40 +114,8 @@ public final class Legacy implements Axi
      */
     public static CartesianCS replaceUnit(CartesianCS cs, final Unit<?> unit) {
         if (unit != null && !unit.equals(SI.METRE)) {
-            cs = (CartesianCS) CoordinateSystems.replaceAxes(cs, new Legacy(unit));
+            cs = (CartesianCS) CoordinateSystems.replaceLinearUnit(cs, unit.asType(Length.class));
         }
         return cs;
     }
-
-
-
-
-    // -----------------------------------------------------------------
-    //         AxisFilter implementation for internal usage only
-    // -----------------------------------------------------------------
-
-    /**
-     * The value to be returned by {@link #getUnitReplacement(CoordinateSystemAxis, Unit)},
-     * or {@code null} if no replacement should be done.
-     */
-    private final Unit<?> replacement;
-
-    /**
-     * For internal usage by {@link #replaceUnit(CartesianCS, Unit)} only.
-     */
-    private Legacy(final Unit<?> unit) {
-        replacement = unit;
-    }
-
-    /**
-     * For internal usage by {@link #replaceUnit(CartesianCS, Unit)} only.
-     *
-     * @param  axis ignored.
-     * @param  unit ignored.
-     * @return The unit of the new coordinate system.
-     */
-    @Override
-    public Unit<?> getUnitReplacement(CoordinateSystemAxis axis, final Unit<?>
unit) {
-        return replacement;
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -18,11 +18,13 @@ package org.apache.sis.referencing.cs;
 
 import java.util.Arrays;
 import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
 import javax.measure.converter.UnitConverter;
 import javax.measure.converter.LinearConverter;
 import javax.measure.converter.ConversionException;
 import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.measure.Angle;
 import org.apache.sis.measure.ElevationAngle;
@@ -49,7 +51,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.6
+ * @version 0.7
  * @module
  */
 public final class CoordinateSystems extends Static {
@@ -306,8 +308,8 @@ public final class CoordinateSystems ext
          * not a matrix multiplication. The last column is processed in a special
          * way, since it contains the offset values.
          */
-        final int sourceDim = matrix.getNumCol() - 1;  // == sourceCS.getDimension()
-        final int targetDim = matrix.getNumRow() - 1;  // == targetCS.getDimension()
+        final int sourceDim = matrix.getNumCol() - 1;                       // == sourceCS.getDimension()
+        final int targetDim = matrix.getNumRow() - 1;                       // == targetCS.getDimension()
         for (int j=0; j<targetDim; j++) {
             final Unit<?> targetUnit = targetCS.getAxis(j).getUnit();
             for (int i=0; i<sourceDim; i++) {
@@ -405,4 +407,66 @@ public final class CoordinateSystems ext
         }
         return cs;
     }
+
+    /**
+     * Returns a coordinate system derived from the given one but with all linear units replaced
by the given unit.
+     * Non-linear units (e.g. angular or scale units) are left unchanged.
+     *
+     * <p>This convenience method is equivalent to the following code:</p>
+     * {@preformat java
+     *     return CoordinateSystems.replaceAxes(cs, new AxisFilter() {
+     *         &#64;Override public Unit<?> getUnitReplacement(CoordinateSystemAxis
axis, Unit<?> unit) {
+     *             return Units.isLinear(unit) ? newUnit : unit;
+     *         }
+     *     });
+     * }
+     *
+     * @param  cs       The coordinate system in which to replace linear units, or {@code
null}.
+     * @param  newUnit  The new linear unit.
+     * @return The modified coordinate system as a new instance,
+     *         or {@code cs} if all linear units were already equal to the given one.
+     *
+     * @see Units#isLinear(Unit)
+     *
+     * @since 0.7
+     */
+    public static CoordinateSystem replaceLinearUnit(final CoordinateSystem cs, final Unit<Length>
newUnit) {
+        ensureNonNull("newUnit", newUnit);
+        return CoordinateSystems.replaceAxes(cs, new AxisFilter() {
+            @Override public Unit<?> getUnitReplacement(CoordinateSystemAxis axis,
Unit<?> unit) {
+                return Units.isLinear(unit) ? newUnit : unit;
+            }
+        });
+    }
+
+    /**
+     * Returns a coordinate system derived from the given one but with all angular units
replaced by the given unit.
+     * Non-angular units (e.g. linear or scale units) are left unchanged.
+     *
+     * <p>This convenience method is equivalent to the following code:</p>
+     * {@preformat java
+     *     return CoordinateSystems.replaceAxes(cs, new AxisFilter() {
+     *         &#64;Override public Unit<?> getUnitReplacement(CoordinateSystemAxis
axis, Unit<?> unit) {
+     *             return Units.isAngular(unit) ? newUnit : unit;
+     *         }
+     *     });
+     * }
+     *
+     * @param  cs       The coordinate system in which to replace angular units, or {@code
null}.
+     * @param  newUnit  The new angular unit.
+     * @return The modified coordinate system as a new instance,
+     *         or {@code cs} if all angular units were already equal to the given one.
+     *
+     * @see Units#isAngular(Unit)
+     *
+     * @since 0.7
+     */
+    public static CoordinateSystem replaceAngularUnit(final CoordinateSystem cs, final Unit<javax.measure.quantity.Angle>
newUnit) {
+        ensureNonNull("newUnit", newUnit);
+        return CoordinateSystems.replaceAxes(cs, new AxisFilter() {
+            @Override public Unit<?> getUnitReplacement(CoordinateSystemAxis axis,
Unit<?> unit) {
+                return Units.isAngular(unit) ? newUnit : unit;
+            }
+        });
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import javax.measure.unit.SI;
 import javax.measure.unit.NonSI;
 import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
 import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.citation.Citation;
@@ -42,7 +43,6 @@ import org.opengis.referencing.crs.Singl
 import org.opengis.referencing.cs.CSFactory;
 import org.opengis.referencing.cs.CartesianCS;
 import org.opengis.referencing.cs.AxisDirection;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.datum.DatumFactory;
 import org.opengis.referencing.datum.EngineeringDatum;
 import org.apache.sis.internal.referencing.GeodeticObjectBuilder;
@@ -52,7 +52,6 @@ import org.apache.sis.internal.system.Lo
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.measure.Units;
 import org.apache.sis.referencing.CommonCRS;
-import org.apache.sis.referencing.cs.AxisFilter;
 import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ArraysExt;
@@ -627,19 +626,14 @@ public class CommonAuthorityFactory exte
              * At this point we got a coordinate system with axes in metres.
              * If the user asked for another unit of measurement, change the axes now.
              */
-            final Unit<?> unit;
+            final Unit<Length> unit;
             if (isLegacy) {
-                unit = createUnitFromEPSG(factor);
+                unit = createUnitFromEPSG(factor).asType(Length.class);
             } else {
                 unit = (factor != 1) ? Units.multiply(SI.METRE, factor) : SI.METRE;
             }
             if (!SI.METRE.equals(unit)) {
-                cs = (CartesianCS) CoordinateSystems.replaceAxes(cs, new AxisFilter() {
-                    @Override public Unit<?> getUnitReplacement(CoordinateSystemAxis
axis, Unit<?> ignored) {
-                        assert SI.METRE.equals(ignored) : ignored;
-                        return unit;
-                    }
-                });
+                cs = (CartesianCS) CoordinateSystems.replaceLinearUnit(cs, unit);
             }
             /*
              * Set the projection name, operation method and parameters. The parameters for
the Transverse Mercator

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationInference.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.HashMap;
 import java.util.Collections;
 import javax.measure.unit.Unit;
+import javax.measure.quantity.Length;
 import javax.measure.quantity.Duration;
 import javax.measure.converter.ConversionException;
 import org.opengis.util.FactoryException;
@@ -34,6 +35,8 @@ import org.opengis.metadata.extent.Geogr
 import org.opengis.metadata.quality.PositionalAccuracy;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
+import org.apache.sis.internal.metadata.AxisDirections;
+import org.apache.sis.internal.metadata.VerticalDatumTypes;
 import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.referencing.CoordinateOperations;
@@ -54,6 +57,8 @@ import org.apache.sis.referencing.Common
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.referencing.cs.CoordinateSystems;
+import org.apache.sis.referencing.crs.DefaultVerticalCRS;
+import org.apache.sis.referencing.crs.DefaultGeographicCRS;
 import org.apache.sis.referencing.datum.BursaWolfParameters;
 import org.apache.sis.referencing.datum.DefaultGeodeticDatum;
 import org.apache.sis.referencing.operation.matrix.Matrices;
@@ -287,7 +292,7 @@ public class CoordinateOperationInferenc
                 return createOperationStep(source, (GeodeticCRS) targetCRS);
             }
             if (targetCRS instanceof VerticalCRS) {
-//              return createOperationStep(source, (VerticalCRS) targetCRS);
+                return createOperationStep(source, (VerticalCRS) targetCRS);
             }
         }
         ////////////////////////////////////////////////////////////////////////////////
@@ -410,6 +415,7 @@ public class CoordinateOperationInferenc
      * @return a coordinate operation from {@code sourceCRS} to {@code targetCRS}.
      * @throws FactoryException if the operation can not be constructed.
      */
+    @SuppressWarnings("null")
     protected CoordinateOperation createOperationStep(final GeodeticCRS sourceCRS,
                                                       final GeodeticCRS targetCRS)
             throws FactoryException
@@ -544,6 +550,85 @@ public class CoordinateOperationInferenc
     }
 
     /**
+     * Creates an operation between a geodetic and a vertical coordinate reference systems.
+     * The height returned by this method will usually be part of a
+     * {@linkplain DefaultPassThroughOperation pass-through operation}.
+     *
+     * @param  sourceCRS  input coordinate reference system.
+     * @param  targetCRS  output coordinate reference system.
+     * @return a coordinate operation from {@code sourceCRS} to {@code targetCRS}.
+     * @throws FactoryException if the operation can not be constructed.
+     */
+    protected CoordinateOperation createOperationStep(final GeodeticCRS sourceCRS,
+                                                      final VerticalCRS targetCRS)
+            throws FactoryException
+    {
+        /*
+         * We will perform the conversion or transformation as a 3 steps process:
+         *
+         *     source CRS          →
+         *     interpolation CRS   →
+         *     ellipsoidal height  →
+         *     target height
+         */
+        CoordinateOperation step1 = null;
+        CoordinateOperation step2;
+        CoordinateOperation step3 = null;
+        /*
+         * Convert the source CRS to the CRS needed for transforming the heights.
+         * For now this step is fixed to a three-dimensional geographic CRS, but
+         * a future version should use a plugin-mechanism, with the code below
+         * as the last fallback.
+         */
+        CoordinateReferenceSystem interpolationCRS = sourceCRS;
+        CoordinateSystem interpolationCS = interpolationCRS.getCoordinateSystem();
+        if (!(interpolationCS instanceof EllipsoidalCS)) {
+            interpolationCRS = new DefaultGeographicCRS(
+                    Collections.singletonMap(GeographicCRS.NAME_KEY, sourceCRS.getName()),
+                    sourceCRS.getDatum(), CommonCRS.WGS84.geographic3D().getCoordinateSystem());
+
+            step1            = createOperation(sourceCRS, interpolationCRS);
+            interpolationCRS = step1.getTargetCRS();                                // May
have changed.
+            interpolationCS  = interpolationCRS.getCoordinateSystem();
+        }
+        /*
+         * Transform from ellipsoidal height to the height requested by the caller.
+         */
+        final int i = AxisDirections.indexOfColinear(interpolationCS, AxisDirection.UP);
+        if (i < 0) {
+            throw new OperationNotFoundException(notFoundMessage(sourceCRS, targetCRS));
+        }
+        VerticalCRS heightCRS = targetCRS;
+        VerticalCS  heightCS  = heightCRS.getCoordinateSystem();
+        final CoordinateSystemAxis interpAxis = interpolationCS.getAxis(i);
+        final Unit<?>              interpUnit = interpAxis.getUnit();
+        if (!Objects.equals(interpUnit, heightCS.getAxis(0).getUnit()) ||
+            !VerticalDatumTypes.ELLIPSOIDAL.equals(targetCRS.getDatum().getVerticalDatumType()))
+        {
+            heightCRS = CommonCRS.Vertical.ELLIPSOIDAL.crs();
+            heightCS  = heightCRS.getCoordinateSystem();
+            if (!Objects.equals(interpUnit, heightCS.getAxis(0).getUnit())) {
+                heightCRS = new DefaultVerticalCRS(
+                        Collections.singletonMap(VerticalCRS.NAME_KEY, heightCRS.getName()),
heightCRS.getDatum(),
+                        (VerticalCS) CoordinateSystems.replaceLinearUnit(heightCS, interpUnit.asType(Length.class)));
+            }
+            step3     = createOperation(heightCRS, targetCRS);
+            heightCRS = (VerticalCRS) step3.getSourceCRS();                         // May
have changed.
+            heightCS  = heightCRS.getCoordinateSystem();
+        }
+        /*
+         * Conversion from three-dimensional geographic CRS to ellipsoidal height.
+         */
+        final int srcDim = interpolationCS.getDimension();                          // Should
always be 3.
+        final int tgtDim = heightCS.getDimension();                                 // Should
always be 1.
+        final Matrix matrix = Matrices.createZero(tgtDim + 1, srcDim + 1);
+        matrix.setElement(0,      i,      1);                                       // Scale
factor for height.
+        matrix.setElement(tgtDim, srcDim, 1);                                       // Always
1 for affine transform.
+        step2 = createFromAffineTransform(AXIS_CHANGES, interpolationCRS, heightCRS, matrix);
+        return concatenate(step1, step2, step3);
+    }
+
+    /**
      * Creates an operation between two vertical coordinate reference systems.
      * The default implementation checks if both CRS use the same datum, then
      * adjusts for axis direction and units.
@@ -783,10 +868,10 @@ public class CoordinateOperationInferenc
                                             final CoordinateOperation step2)
             throws FactoryException
     {
+        if (isIdentity(step1)) return step2;
+        if (isIdentity(step2)) return step1;
         final MathTransform mt1 = step1.getMathTransform();
         final MathTransform mt2 = step2.getMathTransform();
-        if (step1 instanceof Conversion && mt1.isIdentity()) return step2;
-        if (step2 instanceof Conversion && mt2.isIdentity()) return step1;
         final CoordinateReferenceSystem sourceCRS = step1.getSourceCRS();
         final CoordinateReferenceSystem targetCRS = step2.getTargetCRS();
         /*
@@ -803,7 +888,8 @@ public class CoordinateOperationInferenc
             final MathTransform mt = factorySIS.getMathTransformFactory().createConcatenatedTransform(mt1,
mt2);
             main = createFromMathTransform(new HashMap<>(IdentifiedObjects.getProperties(main)),
                    sourceCRS, targetCRS, mt, op.getMethod(), op.getParameterValues(),
-                   (main instanceof Transformation) ? Transformation.class : SingleOperation.class);
+                   (main instanceof Transformation) ? Transformation.class :
+                   (main instanceof Conversion) ? Conversion.class : SingleOperation.class);
         } else {
             main = factory.createConcatenatedOperation(defaultName(sourceCRS, targetCRS),
step1, step2);
         }
@@ -858,7 +944,7 @@ public class CoordinateOperationInferenc
      * are usually datum shift and must be visible.
      */
     private static boolean isIdentity(final CoordinateOperation operation) {
-        return (operation instanceof Conversion) && operation.getMathTransform().isIdentity();
+        return (operation == null) || ((operation instanceof Conversion) && operation.getMathTransform().isIdentity());
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -193,6 +193,18 @@ public final strictfp class HardCodedCRS
             getProperties(HardCodedCS.ELLIPSOIDAL_HEIGHT), HardCodedDatum.ELLIPSOID, HardCodedCS.ELLIPSOIDAL_HEIGHT);
 
     /**
+     * A vertical coordinate reference system using ellipsoidal datum.
+     * Ellipsoidal heights are measured along the normal to the ellipsoid used in the definition
of horizontal datum.
+     *
+     * <p>This is not a valid vertical CRS according ISO 19111.
+     * This CRS is used by Apache SIS for internal calculation.</p>
+     *
+     * @since 0.7
+     */
+    public static final DefaultVerticalCRS ELLIPSOIDAL_HEIGHT_cm = new DefaultVerticalCRS(
+            getProperties(HardCodedCS.ELLIPSOIDAL_HEIGHT_cm), HardCodedDatum.ELLIPSOID, HardCodedCS.ELLIPSOIDAL_HEIGHT_cm);
+
+    /**
      * A vertical coordinate reference system using Mean Sea Level datum.
      */
     public static final DefaultVerticalCRS GRAVITY_RELATED_HEIGHT = new DefaultVerticalCRS(

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedAxes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedAxes.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedAxes.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedAxes.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -114,6 +114,16 @@ public final strictfp class HardCodedAxe
             AxisDirection.UP, SI.METRE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
null);
 
     /**
+     * Axis for height values above the ellipsoid in a
+     * {@linkplain org.apache.sis.referencing.crs.DefaultGeographicCRS geographic CRS}.
+     * Increasing ordinates values go {@linkplain AxisDirection#UP up} and units are {@linkplain
SI#CENTIMETRE centimetres}.
+     *
+     * @since 0.7
+     */
+    public static final DefaultCoordinateSystemAxis ELLIPSOIDAL_HEIGHT_cm = create(AxisNames.ELLIPSOIDAL_HEIGHT,
"h",
+            AxisDirection.UP, SI.CENTIMETRE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
null);
+
+    /**
      * Axis for height values measured from gravity.
      * Increasing ordinates values go {@linkplain AxisDirection#UP up} and units are {@linkplain
SI#METRE metres}.
      * The ISO 19111 name is <cite>"gravity-related height"</cite> and the abbreviation
is upper case <cite>"H"</cite>.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedCS.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedCS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/HardCodedCS.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -211,16 +211,26 @@ public final strictfp class HardCodedCS
 
     /**
      * A one-dimensional vertical CS with
-     * <var>{@linkplain HardCodedAxes#ELLIPSOIDAL_HEIGHT
-     * ellipsoidal height}</var> axis in metres.
+     * <var>{@linkplain HardCodedAxes#ELLIPSOIDAL_HEIGHT ellipsoidal height}</var>
+     * axis in metres.
      */
     public static final DefaultVerticalCS ELLIPSOIDAL_HEIGHT = new DefaultVerticalCS(
             getProperties(HardCodedAxes.ELLIPSOIDAL_HEIGHT), HardCodedAxes.ELLIPSOIDAL_HEIGHT);
 
     /**
      * A one-dimensional vertical CS with
-     * <var>{@linkplain HardCodedAxes#GRAVITY_RELATED_HEIGHT
-     * gravity-related height}</var> axis in metres.
+     * <var>{@linkplain HardCodedAxes#ELLIPSOIDAL_HEIGHT ellipsoidal height}</var>
+     * axis in centimetres.
+     *
+     * @since 0.7
+     */
+    public static final DefaultVerticalCS ELLIPSOIDAL_HEIGHT_cm = new DefaultVerticalCS(
+            getProperties(HardCodedAxes.ELLIPSOIDAL_HEIGHT_cm), HardCodedAxes.ELLIPSOIDAL_HEIGHT_cm);
+
+    /**
+     * A one-dimensional vertical CS with
+     * <var>{@linkplain HardCodedAxes#GRAVITY_RELATED_HEIGHT gravity-related height}</var>
+     * axis in metres.
      */
     public static final DefaultVerticalCS GRAVITY_RELATED_HEIGHT = new DefaultVerticalCS(
             getProperties(HardCodedAxes.GRAVITY_RELATED_HEIGHT), HardCodedAxes.GRAVITY_RELATED_HEIGHT);

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/CoordinateOperationInferenceTest.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -47,9 +47,11 @@ import static org.apache.sis.internal.re
 
 // Test dependencies
 import org.apache.sis.referencing.operation.transform.MathTransformTestCase;
+import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
+import org.opengis.test.Assert;
 import org.junit.BeforeClass;
 import org.junit.AfterClass;
 import org.junit.Test;
@@ -514,11 +516,11 @@ public final strictfp class CoordinateOp
         assertInstanceOf("transform", LinearTransform.class, transform);
         assertEquals(3, transform.getSourceDimensions());
         assertEquals(2, transform.getTargetDimensions());
-        assertTrue(Matrices.equals(Matrices.create(3, 4, new double[] {
+        Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[]
{
             1, 0, 0, 0,
             0, 1, 0, 0,
             0, 0, 0, 1
-        }), ((LinearTransform) transform).getMatrix(), STRICT, false));
+        }), ((LinearTransform) transform).getMatrix(), STRICT);
 
         isInverseTransformSupported = false;
         verifyTransform(new double[] {
@@ -540,7 +542,7 @@ public final strictfp class CoordinateOp
      */
     @Test
     @DependsOnMethod("testGeographic3D_to_2D")
-    public void testGeographic2D_to_3D() throws Exception {
+    public void testGeographic2D_to_3D() throws FactoryException, TransformException {
         final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic();
         final GeographicCRS targetCRS = CommonCRS.WGS84.geographic3D();
         final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
@@ -557,12 +559,12 @@ public final strictfp class CoordinateOp
         assertInstanceOf("transform", LinearTransform.class, transform);
         assertEquals(2, transform.getSourceDimensions());
         assertEquals(3, transform.getTargetDimensions());
-        assertTrue(Matrices.equals(Matrices.create(4, 3, new double[] {
+        Assert.assertMatrixEquals("transform.matrix", Matrices.create(4, 3, new double[]
{
             1, 0, 0,
             0, 1, 0,
             0, 0, 0,
             0, 0, 1
-        }), ((LinearTransform) transform).getMatrix(), STRICT, false));
+        }), ((LinearTransform) transform).getMatrix(), STRICT);
 
         verifyTransform(new double[] {
             30, 10,
@@ -575,6 +577,46 @@ public final strictfp class CoordinateOp
     }
 
     /**
+     * Tests transformation from a tree-dimensional geographic CRS to an ellipsoidal CRS.
+     * Such vertical CRS are illegal according ISO 19111, but they are the easiest test
+     * that we can perform for geographic → vertical transformation.
+     *
+     * @throws FactoryException if the operation can not be created.
+     * @throws TransformException if an error occurred while converting the test points.
+     */
+    @Test
+    public void testGeographic3D_to_EllipsoidalHeight() throws FactoryException, TransformException
{
+        final CoordinateReferenceSystem sourceCRS = CommonCRS.WGS84.geographic3D();
+        final CoordinateReferenceSystem targetCRS = HardCodedCRS.ELLIPSOIDAL_HEIGHT_cm;
+        final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
+        assertSame      ("sourceCRS", sourceCRS,        operation.getSourceCRS());
+        assertSame      ("targetCRS", targetCRS,        operation.getTargetCRS());
+        assertEquals    ("name",      "Axis changes",   operation.getName().getCode());
+        assertInstanceOf("operation", Conversion.class, operation);
+
+        transform = operation.getMathTransform();
+        assertInstanceOf("transform", LinearTransform.class, transform);
+        assertEquals(3, transform.getSourceDimensions());
+        assertEquals(1, transform.getTargetDimensions());
+        Assert.assertMatrixEquals("transform.matrix", Matrices.create(2, 4, new double[]
{
+            0, 0, 100, 0,
+            0, 0,   0, 1
+        }), ((LinearTransform) transform).getMatrix(), STRICT);
+
+        isInverseTransformSupported = false;
+        verifyTransform(new double[] {
+             0,  0,  0,
+             5,  8, 20,
+            -5, -8, 24
+        }, new double[] {
+                     0,
+                  2000,
+                  2400,
+        });
+        validate();
+    }
+
+    /**
      * Convenience method for creating a compound CRS.
      */
     private static CompoundCRS compound(final String name, final SingleCRS... components)
{
@@ -602,13 +644,13 @@ public final strictfp class CoordinateOp
         assertInstanceOf("transform", LinearTransform.class, transform);
         assertEquals(3, transform.getSourceDimensions());
         assertEquals(4, transform.getTargetDimensions());
-        assertTrue(Matrices.create(5, 4, new double[] {
+        Assert.assertMatrixEquals("transform.matrix", Matrices.create(5, 4, new double[]
{
             1, 0, 0, 0,
             0, 1, 0, 0,
             0, 0, 0, 0,
             0, 0, 1./(24*60*60), 40587,
             0, 0, 0, 1
-        }).equals(((LinearTransform) transform).getMatrix(), 1E-12));
+        }), ((LinearTransform) transform).getMatrix(), 1E-12);
         validate();
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java?rev=1737702&r1=1737701&r2=1737702&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
[UTF-8] Mon Apr  4 16:18:23 2016
@@ -17,19 +17,15 @@
 package org.apache.sis.referencing.operation.transform;
 
 import javax.measure.unit.SI;
-import javax.measure.unit.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.cs.SphericalCS;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.referencing.crs.DefaultGeocentricCRS;
 import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.cs.AxesConvention;
-import org.apache.sis.referencing.cs.AxisFilter;
 import org.apache.sis.referencing.CommonCRS;
-import org.apache.sis.measure.Units;
 
 // Test dependencies
 import org.opengis.test.referencing.TransformTestCase;
@@ -89,11 +85,7 @@ public final strictfp class CoordinateSy
      * Returns the given coordinate system but with linear axes in centimetres instead of
metres.
      */
     private static CoordinateSystem toCentimetres(final CoordinateSystem cs) {
-        return CoordinateSystems.replaceAxes(cs, new AxisFilter() {
-            @Override public Unit<?> getUnitReplacement(CoordinateSystemAxis axis,
Unit<?> unit) {
-                return Units.isLinear(unit) ? SI.CENTIMETRE : unit;
-            }
-        });
+        return CoordinateSystems.replaceLinearUnit(cs, SI.CENTIMETRE);
     }
 
     /**



Mime
View raw message