sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1684132 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/ main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/io/wkt/
Date Mon, 08 Jun 2015 09:58:37 GMT
Author: desruisseaux
Date: Mon Jun  8 09:58:37 2015
New Revision: 1684132

URL: http://svn.apache.org/r1684132
Log:
Referencing: DefaultConversion.getParameterValues() should contains the semi-major and semi-minor
axis lengths.

Modified:
    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/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java

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=1684132&r1=1684131&r2=1684132&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] Mon Jun  8 09:58:37 2015
@@ -140,15 +140,23 @@ class AbstractSingleOperation extends Ab
      *
      * <p>This constructor is for {@link DefaultConversion} usage only,
      * in order to create a "real" conversion from a defining conversion.</p>
+     *
+     * @param definition The defining conversion.
+     * @param sourceCRS  The source CRS.
+     * @param targetCRS  The target CRS.
+     * @param transform  The math transform, optionally with the parameters used for creating
it.
+     *        Bundled in a {@code Map.Entry} as an ugly workaround for RFE #4093999 in Java
bug database
+     *        ("Relax constraint on placement of this()/super() call in constructors").
      */
     AbstractSingleOperation(final SingleOperation definition,
                             final CoordinateReferenceSystem sourceCRS,
                             final CoordinateReferenceSystem targetCRS,
-                            final MathTransform transform)
+                            final Map.Entry<ParameterValueGroup,MathTransform> transform)
     {
-        super(definition, sourceCRS, targetCRS, transform);
+        super(definition, sourceCRS, targetCRS, transform.getValue());
         method = definition.getMethod();
-        parameters = getParameterValues(definition);
+        final ParameterValueGroup p = transform.getKey();
+        parameters = (p != null) ? p : getParameterValues(definition);
     }
 
     /**
@@ -337,8 +345,9 @@ class AbstractSingleOperation extends Ab
      * {@code null} (in conformance with {@link #parameters} contract).
      */
     private static ParameterValueGroup getParameterValues(final SingleOperation operation)
{
-        return (operation instanceof AbstractSingleOperation) ?
-                ((AbstractSingleOperation) operation).parameters : operation.getParameterValues();
+        return (operation instanceof AbstractSingleOperation)
+               ? ((AbstractSingleOperation) operation).parameters   // Null if inferred from
MathTransform
+               : operation.getParameterValues();
     }
 
     /**

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=1684132&r1=1684131&r2=1684132&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] Mon Jun  8 09:58:37 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.operation;
 
 import java.util.Map;
+import java.util.AbstractMap;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.measure.converter.ConversionException;
@@ -386,11 +387,19 @@ public class DefaultConversion extends A
 
     /**
      * Creates the math transform to be given to the sub-class constructor.
-     * This method is a workaround for RFE #4093999 in Sun's bug database
+     * This method is a workaround for RFE #4093999 in Java bug database
      * ("Relax constraint on placement of this()/super() call in constructors").
+     *
+     * <p>This method may also return the parameters used for creating the math transform
because those parameters
+     * may have been augmented with the semi-major and semi-minor axis lengths.  Since those
parameter values have
+     * been set on a clone of {@code definition.getParameterValues()}, those values are lost
(ignoring MathTransform
+     * internal) if we do not return them here.</p>
+     *
+     * @return The math transform, optionally with the parameters used for creating it.
+     *         Bundled in a {@code Map.Entry} as an ugly workaround for RFE #4093999.
      */
     @Workaround(library="JDK", version="1.7")
-    private static MathTransform createMathTransform(
+    private static Map.Entry<ParameterValueGroup,MathTransform> createMathTransform(
             final Conversion definition,
             final CoordinateReferenceSystem sourceCRS,
             final CoordinateReferenceSystem targetCRS,
@@ -398,6 +407,7 @@ public class DefaultConversion extends A
     {
         final int interpDim = ReferencingUtilities.getDimension(getInterpolationCRS(definition));
         MathTransform mt = definition.getMathTransform();
+        final Map.Entry<ParameterValueGroup,MathTransform> pair;
         if (mt == null) {
             /*
              * If the user did not specified explicitely a MathTransform, we will need to
create it
@@ -412,7 +422,9 @@ public class DefaultConversion extends A
                 throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedParameterValues));
             }
             mt = factory.createBaseToDerived(sourceCRS, parameters, targetCRS.getCoordinateSystem());
+            pair = new AbstractMap.SimpleEntry<>(parameters, mt);
         } else {
+            pair = new AbstractMap.SimpleEntry<>(null, mt);
             /*
              * If the user specified explicitely a MathTransform, we may still need to swap
or scale axes.
              * If this conversion is a defining conversion (which is usually the case when
creating a new
@@ -434,13 +446,15 @@ public class DefaultConversion extends A
                  */
                 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(…).
+                pair.setValue(mt);
+                return pair;  // Skip createPassThroughTransform(…) since it was handled
by swapAndScaleAxes(…).
             }
         }
         if (interpDim != 0) {
             mt = factory.createPassThroughTransform(interpDim, mt, 0);
         }
-        return mt;
+        pair.setValue(mt);
+        return pair;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java?rev=1684132&r1=1684131&r2=1684132&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] Mon Jun  8 09:58:37 2015
@@ -466,6 +466,12 @@ public class DefaultMathTransformFactory
      * The {@code OperationMethod} instance used by this constructor can be obtained by a
call to
      * {@link #getLastMethodUsed()}.
      *
+     * <div class="section">Modification of given parameters</div>
+     * If this method needs to set the values of {@code "semi_major"} and {@code "semi_minor"}
parameters,
+     * then it sets those values directly on the given {@code parameters} instance – not
on a clone – for
+     * allowing the caller to get back the complete parameter values.
+     * However this method only fills missing values, it never modify existing values.
+     *
      * @param  baseCRS    The source coordinate reference system.
      * @param  parameters The parameter values for the transform.
      * @param  derivedCS  The target coordinate system.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java?rev=1684132&r1=1684131&r2=1684132&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
[UTF-8] Mon Jun  8 09:58:37 2015
@@ -163,14 +163,14 @@ public final strictfp class GeodeticObje
      */
     @Test
     public void testGeographicCRS() throws ParseException {
-        testGeographicCRS(0,
+        verifyGeographicCRS(0, parse(GeographicCRS.class,
                "  GEOGCS[“WGS84”,\n" +
                "    DATUM[“World Geodetic System 1984”,\n" +
                "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
                "      PRIMEM[“Greenwich”, 0.0],\n" +
                "    UNIT[“degree”, 0.017453292519943295],\n" +
                "    AXIS[“Longitude”, EAST],\n" +
-               "    AXIS[“Latitude”, NORTH]]");
+               "    AXIS[“Latitude”, NORTH]]"));
     }
 
     /**
@@ -181,14 +181,14 @@ public final strictfp class GeodeticObje
     @Test
     @DependsOnMethod("testGeographicCRS")
     public void testAxisSwapping() throws ParseException {
-        testGeographicCRS(1,
+        verifyGeographicCRS(1, parse(GeographicCRS.class,
                "  GEOGCS[“WGS84”,\n" +
                "    DATUM[“World Geodetic System 1984”,\n" +
                "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
                "      PRIMEM[“Greenwich”, 0.0],\n" +
                "    UNIT[“degree”, 0.017453292519943295],\n" +
                "    AXIS[“Latitude”, NORTH],\n" +
-               "    AXIS[“Longitude”, EAST]]");
+               "    AXIS[“Longitude”, EAST]]"));
     }
 
     /**
@@ -196,8 +196,7 @@ public final strictfp class GeodeticObje
      *
      * @param swap 1 if axes are expected to be swapped, or 0 otherwise.
      */
-    private void testGeographicCRS(final int swap, final String wkt) throws ParseException
{
-        final GeographicCRS crs = parse(GeographicCRS.class, wkt);
+    private void verifyGeographicCRS(final int swap, final GeographicCRS crs) throws ParseException
{
         assertNameAndIdentifierEqual("WGS84", 0, crs);
 
         final GeodeticDatum datum = crs.getDatum();
@@ -242,6 +241,7 @@ public final strictfp class GeodeticObje
                "  AXIS[“Northing”, NORTH]]");
 
         assertNameAndIdentifierEqual("Mercator test", 0, crs);
+        verifyGeographicCRS(0, crs.getBaseCRS());
 
         final GeodeticDatum datum = crs.getDatum();
         assertNameAndIdentifierEqual("World Geodetic System 1984", 0, datum);
@@ -259,8 +259,8 @@ public final strictfp class GeodeticObje
 
         assertEquals("Mercator (variant A)", crs.getConversionFromBase().getMethod().getName().getCode());
         final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
-//      assertEquals("semi_major",   6378137.0, param.parameter("semi_major"      ).doubleValue(),
STRICT);
-//      assertEquals("semi_minor",   6356752.3, param.parameter("semi_minor"      ).doubleValue(),
0.1);
+        assertEquals("semi_major",   6378137.0, param.parameter("semi_major"      ).doubleValue(),
STRICT);
+        assertEquals("semi_minor",   6356752.3, param.parameter("semi_minor"      ).doubleValue(),
0.1);
         assertEquals("central_meridian", -20.0, param.parameter("central_meridian").doubleValue(),
STRICT);
         assertEquals("scale_factor",       1.0, param.parameter("scale_factor"    ).doubleValue(),
STRICT);
         assertEquals("false_easting", 500000.0, param.parameter("false_easting"   ).doubleValue(),
STRICT);



Mime
View raw message