sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1661572 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/ sis-referencing/src/main/java/org/apache/sis/parameter...
Date Sun, 22 Feb 2015 22:07:18 GMT
Author: desruisseaux
Date: Sun Feb 22 22:07:17 2015
New Revision: 1661572

URL: http://svn.apache.org/r1661572
Log:
Affine.parameters(Matrix) now select the appropriate parameter set (EPSG or OGC)
depending on the matrix characteristics (size and whether it is affine).

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/LocalizedStaticObject.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -191,7 +191,7 @@ public class AffineTransform2D extends I
      */
     @Override
     public ParameterDescriptorGroup getParameterDescriptors() {
-        return Affine.descriptor(2, 2);
+        return Affine.getProvider(2, 2, true).getParameters();
     }
 
     /**
@@ -201,7 +201,7 @@ public class AffineTransform2D extends I
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return Affine.parameters(getMatrix());
+        return Affine.parameters(matrix);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -43,6 +43,22 @@ abstract class AbstractProvider extends
     private static final long serialVersionUID = 2239172887926695217L;
 
     /**
+     * Constructs a math transform provider from the given properties and a set of parameters.
+     *
+     * @param properties      Set of properties. Shall contain at least {@code "name"}.
+     * @param sourceDimension Number of dimensions in the source CRS of this operation method.
+     * @param targetDimension Number of dimensions in the target CRS of this operation method.
+     * @param parameters      The set of parameters (never {@code null}).
+     */
+    AbstractProvider(final Map<String,?> properties,
+                     final int sourceDimension,
+                     final int targetDimension,
+                     final ParameterDescriptorGroup parameters)
+    {
+        super(properties, sourceDimension, targetDimension, parameters);
+    }
+
+    /**
      * Constructs a math transform provider from a set of parameters. The provider name and
      * {@linkplain #getIdentifiers() identifiers} will be the same than the parameter ones.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Affine.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -17,10 +17,11 @@
 package org.apache.sis.internal.referencing.provider;
 
 import java.util.Map;
+import java.util.Arrays;
 import java.util.Collections;
-import org.opengis.parameter.ParameterDescriptorGroup;
-import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.MathTransform;
@@ -29,8 +30,8 @@ import org.apache.sis.internal.util.Cons
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
 import org.apache.sis.parameter.TensorParameters;
-import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.NamedIdentifier;
+import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 
 
@@ -76,6 +77,11 @@ public final class Affine extends Abstra
     public static final String NAME = "Affine general parametric transformation";
 
     /**
+     * The EPSG:9624 compliant instance, created when first needed.
+     */
+    private static volatile Affine EPSG_METHOD;
+
+    /**
      * The number of dimensions used by the EPSG:9624 definition. This will be used as the
      * default number of dimensions. Operation methods of other dimensions, where we have
      * no EPSG definition, shall use the Well Known Text (WKT) parameter names.
@@ -96,56 +102,69 @@ public final class Affine extends Abstra
     private static final Affine[] cached = new Affine[MAX_CACHED_DIMENSION * MAX_CACHED_DIMENSION];
 
     /**
-     * Returns the index where to store a method of the given dimensions in the {@link #cached}
array,
-     * or -1 if it should not be cached.
+     * A map containing identification properties for creating {@code OperationMethod} or
+     * {@code ParameterDescriptorGroup} instances.
      */
-    static int cacheIndex(int sourceDimensions, int targetDimensions) {
-        if (--sourceDimensions >= 0 && sourceDimensions < MAX_CACHED_DIMENSION
&&
-            --targetDimensions >= 0 && targetDimensions < MAX_CACHED_DIMENSION)
-        {
-            return sourceDimensions * MAX_CACHED_DIMENSION + targetDimensions;
-        }
-        return -1;
+    private static final Map<String,?> IDENTIFICATION_EPSG, IDENTIFICATION_OGC;
+    static {
+        final NamedIdentifier nameOGC = new NamedIdentifier(Citations.OGC, Constants.OGC,
Constants.AFFINE, null, null);
+        IDENTIFICATION_OGC = Collections.singletonMap(NAME_KEY, nameOGC);
+        IDENTIFICATION_EPSG = EPSGName.properties(9624, NAME, nameOGC);
     }
 
     /**
-     * Index equivalent to {@link cacheIndex(EPSG_DIMENSION, EPSG_DIMENSION)}.
-     * We expand the computation inline for allowing the compiler to replace the whole
-     * expression by a single constant.
-     */
-    static final int EPSG_INDEX = (EPSG_DIMENSION - 1) * MAX_CACHED_DIMENSION + (EPSG_DIMENSION
- 1);
-
-    /**
-     * Creates a provider for affine transform with a default matrix size.
+     * Creates a provider for affine transform with a default matrix size (standard EPSG:9624
instance).
+     * This constructor is public for the needs of {@link java.util.ServiceLoader} — do
not invoke explicitely.
+     * If an instance of {@code Affine()} is desired, invoke {@code getProvider(EPSG_DIMENSION,
EPSG_DIMENSION)}
+     * instead.
+     *
+     * @see org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory
      */
     public Affine() {
-        super(EPSG_DIMENSION, EPSG_DIMENSION, new DefaultParameterDescriptorGroup(
-                Collections.singletonMap(NAME_KEY, new NamedIdentifier(Citations.EPSG, NAME)),
1, 1,
-                TensorParameters.ALPHANUM.getAllDescriptors(EPSG_DIMENSION, EPSG_DIMENSION)));
+        super(IDENTIFICATION_EPSG, EPSG_DIMENSION, EPSG_DIMENSION, new Descriptor(IDENTIFICATION_EPSG,
+                Arrays.copyOfRange( // Discards param 0 and 1, take only the ones in index
range [2…7].
+                        TensorParameters.ALPHANUM.getAllDescriptors(EPSG_DIMENSION, EPSG_DIMENSION
+ 1), 2, 8)));
         /*
-         * Unconditionally cache this instance because this constructor is typically invoked
by ServiceLoader
-         * when DefaultMathTransformFactory scans the classpath. This normally happen only
once, so the instance
-         * that we create here is probably the unique instance than we want to keep for the
JVM lifetime.
+         * Do caching ourselves because this constructor is usually not invoked by getProvider(int,
int).
+         * It is usually invoked when DefaultMathTransformFactory scans the classpath with
a ServiceLoader.
+         * This normally happen only once, so this instance is probably the unique instance
to keep in the JVM.
          */
-        synchronized (cached) {
-            cached[EPSG_INDEX] = this;
-        }
+        EPSG_METHOD = this;
     }
 
     /**
      * Creates a provider for affine transform with the specified dimensions.
+     * This is created when first needed by {@link #getProvider(int, int)}.
+     *
+     * @see #getProvider(int, int)
      */
     private Affine(final int sourceDimensions, final int targetDimensions) {
-        super(sourceDimensions, targetDimensions, new DefaultParameterDescriptorGroup(
-                Collections.singletonMap(NAME_KEY, new NamedIdentifier(Citations.OGC, Constants.AFFINE)),
1, 1,
-                TensorParameters.WKT1.getAllDescriptors(sourceDimensions, targetDimensions)));
+        super(IDENTIFICATION_OGC, sourceDimensions, targetDimensions, new Descriptor(IDENTIFICATION_OGC,
+                TensorParameters.WKT1.getAllDescriptors(targetDimensions + 1, sourceDimensions
+ 1)));
     }
 
     /**
-     * Returns {@code true} if the given dimensions are those of EPSG:9624 operation method.
+     * The parameter descriptor to be returned by {@link Affine#getParameters()}.
+     * The only purpose of this class is to override the {@link #createValue()} method.
      */
-    private static boolean isEPSG(final int sourceDimensions, final int targetDimensions)
{
-        return (sourceDimensions == EPSG_DIMENSION && targetDimensions == EPSG_DIMENSION);
+    private static final class Descriptor extends DefaultParameterDescriptorGroup {
+        /** For cross-version compatibility. */
+        private static final long serialVersionUID = 8320799650519834830L;
+
+        /** Creates a new descriptor for the given parameters. */
+        Descriptor(final Map<String,?> properties, final ParameterDescriptor<?>[]
parameters) {
+            super(properties, 1, 1, parameters);
+        }
+
+        /**
+         * Returns default parameter values for the "Affine" operation. Unconditionally use
the WKT1 parameter names,
+         * regardless of whether this descriptor is for the EPSG:9624 case, because the caller
is free to change the
+         * matrix size, in which case (strictly speaking) the parameters would no longer
be for EPSG:9624 operation.
+         */
+        @Override
+        public ParameterValueGroup createValue() {
+            return TensorParameters.WKT1.createValueGroup(IDENTIFICATION_OGC);
+        }
     }
 
     /**
@@ -183,7 +202,20 @@ public final class Affine extends Abstra
      */
     @Override
     public OperationMethod redimension(final int sourceDimensions, final int targetDimensions)
{
-        return getProvider(sourceDimensions, targetDimensions);
+        return getProvider(sourceDimensions, targetDimensions, false);
+    }
+
+    /**
+     * Returns the index where to store a method of the given dimensions in the {@link #cached}
array,
+     * or -1 if it should not be cached.
+     */
+    private static int cacheIndex(int sourceDimensions, int targetDimensions) {
+        if (--sourceDimensions >= 0 && sourceDimensions < MAX_CACHED_DIMENSION
&&
+            --targetDimensions >= 0 && targetDimensions < MAX_CACHED_DIMENSION)
+        {
+            return sourceDimensions * MAX_CACHED_DIMENSION + targetDimensions;
+        }
+        return -1;
     }
 
     /**
@@ -192,50 +224,54 @@ public final class Affine extends Abstra
      *
      * @param sourceDimensions The number of source dimensions.
      * @param targetDimensions The number of target dimensions.
+     * @param isAffine {@code true} if the transform is affine.
      * @return The provider for transforms of the given source and target dimensions.
      */
-    private static Affine getProvider(final int sourceDimensions, final int targetDimensions)
{
-        final int i = cacheIndex(sourceDimensions, targetDimensions);
-        if (i >= 0) {
-            final Affine method;
-            synchronized (Affine.class) {
-                method = cached[i];
+    public static Affine getProvider(final int sourceDimensions, final int targetDimensions,
final boolean isAffine) {
+        Affine method;
+        if (isAffine && sourceDimensions == EPSG_DIMENSION && targetDimensions
== EPSG_DIMENSION) {
+            /*
+             * Matrix complies with EPSG:9624 definition. This is the most common case. We
do perform synchronization
+             * for this field since it is okay if the same object is created twice (they
should be identical).
+             */
+            method = EPSG_METHOD;
+            if (method == null) {
+                method = new Affine();
             }
-            if (method != null) {
-                return method;
+        } else {
+            /*
+             * All other cases. We will use the WKT1 parameter names instead than the EPSG
ones.
+             */
+            final int index = cacheIndex(sourceDimensions, targetDimensions);
+            if (index >= 0) {
+                synchronized (cached) {
+                    method = cached[index];
+                }
+                if (method != null) {
+                    return method;
+                }
             }
-        }
-        /*
-         * At this point, no existing instance has been found in the cache.
-         * Create a new instance and cache it if its dimension is not too large.
-         */
-        final Affine method = isEPSG(sourceDimensions, targetDimensions)
-                ? new Affine() : new Affine(sourceDimensions, targetDimensions);
-        if (i >= 0) {
-            synchronized (Affine.class) {
-                final Affine other = cached[i];     // May have been created in another thread.
-                if (other != null) {
-                    return other;
+            /*
+             * At this point, no existing instance has been found in the cache.
+             * Create a new instance and cache it if its dimension is not too large.
+             */
+            method = new Affine(sourceDimensions, targetDimensions);
+            if (index >= 0) {
+                synchronized (cached) {
+                    final Affine other = cached[index];     // May have been created in another
thread.
+                    if (other != null) {
+                        return other;
+                    }
+                    cached[index] = method;
                 }
-                cached[i] = method;
             }
         }
         return method;
     }
 
     /**
-     * Returns the parameter descriptor for the given dimensions.
-     *
-     * @param sourceDimensions The number of source dimensions.
-     * @param targetDimensions The number of target dimensions.
-     * @return The parameters descriptor for the given dimensions.
-     */
-    public static ParameterDescriptorGroup descriptor(final int sourceDimensions, final int
targetDimensions) {
-        return getProvider(sourceDimensions, targetDimensions).getParameters();
-    }
-
-    /**
-     * Returns the parameter values for the given matrix.
+     * Returns the parameter values for the given matrix. This method is invoked by implementations
of
+     * {@link org.apache.sis.referencing.operation.transform.AbstractMathTransform#getParameterValues()}.
      *
      * @param  matrix The matrix for which to get parameter values.
      * @return The parameters of the given matrix.
@@ -243,8 +279,15 @@ public final class Affine extends Abstra
     public static ParameterValueGroup parameters(final Matrix matrix) {
         final int sourceDimensions = matrix.getNumCol() - 1;
         final int targetDimensions = matrix.getNumRow() - 1;
-        Map<String,?> properties = IdentifiedObjects.getProperties(descriptor(sourceDimensions,
targetDimensions));
-        return (isEPSG(sourceDimensions, targetDimensions) ? TensorParameters.ALPHANUM :
TensorParameters.WKT1)
-                .createValueGroup(properties, matrix);
+        final TensorParameters<Double> parameters;
+        final Map<String,?> properties;
+        if (sourceDimensions == EPSG_DIMENSION && targetDimensions == EPSG_DIMENSION
&& Matrices.isAffine(matrix)) {
+            parameters = TensorParameters.ALPHANUM;
+            properties = IDENTIFICATION_EPSG;
+        } else {
+            parameters = TensorParameters.WKT1;
+            properties = IDENTIFICATION_OGC;
+        }
+        return parameters.createValueGroup(properties, matrix);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/EPSGName.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -18,6 +18,8 @@ package org.apache.sis.internal.referenc
 
 import java.util.Map;
 import java.util.HashMap;
+import org.opengis.metadata.Identifier;
+import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
@@ -43,14 +45,21 @@ public final class EPSGName {  // TODO:
     /**
      * Version of the operation method, or {@code null} if unknown.
      *
-     * This is unspecified in current Apache SIS implementation.
+     * <p>This is unspecified in current Apache SIS implementation.
      * However future SIS implementations may fetch this information from the EPSG database.
+     * In the meantime, we use this constant as a way to track the places in Apache SIS code
+     * base where this information is desired.</p>
      */
     private static final String VERSION = null;
 
     /**
      * Placeholder for what may be (in a future Apache SIS version) an implementation
      * capable to fetch the remarks from the database using the given identifier code.
+     *
+     * <p>This is unspecified in current Apache SIS implementation.
+     * However future SIS implementations may fetch this information from the EPSG database.
+     * In the meantime, we use this constant as a way to track the places in Apache SIS code
+     * base where this information is desired.</p>
      */
     private static final InternationalString REMARKS = null;
 
@@ -61,6 +70,26 @@ public final class EPSGName {  // TODO:
     }
 
     /**
+     * Creates an EPSG name or alias.
+     *
+     * @param code The EPSG name to be returned by {@link NamedIdentifier#getCode()}.
+     * @return An EPSG name or alias for the given string.
+     */
+    public static NamedIdentifier create(final String code) {
+        return new NamedIdentifier(Citations.OGP, Constants.EPSG, code, VERSION, REMARKS);
+    }
+
+    /**
+     * Creates an EPSG identifier.
+     *
+     * @param  code The EPSG code.
+     * @return The EPSG identifier for the given numerical value.
+     */
+    public static Identifier identifier(final int code) {
+        return new ImmutableIdentifier(Citations.OGP, Constants.EPSG, String.valueOf(code).intern(),
VERSION, REMARKS);
+    }
+
+    /**
      * Creates a map of properties to be given to the construction of an operation method.
      * The returned map is modifiable - callers can add or remove entries after this method
call.
      *
@@ -69,15 +98,27 @@ public final class EPSGName {  // TODO:
      * @param  nameOGC    The OGC name, or {@code null} if none.
      * @return A map of properties for building the operation method.
      */
-    public static Map<String,Object> properties(final short identifier, final String
name, final String nameOGC) {
+    public static Map<String,Object> properties(final int identifier, final String
name, final String nameOGC) {
+        return properties(identifier, name, (nameOGC == null) ? null :
+            // Version and remarks are intentionally null here, since they are not EPSG version
or remarks.
+            new NamedIdentifier(Citations.OGC, Constants.OGC, nameOGC, null, null));
+    }
+
+    /**
+     * Creates a map of properties to be given to the construction of an operation method.
+     * The returned map is modifiable - callers can add or remove entries after this method
call.
+     *
+     * @param  identifier The EPSG code.
+     * @param  name       The EPSG name.
+     * @param  nameOGC    The OGC name, or {@code null} if none.
+     * @return A map of properties for building the operation method.
+     */
+    public static Map<String,Object> properties(final int identifier, final String
name, final GenericName nameOGC) {
         final Map<String,Object> properties = new HashMap<>(4);
-        properties.put(NAME_KEY, new NamedIdentifier(
-                Citations.OGP, Constants.EPSG, name, VERSION, REMARKS));
-        properties.put(IDENTIFIERS_KEY, new ImmutableIdentifier(
-                Citations.OGP, Constants.EPSG, Short.toString(identifier).intern(), VERSION,
REMARKS));
+        properties.put(IDENTIFIERS_KEY, identifier(identifier));
+        properties.put(NAME_KEY, create(name));
         if (nameOGC != null) {
-            // Version and remarks are intentionally null here, since they are not EPSG version
or remarks.
-            properties.put(ALIAS_KEY, new NamedIdentifier(Citations.OGC, Constants.OGC, nameOGC,
null, null));
+            properties.put(ALIAS_KEY, nameOGC);
         }
         return properties;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParameters.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -19,11 +19,12 @@ package org.apache.sis.parameter;
 import java.util.Map;
 import java.util.HashMap;
 import java.io.ObjectStreamException;
-import org.opengis.metadata.citation.Citation;
+import org.opengis.util.GenericName;
 import org.opengis.parameter.ParameterDescriptor;
 import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.referencing.provider.Affine;
+import org.apache.sis.internal.referencing.provider.EPSGName;
 import org.apache.sis.metadata.iso.citation.Citations;
 
 
@@ -160,17 +161,13 @@ class MatrixParameters extends TensorPar
                 new NamedIdentifier(Citations.OGC, Constants.OGC, indicesToName(indices),
null, null));
         final String c = indicesToAlias(indices);
         if (c != null) {
-            final Citation authority;
-            final String codeSpace;
+            final GenericName alias;
             if (isEPSG(indices)) {
-                authority = Citations.OGP;
-                codeSpace = Constants.EPSG;
+                alias = EPSGName.create(c);
             } else {
-                authority  = Citations.SIS;
-                codeSpace  = Constants.SIS;
+                alias = new NamedIdentifier(Citations.SIS, Constants.SIS, c, null, null);
             }
-            properties.put(ParameterDescriptor.ALIAS_KEY,
-                    new NamedIdentifier(authority, codeSpace, c, null, null));
+            properties.put(ParameterDescriptor.ALIAS_KEY, alias);
         }
         return new DefaultParameterDescriptor<>(properties, 0, 1, Double.class, null,
null, getDefaultValue(indices));
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/MatrixParametersAlphaNum.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -22,8 +22,7 @@ import java.io.ObjectStreamException;
 import org.opengis.util.GenericName;
 import org.opengis.parameter.ParameterDescriptor;
 import org.apache.sis.internal.util.Constants;
-import org.apache.sis.metadata.iso.ImmutableIdentifier;
-import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.internal.referencing.provider.EPSGName;
 
 import static org.apache.sis.internal.util.CollectionsExt.first;
 
@@ -111,10 +110,8 @@ final class MatrixParametersAlphaNum ext
          * Declare the EPSG identifier only for A0, A1, A2, B0, B1 and B2.
          */
         if (isEPSG(indices)) {
-            final ImmutableIdentifier id;
             final int code = (indices[0] == 0 ? Constants.A0 : Constants.B0) + indices[1];
-            id = new ImmutableIdentifier(Citations.OGP, Constants.EPSG, String.valueOf(code));
-            properties.put(ParameterDescriptor.IDENTIFIERS_KEY, id);
+            properties.put(ParameterDescriptor.IDENTIFIERS_KEY, EPSGName.identifier(code));
         }
         return new DefaultParameterDescriptor<>(properties, 0, 1, Double.class, null,
null, wkt.getDefaultValue());
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -437,7 +437,7 @@ public class TensorParameters<E> impleme
         }
         /*
          * Parameter not found in the cache. Create a new one and cache it for future reuse.
-         * Note that an other thread could have created the same descriptor in the main time,
+         * Note that an other thread could have created the same descriptor in the meantime,
          * so we will need to check again.
          */
         final ParameterDescriptor<E> param = createElementDescriptor(indices);
@@ -660,6 +660,8 @@ public class TensorParameters<E> impleme
      *
      * @see #getDimensionDescriptor(int)
      * @see #getElementDescriptor(int...)
+     *
+     * @since 0.6
      */
     public ParameterDescriptor<?>[] getAllDescriptors(final int... actualSize) {
         verifyRank(actualSize);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -309,7 +309,7 @@ final class CopyTransform extends Abstra
      */
     @Override
     public ParameterDescriptorGroup getParameterDescriptors() {
-        return Affine.descriptor(srcDim, getTargetDimensions());
+        return Affine.getProvider(srcDim, getTargetDimensions(), true).getParameters();
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -133,7 +133,7 @@ final class IdentityTransform extends Ab
      */
     @Override
     public ParameterDescriptorGroup getParameterDescriptors() {
-        return Affine.descriptor(dimension, dimension);
+        return Affine.getProvider(dimension, dimension, true).getParameters();
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -115,7 +115,7 @@ class LinearTransform1D extends Abstract
      */
     @Override
     public ParameterDescriptorGroup getParameterDescriptors() {
-        return Affine.descriptor(1, 1);
+        return Affine.getProvider(1, 1, true).getParameters();
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -151,7 +151,7 @@ class ProjectiveTransform extends Abstra
      */
     @Override
     public ParameterDescriptorGroup getParameterDescriptors() {
-        return Affine.descriptor(getSourceDimensions(), getTargetDimensions());
+        return Affine.getProvider(getSourceDimensions(), getTargetDimensions(), Matrices.isAffine(this)).getParameters();
     }
 
     /**
@@ -162,7 +162,7 @@ class ProjectiveTransform extends Abstra
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return Affine.parameters(getMatrix());
+        return Affine.parameters(this);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AffineTest.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -16,8 +16,10 @@
  */
 package org.apache.sis.internal.referencing.provider;
 
-import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.GeneralParameterDescriptor;
+import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -36,47 +38,76 @@ import static org.apache.sis.test.Metada
 @DependsOn(org.apache.sis.parameter.TensorValuesTest.class)
 public final strictfp class AffineTest extends TestCase {
     /**
-     * Ensures that the {@link Affine#EPSG_INDEX} value is consistent with
-     * {@link Affine#cacheIndex(int, int)} computation.
+     * Tests {@link Affine#getParameters()} on a standard EPSG:9624 instance.
      */
     @Test
-    public void testEpsgIndex() {
-        assertEquals("EPSG_INDEX", Affine.cacheIndex(Affine.EPSG_DIMENSION, Affine.EPSG_DIMENSION),
Affine.EPSG_INDEX);
+    public void testParameters() {
+        verifyParameters(Affine.getProvider(Affine.EPSG_DIMENSION, Affine.EPSG_DIMENSION,
true),
+                "A0", "A1", "A2",
+                "B0", "B1", "B2");
+    }
+
+    /**
+     * Tests {@link Affine#getParameters()} on an instance that do not comply with EPSG definition.
+     * The {@link Affine} provider should fallback on OGC parameters in such cases.
+     */
+    @Test
+    public void testOGCParameters() {
+        verifyParameters(Affine.getProvider(3, 2, true),
+                "num_row",
+                "num_col",
+                "elt_0_0", "elt_0_1", "elt_0_2", "elt_0_3",
+                "elt_1_0", "elt_1_1", "elt_1_2", "elt_1_3",
+                "elt_2_0", "elt_2_1", "elt_2_2", "elt_2_3");
+    }
+
+    /**
+     * Verifies that the given providers contain parameters of the given names.
+     */
+    private static void verifyParameters(final Affine provider, final String... expectedNames)
{
+        int index = 0;
+        for (final GeneralParameterDescriptor p : provider.getParameters().descriptors())
{
+            final String expectedName = expectedNames[index++];
+            assertEquals(expectedName, p.getName().getCode());
+        }
+        assertEquals("Number of parameters", expectedNames.length, index);
     }
 
     /**
      * Tests WKT formatting, and in particular the adjustment according
      * whether we comply with EPSG:9624 definition or not.
      */
+    @Test
+    @DependsOnMethod("testParameters")
     public void testWKT() {
-        final ParameterValueGroup matrix = Affine.parameters(Matrices.createDiagonal(3, 3));
+        final Matrix matrix = Matrices.createDiagonal(3, 3);
         assertWktEquals(
                 "ParameterGroup[“Affine general parametric transformation”," +
-                " Id[“EPSG”, 9624, Citation[“OGP”]]]", matrix);
+                " Id[“EPSG”, 9624, Citation[“OGP”]]]", Affine.parameters(matrix));
         /*
          * Try arbitrary values.
          */
-        matrix.parameter("A1").setValue( 2);
-        matrix.parameter("B1").setValue( 0);
-        matrix.parameter("B2").setValue(-1);
+        matrix.setElement(0, 1,  2);  // A1
+        matrix.setElement(1, 1,  0);  // B1
+        matrix.setElement(1, 2, -1);  // B2
         assertWktEquals(
                 "ParameterGroup[“Affine general parametric transformation”,\n" +
                 "  Parameter[“A1”, 2.0, Id[“EPSG”, 8624]],\n"  +
                 "  Parameter[“B1”, 0.0, Id[“EPSG”, 8640]],\n" +
                 "  Parameter[“B2”, -1.0, Id[“EPSG”, 8641]],\n" +
-                "  Id[“EPSG”, 9624, Citation[“OGP”]]]", matrix);
+                "  Id[“EPSG”, 9624, Citation[“OGP”]]]", Affine.parameters(matrix));
         /*
          * Setting a value on the last row make the matrix non-affine.
-         * So it should not ne anymore EPSG:9624.
-         *
-         * TODO: The parameter should also be renamed as "elt_0_1", "elt_1_1", etc.
+         * So it should not be anymore EPSG:9624.
          */
-        matrix.parameter("C0").setValue(3);
+        matrix.setElement(2, 0, 3);  // C0
         assertWktEquals(
                 "ParameterGroup[“Affine”,\n" +
-                "  Parameter[“A1”, 2.0, Id[“EPSG”, 8624]],\n"  +
-                "  Parameter[“B1”, 0.0, Id[“EPSG”, 8640]],\n" +
-                "  Parameter[“B2”, -1.0, Id[“EPSG”, 8641]],\n" +
-                "  Parameter[“C0”, 3.0]]", matrix);
+                "  Parameter[“num_row”, 3],\n"  +
+                "  Parameter[“num_col”, 3],\n"  +
+                "  Parameter[“elt_0_1”, 2.0],\n"  +
+                "  Parameter[“elt_1_1”, 0.0],\n" +
+                "  Parameter[“elt_1_2”, -1.0],\n" +
+                "  Parameter[“elt_2_0”, 3.0]]", Affine.parameters(matrix));
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -60,7 +60,7 @@ public final strictfp class CopyTransfor
     public void testIdentity() throws TransformException {
         transform = new CopyTransform(3, 0, 1, 2);
         validate();
-        verifyParameters(Affine.descriptor(3, 3), null);
+        verifyParameters(Affine.getProvider(3, 3, true).getParameters(), null);
         verifyIsIdentity(true);
 
         final double[] source = generateRandomCoordinates();

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -130,7 +130,7 @@ public strictfp class ProjectiveTransfor
                 Matrices.equals(matrix, tm, tolerance, false));
 
         assertSame("ParameterDescriptor",
-                Affine.descriptor(transform.getSourceDimensions(), transform.getTargetDimensions()),
+                Affine.getProvider(transform.getSourceDimensions(), transform.getTargetDimensions(),
true).getParameters(),
                 ((Parameterized) transform).getParameterDescriptors());
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/LocalizedStaticObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/LocalizedStaticObject.java?rev=1661572&r1=1661571&r2=1661572&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/LocalizedStaticObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/LocalizedStaticObject.java
[UTF-8] Sun Feb 22 22:07:17 2015
@@ -29,7 +29,7 @@ import java.lang.annotation.RetentionPol
  *
  * If JDK provided listeners allowing SIS to be notified about locale and timezone changes,
we would
  * reset the annotated object to {@code null}. However since those listeners do not exist
as of JDK7,
- * we use this annotation in the main time for identifying the code which would need to be
revisited
+ * we use this annotation in the meantime for identifying the code which would need to be
revisited
  * if we want to take in account default locale/timezone changes in a future SIS version.
  *
  * @author  Martin Desruisseaux (Geomatys)



Mime
View raw message