sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1678420 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/crs/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/ sis-...
Date Fri, 08 May 2015 18:26:49 GMT
Author: desruisseaux
Date: Fri May  8 18:26:49 2015
New Revision: 1678420

URL: http://svn.apache.org/r1678420
Log:
Referencing: DefaultConversion.specialize(...) method should accepts a MathTransformFactory
argument.
This factory was previously hidden because it was used only for axis swapping or scaling.
But we will need also for creating a MathTransform when the defining conversion has been created
with
only a ParameterValueGroup instance (no MathTransform instance), in which case the need to
control
the MathTransformFactory instance to use become clearer.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.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/DefaultCylindricalProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -51,6 +51,13 @@ public final class OperationMethods exte
     public static final String PARAMETERS_KEY = "parameters";
 
     /**
+     * The key for specifying a {@linkplain org.opengis.referencing.operation.MathTransformFactory}
+     * instance to use for the construction of a geodetic object. This is usually not needed
for CRS
+     * construction, except in the special case of a derived CRS created from a defining
conversion.
+     */
+    public static final String MT_FACTORY = "mtFactory";
+
+    /**
      * Do not allow instantiation of this class.
      */
     private OperationMethods() {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -21,15 +21,20 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.datum.Datum;
 import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.geometry.MismatchedDimensionException;
 import org.apache.sis.referencing.operation.DefaultConversion;
+import org.apache.sis.internal.referencing.OperationMethods;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.Semaphores;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ComparisonMode;
 
@@ -89,7 +94,6 @@ abstract class AbstractDerivedCRS<C exte
      *         do not match the dimension of {@code base} and {@code derivedCS} respectively.
      */
     AbstractDerivedCRS(final Map<String,?>    properties,
-                       final Class<C>         baseType,
                        final SingleCRS        baseCRS,
                        final Conversion       conversion,
                        final CoordinateSystem derivedCS)
@@ -103,7 +107,7 @@ abstract class AbstractDerivedCRS<C exte
             ArgumentChecks.ensureDimensionMatches("baseCRS",   baseToDerived.getSourceDimensions(),
baseCRS);
             ArgumentChecks.ensureDimensionMatches("derivedCS", baseToDerived.getTargetDimensions(),
derivedCS);
         }
-        conversionFromBase = DefaultConversion.castOrCopy(conversion).specialize(baseType,
baseCRS, this);
+        conversionFromBase = createConversionFromBase(properties, baseCRS, conversion);
     }
 
     /**
@@ -115,13 +119,46 @@ abstract class AbstractDerivedCRS<C exte
      *
      * @param crs The coordinate reference system to copy.
      */
-    AbstractDerivedCRS(final GeneralDerivedCRS crs, final Class<C> baseType) {
+    AbstractDerivedCRS(final GeneralDerivedCRS crs) {
         super(crs);
-        conversionFromBase = DefaultConversion.castOrCopy(crs.getConversionFromBase())
-                .specialize(baseType, crs.getBaseCRS(), this);
+        conversionFromBase = createConversionFromBase(null, crs.getBaseCRS(), crs.getConversionFromBase());
     }
 
     /**
+     * Creates the conversion instance to associate with this {@code AbstractDerivedCRS}.
+     *
+     * <p><b>WARNING:</b> this method is invoked at construction time and
will invoke indirectly
+     * (through {@link DefaultConversion}) the {@link #getCoordinateSystem()} method on {@code
this}.
+     * Consequently this method shall be invoked only after the construction of this {@code
AbstractDerivedCRS}
+     * instance is advanced enough for allowing the {@code getCoordinateSystem()} method
to execute.
+     * Subclasses may consider to make the {@code getCoordinateSystem()} method final for
better guarantees.</p>
+     */
+    private C createConversionFromBase(final Map<String,?> properties, final SingleCRS
baseCRS, final Conversion conversion) {
+        MathTransformFactory factory = null;
+        if (properties != null) {
+            factory = (MathTransformFactory) properties.get(OperationMethods.MT_FACTORY);
+        }
+        if (factory == null) {
+            factory = DefaultFactories.forBuildin(MathTransformFactory.class);
+        }
+        try {
+            return DefaultConversion.castOrCopy(conversion).specialize(getConversionType(),
baseCRS, this, factory);
+        } catch (FactoryException e) {
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
+                    "conversionFromBase", conversion.getName()), e);
+        }
+    }
+
+    /**
+     * Returns the type of conversion associated to this {@code AbstractDerivedCRS}.
+     *
+     * <p><b>WARNING:</b> this method is invoked (indirectly) at construction
time.
+     * Consequently it shall return a constant value - this method is not allowed to
+     * depend on the object state.</p>
+     */
+    abstract Class<C> getConversionType();
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      */
     @Override

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -160,7 +160,7 @@ public class DefaultDerivedCRS extends A
                              final CoordinateSystem derivedCS)
             throws MismatchedDimensionException
     {
-        super(properties, Conversion.class, baseCRS, conversionFromBase, derivedCS);
+        super(properties, baseCRS, conversionFromBase, derivedCS);
     }
 
     /**
@@ -175,7 +175,7 @@ public class DefaultDerivedCRS extends A
      * @see #castOrCopy(DerivedCRS)
      */
     protected DefaultDerivedCRS(final DerivedCRS crs) {
-        super(crs, Conversion.class);
+        super(crs);
     }
 
     /**
@@ -239,6 +239,15 @@ public class DefaultDerivedCRS extends A
     }
 
     /**
+     * Returns the type of conversion associated to this {@code DefaultDerivedCRS}.
+     * Must be a hard-coded, constant value (not dependent on object state).
+     */
+    @Override
+    final Class<Conversion> getConversionType() {
+        return Conversion.class;
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code DerivedCRS.class}.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -148,7 +148,7 @@ public class DefaultProjectedCRS extends
                                final CartesianCS   derivedCS)
             throws MismatchedDimensionException
     {
-        super(properties, Projection.class, baseCRS, conversionFromBase, derivedCS);
+        super(properties, baseCRS, conversionFromBase, derivedCS);
     }
 
     /**
@@ -163,7 +163,7 @@ public class DefaultProjectedCRS extends
      * @see #castOrCopy(ProjectedCRS)
      */
     protected DefaultProjectedCRS(final ProjectedCRS crs) {
-        super(crs, Projection.class);
+        super(crs);
     }
 
     /**
@@ -182,6 +182,15 @@ public class DefaultProjectedCRS extends
     }
 
     /**
+     * Returns the type of conversion associated to this {@code DefaultProjectedCRS}.
+     * Must be a hard-coded, constant value (not dependent on object state).
+     */
+    @Override
+    final Class<Projection> getConversionType() {
+        return Projection.class;
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code ProjectedCRS.class}.
      *
@@ -247,7 +256,9 @@ public class DefaultProjectedCRS extends
      */
     @Override
     @XmlElement(name="cartesianCS", required = true)
-    public CartesianCS getCoordinateSystem() {
+    public final CartesianCS getCoordinateSystem() {
+        // See AbstractDerivedCRS.createConversionFromBase(…) for
+        // an explanation about why this method is declared final.
         return (CartesianCS) super.getCoordinateSystem();
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -23,17 +23,13 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-import javax.measure.converter.ConversionException;
-import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.quality.PositionalAccuracy;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.referencing.operation.OperationMethod;
-import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.metadata.Identifier;
 import org.apache.sis.parameter.Parameterized;
 import org.opengis.parameter.ParameterDescriptorGroup;
@@ -47,12 +43,10 @@ import org.apache.sis.util.ComparisonMod
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.UnsupportedImplementationException;
-import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
 import org.apache.sis.internal.referencing.OperationMethods;
 import org.apache.sis.internal.referencing.WKTUtilities;
-import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.system.Semaphores;
@@ -169,7 +163,7 @@ public class AbstractCoordinateOperation
     private final MathTransform transform;
 
     /**
-     * Constructs a new object in which every attributes are set to a null value.
+     * Creates a new object in which every attributes are set to a null value.
      * <strong>This is not a valid object.</strong> This constructor is strictly
      * reserved to JAXB, which will assign values to the fields using reflexion.
      */
@@ -186,66 +180,30 @@ public class AbstractCoordinateOperation
     }
 
     /**
-     * Constructs a new coordinate operation with the same values than the specified defining
conversion,
-     * together with the specified source and target CRS. This constructor is used by {@link
DefaultConversion} only.
+     * Creates a new coordinate operation with the same values than the specified defining
conversion,
+     * except for the source CRS, target CRS and the math transform which are set the given
values.
+     *
+     * <p>This constructor is (indirectly) for {@link DefaultConversion} usage only,
+     * in order to create a "real" conversion from a defining conversion.</p>
      */
     AbstractCoordinateOperation(final CoordinateOperation definition,
                                 final CoordinateReferenceSystem sourceCRS,
                                 final CoordinateReferenceSystem targetCRS,
-                                final MathTransformFactory factory)
+                                final MathTransform transform)
     {
         super(definition);
         this.sourceCRS                   = sourceCRS;
         this.targetCRS                   = targetCRS;
-        this.interpolationCRS            = null;
+        this.interpolationCRS            = getInterpolationCRS(definition);
         this.operationVersion            = definition.getOperationVersion();
         this.coordinateOperationAccuracy = definition.getCoordinateOperationAccuracy();
         this.domainOfValidity            = definition.getDomainOfValidity();
         this.scope                       = definition.getScope();
-        MathTransform mt = definition.getMathTransform();
-        mt = swapAndScaleAxes(mt, sourceCRS, definition.getSourceCRS(), true,  factory);
-        mt = swapAndScaleAxes(mt, definition.getTargetCRS(), targetCRS, false, factory);
-        transform = mt;
+        this.transform                   = transform;
         checkDimensions();
     }
 
     /**
-     * Concatenates to the given transform the operation needed for swapping and scaling
the axes.
-     * The two coordinate systems must implement the same GeoAPI coordinate system interface.
-     * For example if {@code sourceCRS} uses a {@code CartesianCS}, then {@code targetCRS}
must use
-     * a {@code CartesianCS} too.
-     *
-     * @param transform The transform to which to concatenate axis changes.
-     * @param sourceCRS The first CRS of the pair for which to check for axes changes.
-     * @param targetCRS The second CRS of the pair for which to check for axes changes.
-     * @param isSource  {@code true} for pre-concatenating the changes, or {@code false}
for post-concatenating.
-     * @param factory   The factory to use if some axis changes are needed, or {@code null}
for the default.
-     */
-    private static MathTransform swapAndScaleAxes(MathTransform transform,
-            final CoordinateReferenceSystem sourceCRS,
-            final CoordinateReferenceSystem targetCRS,
-            final boolean isSource, MathTransformFactory factory)
-    {
-        if (sourceCRS != null && targetCRS != null && sourceCRS != targetCRS)
try {
-            final Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(),
-                                                                targetCRS.getCoordinateSystem());
-            if (!m.isIdentity()) {
-                if (factory == null) {
-                    factory = DefaultFactories.forBuildin(MathTransformFactory.class);
-                }
-                final MathTransform s = factory.createAffineTransform(m);
-                transform = factory.createConcatenatedTransform(isSource ? s : transform,
-                                                                isSource ? transform : s);
-            }
-        } catch (ConversionException | FactoryException e) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
-                    (isSource ? "sourceCRS" : "targetCRS"),
-                    (isSource ?  sourceCRS  :  targetCRS).getName()), e);
-        }
-        return transform;
-    }
-
-    /**
      * Creates a coordinate operation from the given properties.
      * The properties given in argument follow the same rules than for the
      * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}.
@@ -354,8 +312,7 @@ public class AbstractCoordinateOperation
         if (value instanceof PositionalAccuracy[]) {
             coordinateOperationAccuracy = CollectionsExt.nonEmptySet((PositionalAccuracy[])
value);
         } else {
-            coordinateOperationAccuracy = (value == null) ? null :
-                    Collections.singleton((PositionalAccuracy) value);
+            coordinateOperationAccuracy = (value != null) ? Collections.singleton((PositionalAccuracy)
value) : null;
         }
         checkDimensions();
     }

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=1678420&r1=1678419&r2=1678420&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] Fri May  8 18:26:49 2015
@@ -26,7 +26,6 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
@@ -110,19 +109,20 @@ class AbstractSingleOperation extends Ab
     }
 
     /**
-     * Constructs a new operation with the same values than the specified one, together with
the
-     * specified source and target CRS. While the source operation can be an arbitrary one,
it is
-     * typically a defining conversion.
+     * Creates a new coordinate operation with the same values than the specified defining
conversion,
+     * except for the source CRS, target CRS and the math transform which are set the given
values.
+     *
+     * <p>This constructor is for {@link DefaultConversion} usage only,
+     * in order to create a "real" conversion from a defining conversion.</p>
      */
     AbstractSingleOperation(final SingleOperation definition,
                             final CoordinateReferenceSystem sourceCRS,
                             final CoordinateReferenceSystem targetCRS,
-                            final MathTransformFactory factory)
+                            final MathTransform transform)
     {
-        super(definition, sourceCRS, targetCRS, factory);
+        super(definition, sourceCRS, targetCRS, transform);
         method = definition.getMethod();
-        parameters = (definition instanceof AbstractSingleOperation) ?
-                ((AbstractSingleOperation) definition).parameters : definition.getParameterValues();
+        parameters = getParameterValues(definition);
     }
 
     /**
@@ -137,8 +137,7 @@ class AbstractSingleOperation extends Ab
     protected AbstractSingleOperation(final SingleOperation operation) {
         super(operation);
         method = operation.getMethod();
-        parameters = (operation instanceof AbstractSingleOperation) ?
-                ((AbstractSingleOperation) operation).parameters : operation.getParameterValues();
+        parameters = getParameterValues(operation);
     }
 
     /**
@@ -277,6 +276,16 @@ class AbstractSingleOperation extends Ab
     }
 
     /**
+     * Gets the parameter values of the given operation without computing and without cloning
them (if possible).
+     * If the parameters are automatically inferred from the math transform, do not compute
them and instead return
+     * {@code null} (in conformance with {@link #parameters} contract).
+     */
+    private static ParameterValueGroup getParameterValues(final SingleOperation operation)
{
+        return (operation instanceof AbstractSingleOperation) ?
+                ((AbstractSingleOperation) operation).parameters : operation.getParameterValues();
+    }
+
+    /**
      * Compares this coordinate operation with the specified object for equality. If the
{@code mode} argument
      * is {@link ComparisonMode#STRICT} or {@link ComparisonMode#BY_CONTRACT BY_CONTRACT},
then all available
      * properties are compared including the {@linkplain #getDomainOfValidity() domain of
validity} and the

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.operation;
 
 import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.ConicProjection;
 import org.opengis.referencing.operation.MathTransformFactory;
@@ -49,12 +50,12 @@ final class DefaultConicProjection exten
      * @param definition The defining conversion.
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
-     * @param factory    The factory to use if some axis changes are needed, or {@code null}
for the default.
+     * @param factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      */
     DefaultConicProjection(final Conversion definition,
                            final CoordinateReferenceSystem sourceCRS,
                            final CoordinateReferenceSystem targetCRS,
-                           final MathTransformFactory factory)
+                           final MathTransformFactory factory) throws FactoryException
     {
         super(definition, sourceCRS, targetCRS, factory);
     }

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=1678420&r1=1678419&r2=1678420&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] Fri May  8 18:26:49 2015
@@ -19,12 +19,20 @@ package org.apache.sis.referencing.opera
 import java.util.Map;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.measure.converter.ConversionException;
+import org.opengis.util.FactoryException;
+import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.MathTransformFactory;
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.referencing.cs.CoordinateSystems;
+import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.Workaround;
 
 
 /**
@@ -156,14 +164,14 @@ public class DefaultConversion extends A
      * @param definition The defining conversion.
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
-     * @param factory    The factory to use if some axis changes are needed, or {@code null}
for the default.
+     * @param factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      */
     DefaultConversion(final Conversion definition,
                       final CoordinateReferenceSystem sourceCRS,
                       final CoordinateReferenceSystem targetCRS,
-                      final MathTransformFactory factory)
+                      final MathTransformFactory factory) throws FactoryException
     {
-        super(definition, sourceCRS, targetCRS, factory);
+        super(definition, sourceCRS, targetCRS, createMathTransform(definition, sourceCRS,
targetCRS, factory));
     }
 
     /**
@@ -247,17 +255,110 @@ public class DefaultConversion extends A
      * @param  baseType   The base GeoAPI interface to be implemented by the conversion to
return.
      * @param  sourceCRS  The source CRS.
      * @param  targetCRS  The target CRS.
+     * @param  factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      * @return The conversion of the given type between the given CRS.
      * @throws ClassCastException if a contradiction is found between the given {@code baseType},
      *         the defining {@linkplain DefaultConversion#getInterface() conversion type}
and
      *         the {@linkplain DefaultOperationMethod#getOperationType() method operation
type}.
+     * @throws FactoryException if the creation of a {@link MathTransform} from the {@linkplain
#getParameterValues()
+     *         parameter values}, or a {@linkplain CoordinateSystems#swapAndScaleAxes change
of axis order or units}
+     *         failed.
      */
     public <T extends Conversion> T specialize(final Class<T> baseType,
-            final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS)
+            final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS,
+            final MathTransformFactory factory) throws FactoryException
     {
         ArgumentChecks.ensureNonNull("baseType",  baseType);
         ArgumentChecks.ensureNonNull("sourceCRS", sourceCRS);
         ArgumentChecks.ensureNonNull("targetCRS", targetCRS);
-        return SubTypes.create(baseType, this, sourceCRS, targetCRS, null);
+        ArgumentChecks.ensureNonNull("factory",   factory);
+        return SubTypes.create(baseType, this, sourceCRS, targetCRS, factory);
+    }
+
+    /**
+     * 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
+     * ("Relax constraint on placement of this()/super() call in constructors").
+     */
+    @Workaround(library="JDK", version="1.7")
+    private static MathTransform createMathTransform(
+            final Conversion definition,
+            final CoordinateReferenceSystem sourceCRS,
+            final CoordinateReferenceSystem targetCRS,
+            final MathTransformFactory factory) throws FactoryException
+    {
+        MathTransform mt = definition.getMathTransform();
+        if (mt == null) {
+            /*
+             * If the user did not specified explicitely a MathTransform, we will need to
create it
+             * from the parameters. This case happen often when creating a ProjectedCRS,
because the
+             * user often did not have all needed information when he created the defining
conversion:
+             * the length of semi-major and semi-minor axes were often missing. But now we
know those
+             * lengths thanks to the 'sourceCRS' argument given to this method. So we can
complete the
+             * parameters. This is the job of MathTransformFactory.createBaseToDerived(…).
+             */
+            final ParameterValueGroup parameters = definition.getParameterValues();
+            if (parameters == null) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedParameterValues));
+            }
+            mt = factory.createBaseToDerived(sourceCRS, parameters, targetCRS.getCoordinateSystem());
+        } else {
+            /*
+             * 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
+             * ProjectedCRS), then DefaultMathTransformFactory has a specialized createBaseToDerived(…)
+             * method for this job.
+             */
+            final CoordinateReferenceSystem mtSource = definition.getSourceCRS();
+            final CoordinateReferenceSystem mtTarget = definition.getTargetCRS();
+            if (mtSource == null && mtTarget == null && factory instanceof
DefaultMathTransformFactory) {
+                mt = ((DefaultMathTransformFactory) factory).createBaseToDerived(
+                        sourceCRS.getCoordinateSystem(), mt,
+                        targetCRS.getCoordinateSystem());
+            } else {
+                /*
+                 * If we can not use our SIS factory implementation, or if this conversion
is not a defining
+                 * conversion (i.e. if this is the conversion of an existing ProjectedCRS,
in which case the
+                 * math transform may not be normalized), then we fallback on a simpler swapAndScaleAxes(…)
+                 * method defined in this class. This is needed for AbstractCRS.forConvention(AxisConvention).
+                 */
+                mt = swapAndScaleAxes(mt, sourceCRS, mtSource, true,  factory);
+                mt = swapAndScaleAxes(mt, mtTarget, targetCRS, false, factory);
+            }
+        }
+        return mt;
+    }
+
+    /**
+     * Concatenates to the given transform the operation needed for swapping and scaling
the axes.
+     * The two coordinate systems must implement the same GeoAPI coordinate system interface.
+     * For example if {@code sourceCRS} uses a {@code CartesianCS}, then {@code targetCRS}
must use
+     * a {@code CartesianCS} too.
+     *
+     * @param transform The transform to which to concatenate axis changes.
+     * @param sourceCRS The first CRS of the pair for which to check for axes changes.
+     * @param targetCRS The second CRS of the pair for which to check for axes changes.
+     * @param isSource  {@code true} for pre-concatenating the changes, or {@code false}
for post-concatenating.
+     * @param factory   The factory to use for performing axis changes.
+     */
+    private static MathTransform swapAndScaleAxes(MathTransform transform,
+            final CoordinateReferenceSystem sourceCRS,
+            final CoordinateReferenceSystem targetCRS,
+            final boolean isSource, final MathTransformFactory factory) throws FactoryException
+    {
+        if (sourceCRS != null && targetCRS != null && sourceCRS != targetCRS)
try {
+            final Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(),
+                                                                targetCRS.getCoordinateSystem());
+            if (!m.isIdentity()) {
+                final MathTransform s = factory.createAffineTransform(m);
+                transform = factory.createConcatenatedTransform(isSource ? s : transform,
+                                                                isSource ? transform : s);
+            }
+        } catch (ConversionException e) {
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
+                    (isSource ? "sourceCRS" : "targetCRS"),
+                    (isSource ?  sourceCRS  :  targetCRS).getName()), e);
+        }
+        return transform;
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.operation;
 
 import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.CylindricalProjection;
 import org.opengis.referencing.operation.MathTransformFactory;
@@ -49,12 +50,12 @@ final class DefaultCylindricalProjection
      * @param definition The defining conversion.
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
-     * @param factory    The factory to use if some axis changes are needed, or {@code null}
for the default.
+     * @param factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      */
     DefaultCylindricalProjection(final Conversion definition,
                                  final CoordinateReferenceSystem sourceCRS,
                                  final CoordinateReferenceSystem targetCRS,
-                                 final MathTransformFactory factory)
+                                 final MathTransformFactory factory) throws FactoryException
     {
         super(definition, sourceCRS, targetCRS, factory);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.operation;
 
 import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.PlanarProjection;
 import org.opengis.referencing.operation.MathTransformFactory;
@@ -49,12 +50,12 @@ final class DefaultPlanarProjection exte
      * @param definition The defining conversion.
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
-     * @param factory    The factory to use if some axis changes are needed, or {@code null}
for the default.
+     * @param factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      */
     DefaultPlanarProjection(final Conversion definition,
                             final CoordinateReferenceSystem sourceCRS,
                             final CoordinateReferenceSystem targetCRS,
-                            final MathTransformFactory factory)
+                            final MathTransformFactory factory) throws FactoryException
     {
         super(definition, sourceCRS, targetCRS, factory);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.operation;
 
 import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.Projection;
 import org.opengis.referencing.operation.MathTransformFactory;
@@ -64,12 +65,12 @@ class DefaultProjection extends DefaultC
      * @param definition The defining conversion.
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
-     * @param factory    The factory to use if some axis changes are needed, or {@code null}
for the default.
+     * @param factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      */
     DefaultProjection(final Conversion definition,
                       final CoordinateReferenceSystem sourceCRS,
                       final CoordinateReferenceSystem targetCRS,
-                      final MathTransformFactory factory)
+                      final MathTransformFactory factory) throws FactoryException
     {
         super(definition, sourceCRS, targetCRS, factory);
         ArgumentChecks.ensureCanCast("sourceCRS", GeographicCRS.class, sourceCRS);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.referencing.operation;
 
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.*;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
@@ -30,7 +31,7 @@ import org.apache.sis.referencing.Abstra
  * <ul>
  *   <li>{@link AbstractCoordinateOperation#castOrCopy(CoordinateOperation)}</li>
  *   <li>{@link DefaultConversion#castOrCopy(Conversion)}</li>
- *   <li>{@link DefaultConversion#specialize(Class, CoordinateReferenceSystem, CoordinateReferenceSystem)}</li>
+ *   <li>{@link DefaultConversion#specialize(Class, CoordinateReferenceSystem, CoordinateReferenceSystem,
MathTransformFactory)}</li>
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
@@ -119,7 +120,7 @@ final class SubTypes {
      * @param  definition The defining conversion.
      * @param  sourceCRS  The source CRS.
      * @param  targetCRS  The target CRS.
-     * @param  factory    The factory to use if some axis changes are needed, or {@code null}
for the default.
+     * @param  factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      * @return The conversion of the given type between the given CRS.
      * @throws ClassCastException if a contradiction is found between the given {@code baseType},
      *         the defining {@linkplain DefaultConversion#getInterface() conversion type}
and
@@ -127,7 +128,7 @@ final class SubTypes {
      */
     static <T extends Conversion> T create(final Class<T> baseType, final Conversion
definition,
             final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS,
-            final MathTransformFactory factory)
+            final MathTransformFactory factory) throws FactoryException
     {
         Class<? extends T> type = baseType;
         if (definition instanceof AbstractIdentifiedObject) {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Fri May  8 18:26:49 2015
@@ -951,7 +951,7 @@ public final class Errors extends Indexe
         public static final short UnresolvedFeatureName_1 = 164;
 
         /**
-         * Coordinate reference system is unspecified.
+         * Coordinate reference system has not been specified.
          */
         public static final short UnspecifiedCRS = 173;
 
@@ -961,6 +961,11 @@ public final class Errors extends Indexe
         public static final short UnspecifiedFormatForClass_1 = 126;
 
         /**
+         * Parameter values have not been specified.
+         */
+        public static final short UnspecifiedParameterValues = 185;
+
+        /**
          * Can not handle instances of ‘{0}’ because arbitrary implementations are not
yet supported.
          */
         public static final short UnsupportedImplementation_1 = 127;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Fri May  8 18:26:49 2015
@@ -201,8 +201,9 @@ UnmodifiableObject_1              = This
 UnparsableStringForClass_2        = Text \u201c{1}\u201d can not be parsed as an object of
type \u2018{0}\u2019.
 UnparsableStringForClass_3        = Text \u201c{1}\u201d can not be parsed as an object of
type \u2018{0}\u2019, because of the \u201c{2}\u201d characters.
 UnresolvedFeatureName_1           = Feature named \u201c{0}\u201d has not yet been resolved.
-UnspecifiedCRS                    = Coordinate reference system is unspecified.
+UnspecifiedCRS                    = Coordinate reference system has not been specified.
 UnspecifiedFormatForClass_1       = No format is specified for objects of class \u2018{0}\u2019.
+UnspecifiedParameterValues        = Parameter values have not been specified.
 UnsupportedImplementation_1       = Can not handle instances of \u2018{0}\u2019 because arbitrary
implementations are not yet supported.
 UnsupportedOperation_1            = The \u2018{0}\u2019 operation is unsupported.
 UnsupportedType_1                 = The \u2018{0}\u2019 type is unsupported.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1678420&r1=1678419&r2=1678420&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Fri May  8 18:26:49 2015
@@ -189,6 +189,7 @@ UnmodifiableMetadata              = Cett
 UnmodifiableObject_1              = Cette instance de \u2018{0}\u2019 n\u2019est pas modifiable.
 UnspecifiedCRS                    = Le syst\u00e8me de r\u00e9f\u00e9rence des coordonn\u00e9es
n\u2019a pas \u00e9t\u00e9 sp\u00e9cifi\u00e9.
 UnspecifiedFormatForClass_1       = Aucun format n\u2019est sp\u00e9cifi\u00e9 pour les objets
de classe \u2018{0}\u2019.
+UnspecifiedParameterValues        = Les valeurs des param\u00e8tres n\u2019ont pas \u00e9t\u00e9
sp\u00e9cifi\u00e9es.
 UnparsableStringForClass_2        = Le texte \u00ab\u202f{1}\u202f\u00bb n\u2019est pas reconnu
comme un objet de type \u2018{0}\u2019.
 UnparsableStringForClass_3        = Le texte \u00ab\u202f{1}\u202f\u00bb n\u2019est pas reconnu
comme un objet de type \u2018{0}\u2019, \u00e0 cause des caract\u00e8res \u00ab\u202f{2}\u202f\u00bb.
 UnresolvedFeatureName_1           = L\u2019entit\u00e9 nomm\u00e9e \u00ab\u202f{0}\u202f\u00bb
n\u2019a pas encore \u00e9t\u00e9 r\u00e9solue.



Mime
View raw message