sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Add "National Transformation version 1" (EPSG:9614) operation method.
Date Sun, 16 Feb 2020 23:48:03 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new c50586b  Add "National Transformation version 1" (EPSG:9614) operation method.
c50586b is described below

commit c50586b4bb7912f3dd8557fc4179185c142af19b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sun Feb 16 22:47:43 2020 +0100

    Add "National Transformation version 1" (EPSG:9614) operation method.
---
 .../provider/DatumShiftGridCompressed.java         |  6 +-
 .../referencing/provider/DatumShiftGridFile.java   | 99 ++++++++++++++++++++--
 .../provider/FranceGeocentricInterpolation.java    |  5 ++
 .../sis/internal/referencing/provider/NTv1.java    | 90 ++++++++++++++++++++
 .../sis/internal/referencing/provider/NTv2.java    | 76 ++++++++++++-----
 ...g.opengis.referencing.operation.OperationMethod |  1 +
 .../internal/referencing/provider/NTv2Test.java    | 10 ++-
 .../referencing/provider/ProvidersTest.java        |  1 +
 8 files changed, 252 insertions(+), 36 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java
index e24bcbd..139760e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java
@@ -19,6 +19,7 @@ package org.apache.sis.internal.referencing.provider;
 import java.util.Arrays;
 import javax.measure.Quantity;
 import org.apache.sis.math.DecimalFunctions;
+import org.apache.sis.internal.util.Numerics;
 
 
 /**
@@ -28,7 +29,7 @@ import org.apache.sis.math.DecimalFunctions;
  * 5 digits in base 10 in ASCII files.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  *
  * @param <C>  dimension of the coordinate unit (usually {@link javax.measure.quantity.Angle}).
  * @param <T>  dimension of the translation unit (usually {@link javax.measure.quantity.Angle}
@@ -258,8 +259,7 @@ final class DatumShiftGridCompressed<C extends Quantity<C>, T
extends Quantity<T
     public boolean equals(final Object other) {
         if (super.equals(other)) {
             final DatumShiftGridCompressed<?,?> that = (DatumShiftGridCompressed<?,?>)
other;
-            return Double.doubleToLongBits(scale) == Double.doubleToLongBits(that.scale)
-                   && Arrays.equals(averages, that.averages);
+            return Numerics.equals(scale, that.scale) && Arrays.equals(averages,
that.averages);
         }
         return false;
     }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
index d216397..f77bba7 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
@@ -118,8 +118,8 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends
Quantity<T>>
      * The best translation accuracy that we can expect from this file.
      * The unit of measurement depends on {@link #isCellValueRatio()}.
      *
-     * <p>This field is initialized to {@link Double#NaN}. It is loader responsibility
-     * to assign a value to this field after {@code DatumShiftGridFile} construction.</p>
+     * <p>This field is initialized to zero. It is loader responsibility to assign
+     * a value to this field after {@code DatumShiftGridFile} construction.</p>
      *
      * @see #getCellPrecision()
      */
@@ -173,7 +173,6 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends
Quantity<T>>
         this.descriptor = descriptor;
         this.files      = files;
         this.nx         = nx;
-        this.accuracy   = Double.NaN;
     }
 
     /**
@@ -191,7 +190,6 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends
Quantity<T>>
         subgrids   = other.subgrids;
     }
 
-
     /**
      * Creates a new datum shift grid with the same configuration than the given grid,
      * except the size and transform which are set to the given values.
@@ -478,11 +476,7 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends
Quantity<T>>
               final Path... files) throws NoninvertibleTransformException
         {
             super(coordinateUnit, translationUnit, isCellValueRatio, x0, y0, Δx, Δy, nx,
ny, descriptor, files);
-            offsets = new float[dim][];
-            final int size = Math.multiplyExact(nx, ny);
-            for (int i=0; i<dim; i++) {
-                Arrays.fill(offsets[i] = new float[size], java.lang.Float.NaN);
-            }
+            offsets = new float[dim][Math.multiplyExact(nx, ny)];
         }
 
         /**
@@ -541,6 +535,7 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends
Quantity<T>>
 
         /**
          * Returns the average translation parameters from source to target.
+         * There is no need to use double-double arithmetic here since all data have only
single precision.
          *
          * @param  dim  the dimension for which to get an average value.
          * @return a value close to the average for the given dimension.
@@ -555,4 +550,90 @@ abstract class DatumShiftGridFile<C extends Quantity<C>, T extends
Quantity<T>>
             return sum / data.length;
         }
     }
+
+
+
+
+    /**
+     * An implementation of {@link DatumShiftGridFile} which stores the offset values in
{@code double[]} arrays.
+     * See {@link DatumShiftGridFile.Float} for more information (most comments apply to
this class as well).
+     *
+     * @author  Martin Desruisseaux (Geomatys)
+     * @version 1.1
+     * @since   1.1
+     * @module
+     */
+    static final class Double<C extends Quantity<C>, T extends Quantity<T>>
extends DatumShiftGridFile<C,T> {
+        /**
+         * Serial number for inter-operability with different versions.
+         */
+        private static final long serialVersionUID = 3999271636016362364L;
+
+        /**
+         * The translation values. See {@link DatumShiftGridFile.Float#offsets} for more
documentation.
+         */
+        final double[][] offsets;
+
+        /**
+         * Creates a new datum shift grid with the given grid geometry, filename and number
of shift dimensions.
+         * All {@code double} values given to this constructor will be converted from degrees
to radians.
+         */
+        Double(final int dim,
+               final Unit<C> coordinateUnit,
+               final Unit<T> translationUnit,
+               final boolean isCellValueRatio,
+               final double x0, final double y0,
+               final double Δx, final double Δy,
+               final int    nx, final int    ny,
+               final ParameterDescriptorGroup descriptor,
+               final Path... files) throws NoninvertibleTransformException
+        {
+            super(coordinateUnit, translationUnit, isCellValueRatio, x0, y0, Δx, Δy, nx,
ny, descriptor, files);
+            offsets = new double[dim][Math.multiplyExact(nx, ny)];
+        }
+
+        /**
+         * Creates a new grid of the same geometry than the given grid but using a different
data array.
+         */
+        private Double(final DatumShiftGridFile<C,T> grid, final double[][] offsets)
{
+            super(grid);
+            this.offsets = offsets;
+        }
+
+        /**
+         * Returns a new grid with the same geometry than this grid but different data arrays.
+         * See {@link DatumShiftGridFile.Float#setData(Object[])} for more documentation.
+         */
+        @Override
+        protected final DatumShiftGridFile<C,T> setData(final Object[] other) {
+            return new Double<>(this, (double[][]) other);
+        }
+
+        /**
+         * Returns direct references (not cloned) to the data arrays.
+         * See {@link DatumShiftGridFile.Float#getData()} for more documentation.
+         */
+        @Override
+        @SuppressWarnings("ReturnOfCollectionOrArrayField")
+        protected final Object[] getData() {
+            return offsets;
+        }
+
+        /**
+         * Returns the number of shift dimensions.
+         */
+        @Override
+        public final int getTranslationDimensions() {
+            return offsets.length;
+        }
+
+        /**
+         * Returns the cell value at the given dimension and grid index.
+         * See {@link DatumShiftGridFile.Float#getCellValue(int, int, int)} for more documentation.
+         */
+        @Override
+        public final double getCellValue(final int dim, final int gridX, final int gridY)
{
+            return offsets[dim][gridX + gridY*nx];
+        }
+    }
 }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java
index 61458a8..57b7eb3 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.referencing.provider;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Locale;
 import java.util.NoSuchElementException;
@@ -427,6 +428,10 @@ public class FranceGeocentricInterpolation extends GeodeticOperation
{
                             grid = new DatumShiftGridFile.Float<>(3,
                                     Units.DEGREE, Units.METRE, false,
                                     x0, y0, Δx, Δy, nx, ny, PARAMETERS, file);
+                            grid.accuracy = Double.NaN;
+                            for (final float[] data : grid.offsets) {
+                                Arrays.fill(data, Float.NaN);
+                            }
                         }
                         break;
                     }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv1.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv1.java
new file mode 100644
index 0000000..6243465
--- /dev/null
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv1.java
@@ -0,0 +1,90 @@
+/*
+ * 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.parameter.ParameterNotFoundException;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.opengis.referencing.operation.Transformation;
+import org.apache.sis.parameter.ParameterBuilder;
+
+
+/**
+ * The provider for <cite>"National Transformation version 1"</cite> (EPSG:9614).
+ * This transform requires data that are not bundled by default with Apache SIS.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+@XmlTransient
+public final class NTv1 extends AbstractProvider {
+    /**
+     * Serial number for inter-operability with different versions.
+     */
+    private static final long serialVersionUID = 3485687719315248009L;
+
+    /**
+     * The group of all parameters expected by this coordinate operation.
+     */
+    public static final ParameterDescriptorGroup PARAMETERS;
+    static {
+        final ParameterBuilder builder = builder();
+        PARAMETERS = builder
+                .addIdentifier("9614")
+                .addName("NTv1")
+                .createGroup(NTv2.FILE);
+    }
+
+    /**
+     * Creates a new provider.
+     */
+    public NTv1() {
+        super(2, 2, PARAMETERS);
+    }
+
+    /**
+     * Returns the base interface of the {@code CoordinateOperation} instances that use this
method.
+     *
+     * @return fixed to {@link Transformation}.
+     */
+    @Override
+    public Class<Transformation> getOperationType() {
+        return Transformation.class;
+    }
+
+    /**
+     * Creates a transform from the specified group of parameter values.
+     *
+     * @param  factory  the factory to use if this constructor needs to create other math
transforms.
+     * @param  values   the group of parameter values.
+     * @return the created math transform.
+     * @throws ParameterNotFoundException if a required parameter was not found.
+     * @throws FactoryException if an error occurred while loading the grid.
+     */
+    @Override
+    public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup
values)
+            throws ParameterNotFoundException, FactoryException
+    {
+        return NTv2.createMathTransform(NTv1.class, factory, values, 1);
+    }
+}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
index 50f829b..9742bf0 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/NTv2.java
@@ -87,7 +87,7 @@ public final class NTv2 extends AbstractProvider {
      *   <li>No default value</li>
      * </ul>
      */
-    private static final ParameterDescriptor<Path> FILE;
+    static final ParameterDescriptor<Path> FILE;
 
     /**
      * The group of all parameters expected by this coordinate operation.
@@ -135,18 +135,41 @@ public final class NTv2 extends AbstractProvider {
     public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup
values)
             throws ParameterNotFoundException, FactoryException
     {
+        return createMathTransform(NTv2.class, factory, values, 2);
+    }
+
+    /**
+     * Creates a transform from the specified group of parameter values.
+     *
+     * @param  provider  the provider which is creating a transform: {@link NTv2} or {@link
NTv1}.
+     * @param  factory   the factory to use if this constructor needs to create other math
transforms.
+     * @param  values    the group of parameter values.
+     * @param  version   the expected version (1 or 2).
+     * @return the created math transform.
+     * @throws ParameterNotFoundException if a required parameter was not found.
+     * @throws FactoryException if an error occurred while loading the grid.
+     */
+    static MathTransform createMathTransform(final Class<? extends AbstractProvider>
provider,
+            final MathTransformFactory factory, final ParameterValueGroup values, final int
version)
+            throws ParameterNotFoundException, FactoryException
+    {
         final Parameters pg = Parameters.castOrWrap(values);
-        return DatumShiftGridFile.createGeodeticTransformation(NTv2.class, factory, getOrLoad(pg.getMandatoryValue(FILE)));
+        final DatumShiftGridFile<Angle,Angle> grid = getOrLoad(provider, pg.getMandatoryValue(FILE),
version);
+        return DatumShiftGridFile.createGeodeticTransformation(provider, factory, grid);
     }
 
     /**
      * Returns the grid of the given name. This method returns the cached instance if it
still exists,
      * or load the grid otherwise.
      *
-     * @param  file  name of the datum shift grid file to load.
+     * @param  provider  the provider which is creating a transform.
+     * @param  file      name of the datum shift grid file to load.
+     * @param  version   the expected version (1 or 2).
      */
     @SuppressWarnings("null")
-    static DatumShiftGridFile<Angle,Angle> getOrLoad(final Path file) throws FactoryException
{
+    static DatumShiftGridFile<Angle,Angle> getOrLoad(final Class<? extends AbstractProvider>
provider,
+            final Path file, final int version) throws FactoryException
+    {
         final Path resolved = DataDirectory.DATUM_CHANGES.resolve(file).toAbsolutePath();
         DatumShiftGridFile<?,?> grid = DatumShiftGridFile.CACHE.peek(resolved);
         if (grid == null) {
@@ -155,12 +178,12 @@ public final class NTv2 extends AbstractProvider {
                 grid = handler.peek();
                 if (grid == null) {
                     try (ReadableByteChannel in = Files.newByteChannel(resolved)) {
-                        DatumShiftGridLoader.startLoading(NTv2.class, file);
-                        final Loader loader = new Loader(in, file, 2);
+                        DatumShiftGridLoader.startLoading(provider, file);
+                        final Loader loader = new Loader(in, file, version);
                         grid = loader.readAllGrids();
-                        loader.report(NTv2.class);
+                        loader.report(provider);
                     } catch (IOException | NoninvertibleTransformException | RuntimeException
e) {
-                        throw DatumShiftGridLoader.canNotLoad("NTv2", file, e);
+                        throw DatumShiftGridLoader.canNotLoad(provider.getSimpleName(), file,
e);
                     }
                     grid = grid.useSharedData();
                 }
@@ -539,26 +562,38 @@ public final class NTv2 extends AbstractProvider {
              * free us from reversing the sign of longitude translations in the code below;
instead, this reversal
              * will be handled by grid.coordinateToGrid MathTransform and its inverse.
              */
-            final DatumShiftGridFile.Float<Angle,Angle> grid = new DatumShiftGridFile.Float<>(2,
-                        unit, unit, true, -xmin, ymin, -dx, dy, width, height, PARAMETERS,
file);
-            @SuppressWarnings("MismatchedReadAndWriteOfArray") final float[] tx = grid.offsets[0];
-            @SuppressWarnings("MismatchedReadAndWriteOfArray") final float[] ty = grid.offsets[1];
+            final double size = Math.max(dx, dy);
+            final DatumShiftGridFile<Angle,Angle> grid;
             if (isV2) {
+                final DatumShiftGridFile.Float<Angle,Angle> data;
+                data = new DatumShiftGridFile.Float<>(2, unit, unit, true,
+                        -xmin, ymin, -dx, dy, width, height, PARAMETERS, file);
+                @SuppressWarnings("MismatchedReadAndWriteOfArray") final float[] tx = data.offsets[0];
+                @SuppressWarnings("MismatchedReadAndWriteOfArray") final float[] ty = data.offsets[1];
+                data.accuracy = Double.NaN;
                 for (int i=0; i<count; i++) {
                     ensureBufferContains(4 * Float.BYTES);
                     ty[i] = (float) (buffer.getFloat() / dy);   // Division by dx and dy
because isCellValueRatio = true.
                     tx[i] = (float) (buffer.getFloat() / dx);
                     final double accuracy = Math.min(buffer.getFloat() / dy, buffer.getFloat()
/ dx);
-                    if (accuracy > 0 && !(accuracy >= grid.accuracy)) {   //
Use '!' for replacing the initial NaN.
-                        grid.accuracy = accuracy;                         // Smallest non-zero
accuracy.
+                    if (accuracy > 0 && !(accuracy >= data.accuracy)) {   
 // Use '!' for replacing the initial NaN.
+                        data.accuracy = accuracy;                           // Smallest non-zero
accuracy.
                     }
                 }
+                grid = DatumShiftGridCompressed.compress(data, null, precision / size);
             } else {
-                // NTv1: same as NTv2 but using double precision and without accuracy information.
+                /*
+                 * NTv1: same as NTv2 but using double precision and without accuracy information.
+                 */
+                final DatumShiftGridFile.Double<Angle,Angle> data;
+                grid = data = new DatumShiftGridFile.Double<>(2, unit, unit, true,
+                        -xmin, ymin, -dx, dy, width, height, PARAMETERS, file);
+                @SuppressWarnings("MismatchedReadAndWriteOfArray") final double[] tx = data.offsets[0];
+                @SuppressWarnings("MismatchedReadAndWriteOfArray") final double[] ty = data.offsets[1];
                 for (int i=0; i<count; i++) {
                     ensureBufferContains(2 * Double.BYTES);
-                    ty[i] = (float) (buffer.getDouble() / dy);
-                    tx[i] = (float) (buffer.getDouble() / dx);
+                    ty[i] = buffer.getDouble() / dy;
+                    tx[i] = buffer.getDouble() / dx;
                 }
             }
             /*
@@ -566,8 +601,7 @@ public final class NTv2 extends AbstractProvider {
              * during inverse transformations. If we did not found that information in the
file, compute
              * an arbitrary default accuracy.
              */
-            final double size = Math.max(dx, dy);
-            if (Double.isNaN(grid.accuracy)) {
+            if (!(grid.accuracy > 0)) {                 // Use ! for catching NaN values
(paranoiac check).
                 grid.accuracy = Units.DEGREE.getConverterTo(unit).convert(Formulas.ANGULAR_TOLERANCE)
/ size;
             }
             /*
@@ -576,7 +610,7 @@ public final class NTv2 extends AbstractProvider {
              * relationship here; we will do that after all sub-grids have been read.
              */
             final String name = (String) get("SUB_NAME", numGrids > 1);
-            if (addTo.put(name, DatumShiftGridCompressed.compress(grid, null, precision /
size)) != null) {
+            if (addTo.put(name, grid) != null) {
                 throw new FactoryException(Errors.format(Errors.Keys.DuplicatedIdentifier_1,
name));
             }
             children.computeIfAbsent((String) get("PARENT", numGrids > 1), (k) -> new
ArrayList<>()).add(grid);
@@ -588,7 +622,7 @@ public final class NTv2 extends AbstractProvider {
         }
 
         /**
-         * Gets the value for the given key. If the value is absent, this method throws an
exception
+         * Gets the value for the given key. If the value is absent, then this method throws
an exception
          * if {@code mandatory} is {@code true} or returns {@code null} otherwise.
          *
          * @param  key        key of the value to search.
diff --git a/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
b/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
index 5aa20e9..ae5ddfe 100644
--- a/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
+++ b/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
@@ -60,6 +60,7 @@ org.apache.sis.internal.referencing.provider.Sinusoidal
 org.apache.sis.internal.referencing.provider.Polyconic
 org.apache.sis.internal.referencing.provider.Mollweide
 org.apache.sis.internal.referencing.provider.NTv2
+org.apache.sis.internal.referencing.provider.NTv1
 org.apache.sis.internal.referencing.provider.NADCON
 org.apache.sis.internal.referencing.provider.FranceGeocentricInterpolation
 org.apache.sis.internal.referencing.provider.Interpolation1D
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
index 1077f01..2a16de9 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
@@ -121,7 +121,7 @@ public final strictfp class NTv2Test extends DatumShiftTestCase {
             final double ymin, final double ymax) throws FactoryException, TransformException
     {
         final double cellSize = 360;
-        final DatumShiftGridFile<Angle,Angle> grid = NTv2.getOrLoad(file);
+        final DatumShiftGridFile<Angle,Angle> grid = NTv2.getOrLoad(NTv2.class, file,
2);
         assertInstanceOf("Should not be compressed.", DatumShiftGridFile.Float.class, grid);
         assertEquals("coordinateUnit",  Units.ARC_SECOND, grid.getCoordinateUnit());
         assertEquals("translationUnit", Units.ARC_SECOND, grid.getTranslationUnit());
@@ -170,7 +170,7 @@ public final strictfp class NTv2Test extends DatumShiftTestCase {
         // Same test than above, but let DatumShiftGrid do the conversions for us.
         assertArrayEquals("interpolateAt", expected, grid.interpolateAt(position),
                 FranceGeocentricInterpolationTest.ANGULAR_TOLERANCE * DEGREES_TO_SECONDS);
-        assertSame("Grid should be cached.", grid, NTv2.getOrLoad(file));
+        assertSame("Grid should be cached.", grid, NTv2.getOrLoad(NTv2.class, file, 2));
     }
 
     /**
@@ -186,7 +186,7 @@ public final strictfp class NTv2Test extends DatumShiftTestCase {
         assumeTrue(RUN_EXTENSIVE_TESTS);
         final Path file = DataDirectory.DATUM_CHANGES.resolve(Paths.get(MULTIGRID_TEST_FILE));
         assumeTrue(Files.exists(file));
-        final DatumShiftGridFile<Angle,Angle> grid = NTv2.getOrLoad(file);
+        final DatumShiftGridFile<Angle,Angle> grid = NTv2.getOrLoad(NTv2.class, file,
2);
         assertInstanceOf("Should contain many grids.", DatumShiftGridGroup.class, grid);
         assertEquals("coordinateUnit",  Units.ARC_SECOND, grid.getCoordinateUnit());
         assertEquals("translationUnit", Units.ARC_SECOND, grid.getTranslationUnit());
@@ -236,6 +236,10 @@ public final strictfp class NTv2Test extends DatumShiftTestCase {
         result[0] = position[0] - result[0] * cellSize;                     // Positive translation
is toward west.
         result[1] = position[1] + result[1] * cellSize;
         assertArrayEquals("interpolateInCell", expected, result, Formulas.ANGULAR_TOLERANCE
* DEGREES_TO_SECONDS);
+        /*
+         * Verify that the caching mechanism works for DatumShiftGridGroup too.
+         */
+        assertSame("Grid should be cached.", grid, NTv2.getOrLoad(NTv2.class, file, 2));
     }
 
 
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
index c6e497d..3373bae 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ProvidersTest.java
@@ -110,6 +110,7 @@ public final strictfp class ProvidersTest extends TestCase {
             Polyconic.class,
             Mollweide.class,
             NTv2.class,
+            NTv1.class,
             NADCON.class,
             FranceGeocentricInterpolation.class,
             MolodenskyInterpolation.class,


Mime
View raw message