sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1714015 - 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 10:53:16 GMT
Author: desruisseaux
Date: Thu Nov 12 10:53:16 2015
New Revision: 1714015

URL: http://svn.apache.org/viewvc?rev=1714015&view=rev
Log:
Add a TargetType enum in the EllipsoidToCentricTransform API in anticipation for the support
of the spherical case.
For now we support only the Cartesian case, but we make the API ready for addition of other
coordinate systems later.

Modified:
    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/ContextualParameters.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/referencing/operation/transform/EllipsoidToCentricTransformTest.java

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=1714015&r1=1714014&r2=1714015&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 10:53:16 2015
@@ -130,7 +130,8 @@ public final class GeographicToGeocentri
         final ParameterValue<?> semiMajor = values.parameter(Constants.SEMI_MAJOR);
         final Unit<Length> unit = semiMajor.getUnit().asType(Length.class);
         return EllipsoidToCentricTransform.createGeodeticConversion(factory, semiMajor.doubleValue(),
-                values.parameter(Constants.SEMI_MINOR).doubleValue(unit), unit, true);
+                values.parameter(Constants.SEMI_MINOR).doubleValue(unit), unit, true,
+                EllipsoidToCentricTransform.TargetType.CARTESIAN);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java?rev=1714015&r1=1714014&r2=1714015&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] Thu Nov 12 10:53:16 2015
@@ -511,7 +511,6 @@ public class ContextualParameters extend
      * @throws FactoryException if an error occurred while creating a math transform instance.
      *
      * @see org.apache.sis.referencing.operation.projection.NormalizedProjection#createMapProjection(MathTransformFactory)
-     * @see EllipsoidToCentricTransform#createGeodeticConversion(MathTransformFactory, double,
double, Unit, boolean)
      */
     @SuppressWarnings("AssignmentToForLoopParameter")
     public synchronized MathTransform completeTransform(final MathTransformFactory factory,
final MathTransform kernel)

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=1714015&r1=1714014&r2=1714015&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 10:53:16 2015
@@ -28,6 +28,7 @@ import org.opengis.util.FactoryException
 import org.opengis.geometry.DirectPosition;
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
@@ -74,11 +75,15 @@ import static org.apache.sis.internal.re
  * </ol>
  *
  * Output coordinates are as below:
- * <ol>
- *   <li>distance from Earth center on the X axis (toward the intersection of prime
meridian and equator),</li>
- *   <li>distance from Earth center on the Y axis (toward the intersection of 90°E
meridian and equator),</li>
- *   <li>distance from Earth center on the Z axis (toward North pole).</li>
- * </ol>
+ * <ul>
+ *   <li>In the Cartesian case:
+ *     <ol>
+ *       <li>distance from Earth center on the X axis (toward the intersection of prime
meridian and equator),</li>
+ *       <li>distance from Earth center on the Y axis (toward the intersection of 90°E
meridian and equator),</li>
+ *       <li>distance from Earth center on the Z axis (toward North pole).</li>
+ *     </ol>
+ *   </li>
+ * </ul>
  *
  * The units of measurements depend on how the {@code MathTransform} has been created:
  * <ul>
@@ -101,6 +106,26 @@ public class EllipsoidToCentricTransform
     private static final long serialVersionUID = -3352045463953828140L;
 
     /**
+     * Whether the output coordinate system is Cartesian or Spherical.
+     *
+     * <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)
+     * @since   0.7
+     * @version 0.7
+     * @module
+     */
+    public static enum TargetType {
+        /**
+         * Indicates conversions from
+         * {@linkplain org.apache.sis.referencing.cs.DefaultEllipsoidalCS ellipsoidal} to
+         * {@linkplain org.apache.sis.referencing.cs.DefaultCartesianCS Cartesian} coordinate
system.
+         */
+        CARTESIAN
+    }
+
+    /**
      * Internal parameter descriptor, used only for debugging purpose.
      * Created only when first needed.
      *
@@ -137,7 +162,7 @@ public class EllipsoidToCentricTransform
      * <var>b</var> is the <cite>semi-minor</cite> axis length.
      * Since the {@code EllipsoidToCentricTransform} class works on an ellipsoid where a
= 1
      * (because of the work performed by the normalization matrices), we just drop <var>a</var>
-     * in the formulas - so this field can be written as just <var>b</var>.
+     * in the formulas - so this field could be written as just <var>b</var>.
      *
      * <p>This value is related to {@link #eccentricitySquared} and to the ε value
used in EPSG guide
      * by (assuming a=1):</p>
@@ -150,7 +175,7 @@ public class EllipsoidToCentricTransform
      * It is not final only for the purpose of {@link #readObject(ObjectInputStream)}.
      * This field is recomputed from {@link #eccentricitySquared} on deserialization.</p>
      */
-    private transient double b;
+    private transient double axisRatio;
 
     /**
      * Whether calculation of φ should use an iterative method after the first φ approximation.
@@ -231,18 +256,20 @@ public class EllipsoidToCentricTransform
      * @param semiMajor  The semi-major axis length.
      * @param semiMinor  The semi-minor axis length.
      * @param unit       The unit of measurement for the semi-axes and the ellipsoidal height.
-     * @param withHeight {@code true} if geographic coordinates include an ellipsoidal height
(i.e. are 3-D),
-     *                   or {@code false} if they are only 2-D.
+     * @param withHeight {@code true} if source geographic coordinates include an ellipsoidal
height
+     *                   (i.e. are 3-D), or {@code false} if they are only 2-D.
+     * @param target     Whether the target coordinate shall be Cartesian or Spherical.
      *
-     * @see #createGeodeticConversion(MathTransformFactory, double, double, Unit, boolean)
+     * @see #createGeodeticConversion(MathTransformFactory, double, double, Unit, boolean,
TargetType)
      */
     protected EllipsoidToCentricTransform(final double semiMajor, final double semiMinor,
-            final Unit<Length> unit, final boolean withHeight)
+            final Unit<Length> unit, final boolean withHeight, final TargetType target)
     {
         ArgumentChecks.ensureStrictlyPositive("semiMajor", semiMajor);
         ArgumentChecks.ensureStrictlyPositive("semiMinor", semiMinor);
-        b = semiMinor / semiMajor;
-        eccentricitySquared = 1 - (b * b);
+        ArgumentChecks.ensureNonNull("target", target);
+        axisRatio = semiMinor / semiMajor;
+        eccentricitySquared = 1 - (axisRatio * axisRatio);
         useIterations = (eccentricitySquared >= ECCENTRICITY_THRESHOLD * ECCENTRICITY_THRESHOLD);
         this.withHeight = withHeight;
         /*
@@ -278,7 +305,7 @@ public class EllipsoidToCentricTransform
     private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
{
         in.defaultReadObject();
         useIterations = (eccentricitySquared >= ECCENTRICITY_THRESHOLD * ECCENTRICITY_THRESHOLD);
-        b = sqrt(1 - eccentricitySquared);
+        axisRatio = sqrt(1 - eccentricitySquared);
     }
 
     /**
@@ -304,16 +331,17 @@ public class EllipsoidToCentricTransform
      * @param semiMajor  The semi-major axis length.
      * @param semiMinor  The semi-minor axis length.
      * @param unit       The unit of measurement for the semi-axes and the ellipsoidal height.
-     * @param withHeight {@code true} if geographic coordinates include an ellipsoidal height
(i.e. are 3-D),
-     *                   or {@code false} if they are only 2-D.
+     * @param withHeight {@code true} if source geographic coordinates include an ellipsoidal
height
+     *                   (i.e. are 3-D), or {@code false} if they are only 2-D.
+     * @param target     Whether the target coordinate shall be Cartesian or Spherical.
      * @return The conversion from geographic to geocentric coordinates.
      * @throws FactoryException if an error occurred while creating a transform.
      */
     public static MathTransform createGeodeticConversion(final MathTransformFactory factory,
-            final double semiMajor, final double semiMinor, final Unit<Length> unit,
final boolean withHeight)
-            throws FactoryException
+            final double semiMajor, final double semiMinor, final Unit<Length> unit,
+            final boolean withHeight, final TargetType target) throws FactoryException
     {
-        EllipsoidToCentricTransform tr = new EllipsoidToCentricTransform(semiMajor, semiMinor,
unit, withHeight);
+        EllipsoidToCentricTransform tr = new EllipsoidToCentricTransform(semiMajor, semiMinor,
unit, withHeight, target);
         return tr.context.completeTransform(factory, tr);
     }
 
@@ -348,6 +376,7 @@ public class EllipsoidToCentricTransform
     public ParameterValueGroup getParameterValues() {
         final Parameters pg = Parameters.castOrWrap(getParameterDescriptors().createValue());
         pg.getOrCreate(ECCENTRICITY).setValue(sqrt(eccentricitySquared));
+        pg.parameter("target").setValue(getTargetType());
         pg.getOrCreate(DIMENSION).setValue(getSourceDimensions());
         return pg;
     }
@@ -363,8 +392,10 @@ public class EllipsoidToCentricTransform
     public ParameterDescriptorGroup getParameterDescriptors() {
         synchronized (EllipsoidToCentricTransform.class) {
             if (DESCRIPTOR == null) {
-                DESCRIPTOR = new ParameterBuilder().setCodeSpace(Citations.SIS, Constants.SIS)
-                        .addName("Ellipsoid to centric").createGroup(1, 1, DIMENSION, ECCENTRICITY);
+                final ParameterBuilder builder = new ParameterBuilder().setCodeSpace(Citations.SIS,
Constants.SIS);
+                final ParameterDescriptor<TargetType> target = builder.setRequired(true)
+                        .addName("target").create(TargetType.class, TargetType.CARTESIAN);
+                DESCRIPTOR = builder.addName("Ellipsoid to centric").createGroup(1, 1, ECCENTRICITY,
target, DIMENSION);
             }
             return DESCRIPTOR;
         }
@@ -391,6 +422,15 @@ public class EllipsoidToCentricTransform
     }
 
     /**
+     * Returns whether the target coordinate system is Cartesian or Spherical.
+     *
+     * @return Whether the target coordinate system is Cartesian or Spherical.
+     */
+    public final TargetType getTargetType() {
+        return TargetType.CARTESIAN;
+    }
+
+    /**
      * Computes the derivative at the given location.
      * This method relaxes a little bit the {@code MathTransform} contract by accepting two-
or three-dimensional
      * points even if the number of dimensions does not match the {@link #getSourceDimensions()}
value.
@@ -591,10 +631,10 @@ next:   while (--numPts >= 0) {
              *    cos²(q) = 1/(1 + tan²(q))         and  cos(q)  is always positive
              *    sin²(q) = 1 - cos²(q)             and  sin(q)  has the sign of tan(q).
              */
-            final double tanq  = Z / (p*b);
+            final double tanq  = Z / (p*axisRatio);
             final double cos2q = 1/(1 + tanq*tanq);
             final double sin2q = 1 - cos2q;
-            double φ = atan((Z + copySign(eccentricitySquared * sin2q*sqrt(sin2q), tanq)
/ b) /
+            double φ = atan((Z + copySign(eccentricitySquared * sin2q*sqrt(sin2q), tanq)
/ axisRatio) /
                             (p -          eccentricitySquared * cos2q*sqrt(cos2q)));
             /*
              * The above is an approximation of φ. Usually we are done with a good approximation
for
@@ -654,7 +694,7 @@ next:   while (--numPts >= 0) {
      */
     @Override
     protected int computeHashCode() {
-        return super.computeHashCode() + Numerics.hashCode(Double.doubleToLongBits(b));
+        return super.computeHashCode() + Numerics.hashCode(Double.doubleToLongBits(axisRatio));
     }
 
     /**
@@ -670,7 +710,7 @@ next:   while (--numPts >= 0) {
         }
         if (super.equals(object, mode)) {
             final EllipsoidToCentricTransform that = (EllipsoidToCentricTransform) object;
-            return (withHeight == that.withHeight) && Numerics.equals(b, that.b);
+            return (withHeight == that.withHeight) && Numerics.equals(axisRatio,
that.axisRatio);
         }
         return false;
     }
@@ -932,6 +972,6 @@ next:   while (--numPts >= 0) {
         final ParameterValue<Double> p = context.getOrCreate(SEMI_MAJOR);
         final Unit<Length> unit = p.getUnit().asType(Length.class);
         return new EllipsoidToCentricTransform(p.doubleValue(),
-                context.getOrCreate(SEMI_MINOR).doubleValue(unit), unit, false);
+                context.getOrCreate(SEMI_MINOR).doubleValue(unit), unit, false, getTargetType());
     }
 }

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=1714015&r1=1714014&r2=1714015&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 10:53:16 2015
@@ -270,6 +270,7 @@ public final strictfp class GeocentricTr
                 "    Parameter[“elt_2_2”, 1.567855942887398E-7]],\n" +
                 "  Param_MT[“Ellipsoid to centric”,\n" +
                 "    Parameter[“eccentricity”, 0.08181919084262157],\n" +
+                "    Parameter[“target”, “CARTESIAN”],\n" +
                 "    Parameter[“dim”, 3]],\n" +
                 "  Param_MT[“Affine”,\n" +
                 "    Parameter[“num_row”, 4],\n" +
@@ -282,6 +283,7 @@ public final strictfp class GeocentricTr
                 "    Parameter[“elt_2_3”, 1.8335353697517302E-5]],\n" +
                 "  Param_MT[“Centric to ellipsoid”,\n" +
                 "    Parameter[“eccentricity”, 0.08199188997902956],\n" +
+                "    Parameter[“target”, “CARTESIAN”],\n" +
                 "    Parameter[“dim”, 3]],\n" +
                 "  Param_MT[“Affine”,\n" +
                 "    Parameter[“num_row”, 4],\n" +

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=1714015&r1=1714014&r2=1714015&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 10:53:16 2015
@@ -61,7 +61,8 @@ public final strictfp class EllipsoidToC
                 DefaultFactories.forBuildin(MathTransformFactory.class),
                 ellipsoid.getSemiMajorAxis(),
                 ellipsoid.getSemiMinorAxis(),
-                ellipsoid.getAxisUnit(), is3D);
+                ellipsoid.getAxisUnit(), is3D,
+                EllipsoidToCentricTransform.TargetType.CARTESIAN);
     }
 
     /**
@@ -139,7 +140,7 @@ public final strictfp class EllipsoidToC
     public void testHighEccentricity() throws FactoryException, TransformException, FactoryException
{
         transform = EllipsoidToCentricTransform.createGeodeticConversion(
                 DefaultFactories.forBuildin(MathTransformFactory.class),
-                6000000, 4000000, SI.METRE, true);
+                6000000, 4000000, SI.METRE, true, EllipsoidToCentricTransform.TargetType.CARTESIAN);
 
         final double delta = toRadians(100.0 / 60) / 1852;
         derivativeDeltas  = new double[] {delta, delta, 100};
@@ -290,6 +291,7 @@ public final strictfp class EllipsoidToC
                 "    Parameter[“elt_2_2”, 1.567855942887398E-7]],\n" +
                 "  Param_MT[“Ellipsoid to centric”,\n" +
                 "    Parameter[“eccentricity”, 0.08181919084262157],\n" +
+                "    Parameter[“target”, “CARTESIAN”],\n" +
                 "    Parameter[“dim”, 3]],\n" +
                 "  Param_MT[“Affine”,\n" +
                 "    Parameter[“num_row”, 4],\n" +
@@ -309,6 +311,7 @@ public final strictfp class EllipsoidToC
                 "    Parameter[“elt_2_2”, 1.567855942887398E-7]],\n" +
                 "  Param_MT[“Centric to ellipsoid”,\n" +
                 "    Parameter[“eccentricity”, 0.08181919084262157],\n" +
+                "    Parameter[“target”, “CARTESIAN”],\n" +
                 "    Parameter[“dim”, 3]],\n" +
                 "  Param_MT[“Affine”,\n" +
                 "    Parameter[“num_row”, 4],\n" +



Mime
View raw message