sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1794135 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/provider/ main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/internal/referencing/provider/
Date Sat, 06 May 2017 11:48:53 GMT
Author: desruisseaux
Date: Sat May  6 11:48:53 2017
New Revision: 1794135

URL: http://svn.apache.org/viewvc?rev=1794135&view=rev
Log:
Fix an exception that occurs on attempt to redimension a "Geographic 3D to 2D conversion"
operation method.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeodeticOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic2Dto3D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Providers.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeodeticOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeodeticOperation.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeodeticOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeodeticOperation.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -19,6 +19,7 @@ package org.apache.sis.internal.referenc
 import javax.xml.bind.annotation.XmlTransient;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.referencing.operation.OperationMethod;
+import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.Transformation;
 
 
@@ -86,6 +87,8 @@ abstract class GeodeticOperation extends
      * Returns the three-dimensional variant of this operation method, or {@code null} if
none.
      * This method needs to be overridden only if the three-dimensional variant is an instance
      * of a different class than this instance.
+     *
+     * <p>This method is not needed on the JDK9 branch.</p>
      */
     Class<? extends GeodeticOperation> variant3D() {
         return null;
@@ -112,12 +115,12 @@ abstract class GeodeticOperation extends
     }
 
     /**
-     * Returns the interface implemented by all coordinate operations that extends this class.
+     * Returns the interface implemented by most coordinate operations that extends this
class.
      *
-     * @return fixed to {@link Transformation}.
+     * @return default to {@link Transformation}.
      */
     @Override
-    public final Class<Transformation> getOperationType() {
+    public Class<? extends SingleOperation> getOperationType() {
         return Transformation.class;
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic2Dto3D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic2Dto3D.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic2Dto3D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic2Dto3D.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -21,7 +21,6 @@ import org.opengis.util.FactoryException
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
-import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.apache.sis.referencing.operation.matrix.Matrices;
@@ -41,12 +40,15 @@ import org.apache.sis.parameter.Paramete
  * format the inverse ({@code "INVERSE_MT"}) of 3D to 2D transform.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
- * @since   0.7
+ * @version 0.8
+ *
+ * @see Geographic3Dto2D
+ *
+ * @since 0.7
  * @module
  */
 @XmlTransient
-public final class Geographic2Dto3D extends AbstractProvider {
+public final class Geographic2Dto3D extends GeographicRedimension {
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -71,17 +73,24 @@ public final class Geographic2Dto3D exte
      * Constructs a provider with default parameters.
      */
     public Geographic2Dto3D() {
-        super(2, 3, PARAMETERS);
+        this(null);
+    }
+
+    /**
+     * Constructs a provider that can be resized.
+     */
+    Geographic2Dto3D(GeodeticOperation[] redimensioned) {
+        super(2, 3, PARAMETERS, redimensioned);
     }
 
     /**
-     * Returns the operation type.
-     *
-     * @return interface implemented by all coordinate operations that use this method.
+     * Returns the tree-dimensional variant of this class.
+     * Used for having a unique instance of this provider.
+     * This hack is not needed on the JDK9 branch.
      */
     @Override
-    public Class<Conversion> getOperationType() {
-        return Conversion.class;
+    Class<Geographic3Dto2D> variant3D() {
+        return Geographic3Dto2D.class;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2D.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -20,7 +20,6 @@ import javax.xml.bind.annotation.XmlTran
 import org.opengis.util.FactoryException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
-import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
@@ -40,12 +39,15 @@ import org.apache.sis.internal.referenci
  * The inverse operation arbitrarily sets the ellipsoidal height to zero.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
- * @since   0.7
+ * @version 0.8
+ *
+ * @see Geographic2Dto3D
+ *
+ * @since 0.7
  * @module
  */
 @XmlTransient
-public final class Geographic3Dto2D extends AbstractProvider {
+public final class Geographic3Dto2D extends GeographicRedimension {
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -66,17 +68,18 @@ public final class Geographic3Dto2D exte
      * Constructs a provider with default parameters.
      */
     public Geographic3Dto2D() {
-        super(3, 2, PARAMETERS);
+        this(new GeodeticOperation[4]);
+        redimensioned[0] = new GeographicRedimension(2, redimensioned);
+        redimensioned[1] = new Geographic2Dto3D(redimensioned);
+        redimensioned[2] = this;
+        redimensioned[3] = new GeographicRedimension(3, redimensioned);
     }
 
     /**
-     * Returns the operation type.
-     *
-     * @return interface implemented by all coordinate operations that use this method.
+     * Constructs a provider that can be resized.
      */
-    @Override
-    public Class<Conversion> getOperationType() {
-        return Conversion.class;
+    private Geographic3Dto2D(GeodeticOperation[] redimensioned) {
+        super(3, 2, PARAMETERS, redimensioned);
     }
 
     /**

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java?rev=1794135&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.referencing.provider;
+
+import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.util.FactoryException;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.internal.util.Constants;
+
+
+/**
+ * Base class of operations working on the number of dimensions of a geographic CRS.
+ * The default implementation does nothing; this is used as a placeholder for the result
of a call
+ * to {@link Geographic3Dto2D#redimension(int, int)} when the given number of dimensions
are equal.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+@XmlTransient
+class GeographicRedimension extends GeodeticOperation {
+    /**
+     * Serial number for inter-operability with different versions.
+     */
+    private static final long serialVersionUID = -3021902514274756742L;
+
+    /**
+     * Constructs a math transform provider from a set of parameters.
+     * This is for sub-class constructors only.
+     */
+    GeographicRedimension(final int sourceDimensions,
+                          final int targetDimensions,
+                          final ParameterDescriptorGroup parameters,
+                          final GeodeticOperation[] redimensioned)
+    {
+        super(sourceDimensions, targetDimensions, parameters, redimensioned);
+    }
+
+    /**
+     * Creates an identity operation of the given number of dimensions.
+     */
+    GeographicRedimension(final int dimension, final GeodeticOperation[] redimensioned) {
+        super(dimension, dimension, builder().setCodeSpace(Citations.SIS, Constants.SIS)
+                .addName("Identity " + dimension + 'D').createGroup(), redimensioned);
+    }
+
+    /**
+     * Returns the interface implemented by all coordinate operations that extends this class.
+     *
+     * @return default to {@link Conversion}.
+     */
+    @Override
+    public final Class<Conversion> getOperationType() {
+        return Conversion.class;
+    }
+
+    /**
+     * Returns the transform.
+     *
+     * @param  factory  the factory for creating affine transforms.
+     * @param  values   the parameter values.
+     * @return the math transform for the given parameter values.
+     * @throws FactoryException if an error occurred while creating the transform.
+     */
+    @Override
+    public MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup
values)
+            throws FactoryException
+    {
+        return factory.createAffineTransform(Matrices.createDiagonal(getTargetDimensions()
+ 1, getSourceDimensions() + 1));
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/GeographicRedimension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Providers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Providers.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Providers.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Providers.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -27,6 +27,8 @@ import org.apache.sis.internal.util.Lazy
  *
  * <p>This class is <strong>not</strong> thread-safe. Synchronization are
user's responsibility.</p>
  *
+ * <p>This class is not needed on the JDK9 branch.</p>
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 0.7
  * @since   0.7
@@ -54,11 +56,11 @@ public final class Providers extends Laz
                 for (int i=cached.size(); --i >= 0;) {
                     final OperationMethod m = cached.get(i);
                     if (m.getClass() == variant3D) {
-                        final GeodeticOperation candidate = ((GeodeticOperation) m).redimensioned[0];
-                        if (candidate != null) {            // Should not be null, but let
be safe.
-                            assert candidate.getClass() == element.getClass() : variant3D;
-                            element = candidate;
-                            break;
+                        for (final GeodeticOperation candidate : ((GeodeticOperation) m).redimensioned)
{
+                            if (candidate != null && candidate.getClass() == element.getClass())
{
+                                element = candidate;
+                                break;
+                            }
                         }
                     }
                 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -104,19 +104,22 @@ final class DefaultConcatenatedOperation
      * @param  mtFactory   the math transform factory to use for math transforms concatenation.
      * @throws FactoryException if the factory can not concatenate the math transforms.
      */
-    @SuppressWarnings("PublicConstructorInNonPublicClass")
     public DefaultConcatenatedOperation(final Map<String,?> properties, CoordinateOperation[]
operations,
             final MathTransformFactory mtFactory) throws FactoryException
     {
         super(properties);
         ArgumentChecks.ensureNonNull("operations", operations);
-        final List<CoordinateOperation> flattened = new ArrayList<>(operations.length);
-        initialize(properties, operations, flattened, mtFactory,
-                (coordinateOperationAccuracy == null), (domainOfValidity == null));
-        if (flattened.size() < 2) {
+        if (operations.length < 2) {
             throw new IllegalArgumentException(Errors.getResources(properties).getString(
                     Errors.Keys.TooFewOccurrences_2, 2, CoordinateOperation.class));
         }
+        final List<CoordinateOperation> flattened = new ArrayList<>(operations.length);
+        initialize(properties, operations, flattened, mtFactory,
+                (coordinateOperationAccuracy == null), (domainOfValidity == null));
+        /*
+         * At this point we should have flattened.size() >= 2, except if some operations
+         * were omitted because their associated math transform were identity operation.
+         */
         operations      = flattened.toArray(new CoordinateOperation[flattened.size()]);
         this.operations = UnmodifiableArrayList.wrap(operations);
         this.sourceCRS  = operations[0].getSourceCRS();
@@ -190,7 +193,7 @@ final class DefaultConcatenatedOperation
                     }
                 }
             }
-            previous = op.getTargetCRS();   // For next iteration cycle.
+            previous = op.getTargetCRS();                                       // For next
iteration cycle.
             /*
              * Now that we have verified the CRS dimensions, we should be able to concatenate
the transforms.
              * If an operation is a nested ConcatenatedOperation (not allowed by ISO 19111,
but we try to be
@@ -205,7 +208,7 @@ final class DefaultConcatenatedOperation
                 @SuppressWarnings("SuspiciousToArrayCall")
                 final CoordinateOperation[] asArray = children.toArray(new CoordinateOperation[children.size()]);
                 initialize(properties, asArray, flattened, (step == null) ? mtFactory : null,
setAccuracy, setDomain);
-            } else {
+            } else if (!step.isIdentity()) {
                 flattened.add(op);
             }
             if (mtFactory != null) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -650,12 +650,22 @@ next:   for (int i=components.size(); --
         if (operations != null && operations.length == 1) {
             return operations[0];
         }
-        final CoordinateOperation op;
+        final ConcatenatedOperation op;
         try {
             op = new DefaultConcatenatedOperation(properties, operations, getMathTransformFactory());
         } catch (IllegalArgumentException exception) {
             throw new InvalidGeodeticParameterException(exception.getLocalizedMessage(),
exception);
         }
+        /*
+         * Verifies again the number of single operations.  We may have a singleton if some
operations
+         * were omitted because their associated math transform were identity. This happen
for example
+         * if a "Geographic 3D to 2D conversion" as been redimensioned to a "3D to 3D" operation.
+         */
+        final List<? extends CoordinateOperation> co = op.getOperations();
+        if (co.size() == 1) {
+            assert op.getMathTransform().equals(co.get(0).getMathTransform()) : op;
+            return co.get(0);
+        }
         return pool.unique(op);
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/Geographic3Dto2DTest.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -34,7 +34,7 @@ import static org.opengis.test.Assert.*;
  * Tests the {@link Geographic3Dto2D} class.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 0.8
  * @since   0.7
  * @module
  */
@@ -69,6 +69,18 @@ public final strictfp class Geographic3D
     }
 
     /**
+     * Tests {@link Geographic3Dto2D#redimension(int, int)}.
+     */
+    @Test
+    public void testRedimension() {
+        final Geographic3Dto2D provider = new Geographic3Dto2D();
+        assertSame  ("3 → 2", provider,                    provider.redimension(3, 2));
+        assertEquals("2 → 3", Geographic2Dto3D.class,      provider.redimension(2, 3).getClass());
+        assertEquals("3 → 3", GeographicRedimension.class, provider.redimension(3, 3).getClass());
+        assertEquals("2 → 2", GeographicRedimension.class, provider.redimension(2, 2).getClass());
+    }
+
+    /**
      * Creates a "Geographic 2D to 3D → Geocentric → Affine → Geographic → Geographic
3D to 2D" chain.
      * This method is used for integration tests.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java?rev=1794135&r1=1794134&r2=1794135&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
[UTF-8] Sat May  6 11:48:53 2017
@@ -124,6 +124,8 @@ public final strictfp class ProvidersTes
             PositionVector7Param3D.class,
             GeocentricTranslation2D.class,
             GeocentricTranslation3D.class,
+            Geographic3Dto2D.class,
+            Geographic2Dto3D.class,
             Molodensky.class,
             AbridgedMolodensky.class,
             FranceGeocentricInterpolation.class



Mime
View raw message