You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/11/19 16:37:28 UTC

svn commit: r1715198 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/provider/ main/java/org/apache/sis/referencing/datum/ main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/si...

Author: desruisseaux
Date: Thu Nov 19 15:37:28 2015
New Revision: 1715198

URL: http://svn.apache.org/viewvc?rev=1715198&view=rev
Log:
Move the FranceGeocentricInterpolation.Grid implementation in a new DatumShiftGridFile class
in anticipation for NADCON and NTv2 datum shift grid files support.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java   (with props)
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java   (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedGeocentricTransform.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java?rev=1715198&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java (added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridCompressed.java [UTF-8] Thu Nov 19 15:37:28 2015
@@ -0,0 +1,142 @@
+/*
+ * 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;
+
+
+/**
+ * A datum shift grid which store the values in {@code short[]} array.
+ * In addition to using half the space of {@code float[]} arrays, it can also (ironically)
+ * increase the precision in the common case where the shifts are specified with no more than
+ * 5 digits in base 10 in ASCII files.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+final class DatumShiftGridCompressed extends DatumShiftGridFile {
+    /**
+     * Serial number for inter-operability with different versions.
+     */
+    private static final long serialVersionUID = 4847888093457104917L;
+
+    /**
+     * An "average" value for the offset in each dimension.
+     */
+    private final double[] averages;
+
+    /**
+     * Differences between {@link #averages} values and the actual value.
+     * The differences need to be multiplied by {@link #scale}.
+     */
+    private final short[][] data;
+
+    /**
+     * The factor by which to multiply each {@link #data} value before to add to the {@link #averages}.
+     */
+    private final double scale;
+
+    /**
+     * Creates a new datum shift grid for the same geometry than the given grid but different data.
+     */
+    private DatumShiftGridCompressed(final DatumShiftGridFile grid, final double[] averages,
+            final short[][] data, final double scale)
+    {
+        super(grid);
+        this.averages = averages;
+        this.data     = data;
+        this.scale    = scale;
+    }
+
+    /**
+     * Tries to compress the given grid. If this operation succeed, a new grid is returned.
+     * Otherwise this method returns the given {@code grid} unchanged.
+     *
+     * @param  grid      The grid to compress.
+     * @param  averages  An "average" value for the offset in each dimension, or {@code null} if unknown.
+     * @param  scale     The factor by which to multiply each compressed value before to add to the average value.
+     * @return The grid to use (may or may not be compressed).
+     */
+    static DatumShiftGridFile compress(final DatumShiftGridFile.Float grid, double[] averages, final double scale) {
+        final short[][] data = new short[grid.offsets.length][];
+        final boolean computeAverages = (averages == null);
+        if (computeAverages) {
+            averages = new double[data.length];
+        }
+        for (int dim = 0; dim < data.length; dim++) {
+            if (computeAverages) {
+                averages[dim] = grid.getAverageOffset(dim);
+            }
+            final double average = averages[dim];
+            final float[] offsets = grid.offsets[dim];
+            final short[] compressed = new short[offsets.length];
+            for (int i=0; i<offsets.length; i++) {
+                final double c = (offsets[i] - average) / scale;
+                final double e = (compressed[i] = (short) c) - c;
+                if (!(Math.abs(e) < Math.ulp((float) c))) {         // Use '!' for catching NaN values.
+                    return grid;    // Can not compress.
+                }
+            }
+            data[dim] = compressed;
+        }
+        return new DatumShiftGridCompressed(grid, averages, data, scale);
+    }
+
+    /**
+     * Returns a new grid with the same geometry than this grid but different data arrays.
+     */
+    @Override
+    final DatumShiftGridFile setData(final Object[] other) {
+        return new DatumShiftGridCompressed(this, averages, (short[][]) other, scale);
+    }
+
+    /**
+     * Returns direct references (not cloned) to the data arrays.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
+    final Object[] getData() {
+        return data;
+    }
+
+    /**
+     * Returns the number of shift dimensions.
+     */
+    @Override
+    public final int getShiftDimensions() {
+        return data.length;
+    }
+
+    /**
+     * Returns the average translation parameters from source to target.
+     *
+     * @param dim The dimension for which to get an average value.
+     * @return A value close to the average for the given dimension.
+     */
+    @Override
+    public double getAverageOffset(final int dim) {
+        return averages[dim];
+    }
+
+    /**
+     * Returns the cell value at the given grid index.
+     */
+    @Override
+    protected double getCellValue(final int dim, final int gridX, final int gridY) {
+        return data[dim][gridX + gridY*nx] * scale + averages[dim];
+    }
+}

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

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

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java?rev=1715198&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java (added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.java [UTF-8] Thu Nov 19 15:37:28 2015
@@ -0,0 +1,217 @@
+/*
+ * 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 java.util.Arrays;
+import java.nio.file.Path;
+import java.lang.reflect.Array;
+import org.apache.sis.util.collection.Cache;
+import org.apache.sis.referencing.datum.DatumShiftGrid;
+
+
+/**
+ * A datum shift grid loaded from a file.
+ * The filename is usually a parameter defined in the EPSG database.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+public abstract class DatumShiftGridFile extends DatumShiftGrid {
+    /**
+     * Serial number for inter-operability with different versions.
+     */
+    private static final long serialVersionUID = -4471670781277328193L;
+
+    /**
+     * Cache of grids loaded so far. Those grids will be stored by soft references until the amount of
+     * data exceed 32768 (about 128 kilobytes if the values use the {@code float} type). in which case
+     * the oldest grids will be replaced by weak references.
+     */
+    static final Cache<Path, DatumShiftGridFile> CACHE = new Cache<Path, DatumShiftGridFile>(4, 32*1024, true) {
+        @Override protected int cost(final DatumShiftGridFile grid) {
+            int p = 1;
+            for (final Object array : grid.getData()) {
+                p *= Array.getLength(array);
+            }
+            return p;
+        }
+    };
+
+    /**
+     * The file from which the grid has been loaded. This is not used directly by this class
+     * (except for {@link #equals(Object)} and {@link #hashCode()}), but can be used by math
+     * transform for setting the parameter values.
+     */
+    private final String file;
+
+    /**
+     * Creates a new datum shift grid for the given grid geometry.
+     * The actual offset values need to be provided by subclasses.
+     *
+     * @param x0  First ordinate (often longitude in radians) of the center of the cell at grid index (0,0).
+     * @param y0  Second ordinate (often latitude in radians) of the center of the cell at grid index (0,0).
+     * @param Δx  Increment in <var>x</var> value between cells at index <var>gridX</var> and <var>gridX</var> + 1.
+     * @param Δy  Increment in <var>y</var> value between cells at index <var>gridY</var> and <var>gridY</var> + 1.
+     * @param nx  Number of cells along the <var>x</var> axis in the grid.
+     * @param ny  Number of cells along the <var>y</var> axis in the grid.
+     */
+    DatumShiftGridFile(final double x0, final double y0,
+                       final double Δx, final double Δy,
+                       final int    nx, final int    ny,
+                       final Path file)
+    {
+        super(x0, y0, Δx, Δy, nx, ny);
+        this.file = file.getFileName().toString();
+    }
+
+    /**
+     * Creates a new datum shift grid with the same grid geometry than the given grid.
+     *
+     * @param other The other datum shift grid from which to copy the grid geometry.
+     */
+    DatumShiftGridFile(final DatumShiftGridFile other) {
+        super(other);
+        this.file = other.file;
+    }
+
+    /**
+     * If a grid exists in the cache for the same data, returns a new grid sharing the same data arrays.
+     * Otherwise returns {@code this}.
+     */
+    final DatumShiftGridFile useSharedData() {
+        final Object[] data = getData();
+        for (final DatumShiftGridFile grid : CACHE.values()) {
+            final Object[] other = grid.getData();
+            if (Arrays.deepEquals(data, other)) {
+                return setData(other);
+            }
+        }
+        return this;
+    }
+
+    /**
+     * Returns a new grid with the same geometry than this grid but different data arrays.
+     * This method is invoked by {@link #useSharedData()} when it detected that a newly created grid uses
+     * the same data than an existing grid. The typical use case is when a filename is different but still
+     * reference the same grid (e.g. symbolic link, lower case versus upper case in a case-insensitive file
+     * system).
+     */
+    abstract DatumShiftGridFile setData(Object[] other);
+
+    /**
+     * Returns the data for each shift dimensions.
+     */
+    abstract Object[] getData();
+
+    /**
+     * Returns the value to shown in {@code PARAMETER} WKT elements.
+     * Current implementation returns the grid filename.
+     *
+     * @return The grid filename.
+     */
+    @Override
+    public String toString() {
+        return file;
+    }
+
+
+
+
+    /**
+     * An implementation of {@link DatumShiftGridFile} which stores the offset values in {@code float[]} arrays.
+     *
+     * @author  Martin Desruisseaux (Geomatys)
+     * @since   0.7
+     * @version 0.7
+     * @module
+     */
+    static class Float extends DatumShiftGridFile {
+        /**
+         * Serial number for inter-operability with different versions.
+         */
+        private static final long serialVersionUID = -9221609983475286496L;
+
+        /**
+         * The translation values.
+         */
+        final float[][] offsets;
+
+        /**
+         * Creates a new datum shift grid with the given grid geometry, filename and number of shift dimensions.
+         */
+        Float(final double x0, final double y0,
+              final double Δx, final double Δy,
+              final int    nx, final int    ny,
+              final Path file, final int dim)
+        {
+            super(x0, y0, Δx, Δy, nx, ny, file);
+            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);
+            }
+        }
+
+        /**
+         * Creates a new grid of the same geometry than the given grid but using a different data array.
+         */
+        private Float(final DatumShiftGridFile grid, final float[][] offsets) {
+            super(grid);
+            this.offsets = offsets;
+        }
+
+        /**
+         * Returns a new grid with the same geometry than this grid but different data arrays.
+         */
+        @Override
+        final DatumShiftGridFile setData(final Object[] other) {
+            return new Float(this, (float[][]) other);
+        }
+
+        /**
+         * Returns direct references (not cloned) to the data arrays.
+         */
+        @Override
+        @SuppressWarnings("ReturnOfCollectionOrArrayField")
+        final Object[] getData() {
+            return offsets;
+        }
+
+        /**
+         * Returns the number of shift dimension.
+         */
+        @Override
+        public final int getShiftDimensions() {
+            return offsets.length;
+        }
+
+        /**
+         * Returns the cell value at the given dimension and grid index.
+         *
+         * @param dim    The dimension for which to get an average value.
+         * @param gridX  The grid index along the <var>x</var> axis, from 0 inclusive to {@link #nx} exclusive.
+         * @param gridY  The grid index along the <var>y</var> axis, from 0 inclusive to {@link #ny} exclusive.
+         * @return The offset at the given dimension in the grid cell at the given index.
+         */
+        @Override
+        protected final double getCellValue(final int dim, final int gridX, final int gridY) {
+            return offsets[dim][gridX + gridY*nx];
+        }
+    }
+}

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

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridFile.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/FranceGeocentricInterpolation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java?rev=1715198&r1=1715197&r2=1715198&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java [UTF-8] Thu Nov 19 15:37:28 2015
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.internal.referencing.provider;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Locale;
 import java.util.NoSuchElementException;
@@ -46,15 +45,15 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.parameter.ParameterBuilder;
 import org.apache.sis.parameter.Parameters;
 import org.apache.sis.util.CharSequences;
-import org.apache.sis.util.Workaround;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.collection.WeakValueHashMap;
+import org.apache.sis.util.collection.Cache;
 import org.apache.sis.referencing.CommonCRS;
-import org.apache.sis.referencing.datum.DatumShiftGrid;
 import org.apache.sis.referencing.datum.DefaultEllipsoid;
 import org.apache.sis.referencing.operation.transform.InterpolatedGeocentricTransform;
 
+import static java.lang.Float.parseFloat;
+
 
 /**
  * The provider for <cite>"France geocentric interpolation"</cite> (ESPG:9655).
@@ -78,6 +77,11 @@ public final class FranceGeocentricInter
     private static final long serialVersionUID = -4707304160205218546L;
 
     /**
+     * The keyword expected at the beginning of every lines in the header.
+     */
+    private static final String HEADER = "GR3D";
+
+    /**
      * The operation parameter descriptor for the <cite>Geocentric translations file</cite> parameter value.
      */
     public static final ParameterDescriptor<Path> FILE;
@@ -187,238 +191,180 @@ public final class FranceGeocentricInter
             case 3:  withHeights = true; break;
             default: throw new InvalidParameterValueException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "dim", dim), "dim", dim);
         }
-        final Grid grid = Grid.load(pg.getValue(FILE));
+        /*
+         * Array contains average translation parameters from source (RGF93) to target (NTF).
+         * The numerical values are given by operation EPSG:1651, but SIS implementation
+         * uses the opposite signs (because we reverse the direction of the operation).
+         */
+        final DatumShiftGridFile grid = getOrLoad(pg.getValue(FILE), new double[] {168, 60, -320}, 0.001);
         return InterpolatedGeocentricTransform.createGeodeticTransformation(factory,
-                createEllipsoid(pg, Molodensky.TGT_SEMI_MAJOR, Molodensky.TGT_SEMI_MINOR, CommonCRS.ETRS89.ellipsoid()), withHeights, // GRS 1980 ellipsoid
-                createEllipsoid(pg, Molodensky.SRC_SEMI_MAJOR, Molodensky.SRC_SEMI_MINOR, null), withHeights,                         // Clarke 1880 (IGN) ellipsoid
+                createEllipsoid(pg, Molodensky.TGT_SEMI_MAJOR,
+                                    Molodensky.TGT_SEMI_MINOR, CommonCRS.ETRS89.ellipsoid()), withHeights, // GRS 1980 ellipsoid
+                createEllipsoid(pg, Molodensky.SRC_SEMI_MAJOR,
+                                    Molodensky.SRC_SEMI_MINOR, null), withHeights,  // Clarke 1880 (IGN) ellipsoid
                 grid);  // TODO: invert
     }
 
     /**
-     * RGF93 datum shift 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  averages  An "average" value for the offset in each dimension, or {@code null} if unknown.
+     * @param  scale     The factor by which to multiply each compressed value before to add to the average value.
      */
-    public static final class Grid extends DatumShiftGrid {
-        /**
-         * Serial number for inter-operability with different versions.
-         */
-        private static final long serialVersionUID = 2151790417501356919L;
-
-        /**
-         * Cache of the grids loaded so far. This cache will usually contains only one element:
-         * the grid for the {@code "GR3DF97A.txt"} file.
-         */
-        private static final WeakValueHashMap<Path,Grid> CACHE = new WeakValueHashMap<>(Path.class);
-
-        /**
-         * The keyword expected at the beginning of every lines in the header.
-         */
-        private static final String HEADER = "GR3D";
-
-        /**
-         * Returns the grid of the given name. This method returns the cached instance if it still exists,
-         * or reload the grid otherwise.
-         */
-        static Grid load(final Path file) throws FactoryException {
-            synchronized (CACHE) {
-                Grid grid = CACHE.get(file);
+    static DatumShiftGridFile getOrLoad(final Path file, final double[] averages, final double scale)
+            throws FactoryException
+    {
+        DatumShiftGridFile grid = DatumShiftGridFile.CACHE.peek(file);
+        if (grid == null) {
+            final Cache.Handler<DatumShiftGridFile> handler = DatumShiftGridFile.CACHE.lock(file);
+            try {
+                grid = handler.peek();
                 if (grid == null) {
                     try (final BufferedReader in = Files.newBufferedReader(file)) {
-                        grid = new Grid(readHeader(in, file));
-                        grid.load(in, file);
+                        final DatumShiftGridFile.Float g = load(in, file);
+                        grid = DatumShiftGridCompressed.compress(g, averages, scale);
                     } catch (IOException | RuntimeException e) {
                         // NumberFormatException, ArithmeticException, NoSuchElementException, possibly other.
                         throw new FactoryException(Errors.format(Errors.Keys.CanNotParseFile_2, HEADER, file), e);
                     }
                 }
-                CACHE.put(file, grid);
-                return grid;
+            } finally {
+                handler.putAndUnlock(grid);
             }
         }
+        return grid;
+    }
 
-        /**
-         * Geocentric translations among <var>X</var>, <var>Y</var>, <var>Z</var> axes.
-         */
-        private final float[][] offsets;
-
-        /**
-         * Creates an initially empty grid geometry.
-         *
-         * @param gridGeometry The value returned by {@link #readHeader(BufferedReader, Path)}.
-         */
-        private Grid(final double[] gridGeometry) {
-            super(gridGeometry[0],  // x₀
-                  gridGeometry[2],  // y₀
-                  gridGeometry[4],  // Δx
-                  gridGeometry[5],  // Δy
-                  numCells(gridGeometry, 0),
-                  numCells(gridGeometry, 2));
-            final int size = Math.multiplyExact(nx, ny);
-            offsets = new float[3][];
-            for (int i=0; i<offsets.length; i++) {
-                Arrays.fill(offsets[i] = new float[size], Float.NaN);
-            }
-        }
-
-        /**
-         * Helper method for computing the {@link #nx} or {@link #ny} value.
-         *
-         * @param p 0 for computing {@code nx}, or 2 for computing {@code ny}.
-         */
-        private static int numCells(final double[] g, final int p) {
-            return Math.toIntExact(Math.round((g[p+1] - g[p]) / g[4+p/2] + 1));
-        }
-
-        /**
-         * Returns the value in the {@code GR3D1} line of the header.
+    /**
+     * Unconditionally loads the grid for the given file without in-memory compression.
+     *
+     * @param  in Reader of the RGF93 datum shift file.
+     * @param  file Path to the file being read, used only for error reporting.
+     * @throws IOException if an I/O error occurred.
+     * @throws NumberFormatException if a number can not be parsed.
+     * @throws NoSuchElementException if a data line is missing a value.
+     * @throws FactoryException if an problem is found with the file content.
+     * @throws ArithmeticException if the width or the height exceed the integer capacity.
+     */
+    static DatumShiftGridFile.Float load(final BufferedReader in, final Path file)
+            throws IOException, FactoryException
+    {
+        DatumShiftGridFile.Float grid = null;
+        double x0 = 0;
+        double xf = 0;
+        double y0 = 0;
+        double yf = 0;
+        double Δx = 0;
+        double Δy = 0;
+        int    nx = 0;
+        int    ny = 0;
+        /*
          * The header should be like below, but the only essential line for this class is the one
          * starting with "GR3D1". We also check that "GR3D2" declares the expected interpolation.
          *
-         * {@preformat text
          *     GR3D  002024 024 20370201
          *     GR3D1   -5.5000  10.0000  41.0000  52.0000    .1000    .1000
          *     GR3D2 INTERPOLATION BILINEAIRE
          *     GR3D3 PREC CM 01:5 02:10 03:20 04:50 99>100
-         * }
-         *
-         * @param  in Reader of the RGF93 datum shift file.
-         * @param  file Path to the file being read, used only for error reporting.
-         * @throws IOException if an I/O error occurred.
-         * @throws NumberFormatException if a number can not be parsed.
-         * @throws FactoryException if an problem is found with the file content.
          */
-        @Workaround(library="JDK", version="1.7")
-        private static double[] readHeader(final BufferedReader in, final Path file) throws IOException, FactoryException {
-            double[] gridGeometry = null;
-            String line;
-            while (true) {
-                in.mark(250);
-                line = in.readLine();
-                if (line == null) {
-                    throw new EOFException(Errors.format(Errors.Keys.UnexpectedEndOfFile_1, file));
-                }
-                final int length = CharSequences.skipTrailingWhitespaces(line, 0, line.length());
-                if (length <= 0) {
-                    continue;   // Skip empty lines.
-                }
-                int p = CharSequences.skipLeadingWhitespaces(line, 0, length);
-                if (line.charAt(p) == '#') {
-                    continue;   // Skip comment lines (not officially part of the format).
-                }
-                if (!line.regionMatches(true, p, HEADER, 0, HEADER.length())) {
-                    break;      // End of header.
-                }
-                if ((p += HEADER.length()) < length) {
-                    final char c = line.charAt(p);
-                    p = CharSequences.skipLeadingWhitespaces(line, p+1, length);
-                    switch (c) {
-                        case '1': {
-                            gridGeometry = CharSequences.parseDoubles(line.substring(p, length), ' ');
-                            break;
+        String line;
+        while (true) {
+            line = in.readLine();
+            if (line == null) {
+                throw new EOFException(Errors.format(Errors.Keys.UnexpectedEndOfFile_1, file));
+            }
+            final int length = CharSequences.skipTrailingWhitespaces(line, 0, line.length());
+            if (length <= 0) {
+                continue;   // Skip empty lines.
+            }
+            int p = CharSequences.skipLeadingWhitespaces(line, 0, length);
+            if (line.charAt(p) == '#') {
+                continue;   // Skip comment lines (not officially part of the format).
+            }
+            if (!line.regionMatches(true, p, HEADER, 0, HEADER.length())) {
+                break;      // End of header.
+            }
+            if ((p += HEADER.length()) < length) {
+                final char c = line.charAt(p);
+                p = CharSequences.skipLeadingWhitespaces(line, p+1, length);
+                switch (c) {
+                    case '1': {
+                        if (grid != null) {
+                            throw new FactoryException(Errors.format(Errors.Keys.DuplicatedElement_1, HEADER));
                         }
-                        case '2': {
-                            final String interp = line.substring(p, length);
-                            if (!interp.matches("(?i)INTERPOLATION[^A-Z]+BILINEAIRE")) {
-                                final LogRecord record = Errors.getResources((Locale) null).getLogRecord(
-                                        Level.WARNING, Errors.Keys.UnsupportedInterpolation_1, interp);
-                                record.setLoggerName(Loggers.COORDINATE_OPERATION);
-                                Logging.log(FranceGeocentricInterpolation.class, "createMathTransform", record);
-                                // We declare 'createMathTransform' method because it is closer to public API.
-                            }
-                            break;
+                        final double[] gridGeometry = CharSequences.parseDoubles(line.substring(p, length), ' ');
+                        if (gridGeometry.length == 6) {
+                            x0 = gridGeometry[0];
+                            xf = gridGeometry[1];
+                            y0 = gridGeometry[2];
+                            yf = gridGeometry[3];
+                            Δx = gridGeometry[4];
+                            Δy = gridGeometry[5];
+                            nx = Math.toIntExact(Math.round((xf - x0) / Δx + 1));
+                            ny = Math.toIntExact(Math.round((yf - y0) / Δy + 1));
+                            grid = new DatumShiftGridFile.Float(x0, y0, Δx, Δy, nx, ny, file, 3);
+                        }
+                        break;
+                    }
+                    case '2': {
+                        final String interp = line.substring(p, length);
+                        if (!interp.matches("(?i)INTERPOLATION[^A-Z]+BILINEAIRE")) {
+                            final LogRecord record = Errors.getResources((Locale) null).getLogRecord(
+                                    Level.WARNING, Errors.Keys.UnsupportedInterpolation_1, interp);
+                            record.setLoggerName(Loggers.COORDINATE_OPERATION);
+                            Logging.log(FranceGeocentricInterpolation.class, "createMathTransform", record);
+                            // We declare 'createMathTransform' method because it is closer to public API.
                         }
+                        break;
                     }
                 }
             }
-            if (gridGeometry == null || gridGeometry.length != 6) {
-                throw new FactoryException(Errors.format(Errors.Keys.CanNotParseFile_2, HEADER, file));
-            }
-            in.reset();
-            return gridGeometry;
         }
-
-        /**
-         * Loads the given file with the sign of all data reversed. Data columns are
+        if (grid == null) {
+            throw new FactoryException(Errors.format(Errors.Keys.CanNotParseFile_2, HEADER, file));
+        }
+        /*
+         * Loads the data with the sign of all offsets reversed. Data columns are
          *
          *     (unknown), longitude, latitude, tX, tY, tZ, accuracy code, data sheet (ignored)
          *
          * where the longitude and latitude values are in RGF93 system.
          * Example:
          *
-         * {@preformat text
          *     00002   -5.500000000   41.000000000  -165.027   -67.100   315.813  99  -0158
          *     00002   -5.500000000   41.100000000  -165.169   -66.948   316.007  99  -0157
          *     00002   -5.500000000   41.200000000  -165.312   -66.796   316.200  99  -0157
-         * }
          *
          * Translation values in the IGN file are from NTF to RGF93, but Apache SIS implementation needs
          * the opposite direction (from RGF93 to NTF). The reason is that SIS expect the source datum to
          * be the datum in which longitude and latitude values are expressed.
-         *
-         * @param  in Reader of the RGF93 datum shift file.
-         * @param  file Path to the file being read, used only for error reporting.
-         * @throws IOException if an I/O error occurred.
-         * @throws NumberFormatException if a number can not be parsed.
-         * @throws NoSuchElementException if a data line is missing a value.
-         * @throws FactoryException if an problem is found with the file content.
-         * @throws ArithmeticException if the width or the height exceed the integer capacity.
          */
-        private void load(final BufferedReader in, final Path file) throws IOException, FactoryException {
-            final float[] tX = offsets[0];
-            final float[] tY = offsets[1];
-            final float[] tZ = offsets[2];
-            String line;
-            while ((line = in.readLine()) != null) {
-                final StringTokenizer t = new StringTokenizer(line.trim());
-                t.nextToken();                                                    // Ignored
-                final double x = Double.parseDouble(t.nextToken());               // Longitude
-                final double y = Double.parseDouble(t.nextToken());               // Latitude
-                final int    i = Math.toIntExact(Math.round((x - x0) * scaleX));  // Column index
-                final int    j = Math.toIntExact(Math.round((y - y0) * scaleY));  // Row index
-                if (i < 0 || i >= nx) {
-                    throw new FactoryException(Errors.format(Errors.Keys.ValueOutOfRange_4, "x", x, x0, x0 + nx/scaleX));
-                }
-                if (j < 0 || j >= ny) {
-                    throw new FactoryException(Errors.format(Errors.Keys.ValueOutOfRange_4, "y", y, y0, y0 + ny/scaleY));
-                }
-                final int p = j*nx + i;
-                if (!Double.isNaN(tX[p]) || !Double.isNaN(tY[p]) || !Double.isNaN(tZ[p])) {
-                    throw new FactoryException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, x + ", " + y));
-                }
-                tX[p] = -Float.parseFloat(t.nextToken());  // See javadoc for the reason why we reverse the sign.
-                tY[p] = -Float.parseFloat(t.nextToken());
-                tZ[p] = -Float.parseFloat(t.nextToken());
+        final float[] tX = grid.offsets[0];
+        final float[] tY = grid.offsets[1];
+        final float[] tZ = grid.offsets[2];
+        do {
+            final StringTokenizer t = new StringTokenizer(line.trim());
+            t.nextToken();                                                // Ignored
+            final double x = Double.parseDouble(t.nextToken());           // Longitude
+            final double y = Double.parseDouble(t.nextToken());           // Latitude
+            final int    i = Math.toIntExact(Math.round((x - x0) / Δx));  // Column index
+            final int    j = Math.toIntExact(Math.round((y - y0) / Δy));  // Row index
+            if (i < 0 || i >= nx) {
+                throw new FactoryException(Errors.format(Errors.Keys.ValueOutOfRange_4, "x", x, x0, xf));
             }
-        }
-
-        /**
-         * Returns the average translation parameters from source (RGF93) to target (NTF).
-         * The numerical values are given by operation EPSG:1651, but SIS implementation
-         * uses the opposite signs (because we reverse the direction of the operation).
-         *
-         * @param dim The dimension for which to get an average value. Can be only 0, 1 or 2.
-         * @return A value close to the average for the given dimension.
-         */
-        @Override
-        public double getAverageOffset(final int dim) {
-            switch (dim) {
-                case 0: return  168;        // Sign reversed (see above).
-                case 1: return   60;
-                case 2: return -320;
-                default: throw new IllegalArgumentException();
+            if (j < 0 || j >= ny) {
+                throw new FactoryException(Errors.format(Errors.Keys.ValueOutOfRange_4, "y", y, y0, yf));
             }
-        }
-
-        /**
-         * Returns the cell value at the given dimension and grid index.
-         *
-         * @param dim    The dimension for which to get an average value. Can be only 0, 1 or 2.
-         * @param gridX  The grid index along the <var>x</var> axis, from 0 inclusive to {@link #nx} exclusive.
-         * @param gridY  The grid index along the <var>y</var> axis, from 0 inclusive to {@link #ny} exclusive.
-         * @return The offset at the given dimension in the grid cell at the given index.
-         */
-        @Override
-        protected double getCellValue(final int dim, final int gridX, final int gridY) {
-            return offsets[dim][gridX + gridY*nx];
-        }
+            final int p = j*nx + i;
+            if (!Double.isNaN(tX[p]) || !Double.isNaN(tY[p]) || !Double.isNaN(tZ[p])) {
+                throw new FactoryException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, x + ", " + y));
+            }
+            tX[p] = -parseFloat(t.nextToken());  // See javadoc for the reason why we reverse the sign.
+            tY[p] = -parseFloat(t.nextToken());
+            tZ[p] = -parseFloat(t.nextToken());
+        } while ((line = in.readLine()) != null);
+        return grid;
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java?rev=1715198&r1=1715197&r2=1715198&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java [UTF-8] Thu Nov 19 15:37:28 2015
@@ -20,7 +20,6 @@ import java.io.Serializable;
 import org.opengis.geometry.Envelope;
 import org.apache.sis.geometry.Envelope2D;
 import org.apache.sis.internal.util.DoubleDouble;
-import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.ArgumentChecks;
 
 
@@ -42,16 +41,16 @@ import org.apache.sis.util.ArgumentCheck
  * {@link org.apache.sis.referencing.operation.transform.InterpolatedGeocentricTransform} implementation.
  * <ul>
  *   <li><p><b>Datum shift by geographic translations</b><br>
- *   For datum shifts using NADCON or NTv2 grids, the (<var>x</var>,<var>y</var>) arguments are longitude (λ)
- *   and latitude (φ) in angular <em>degrees</em> and the translations are (<var>Δλ</var>, <var>Δφ</var>)
- *   offsets in angular <em>seconds</em>, converted to degrees for Apache SIS needs. Those offsets will be
- *   added or subtracted by {@link org.apache.sis.referencing.operation.transform.InterpolatedTransform}
+ *   NADCON and NTv2 grids are defined with longitude (λ) and latitude (φ) inputs in angular <em>degrees</em>
+ *   and give (<var>Δλ</var>, <var>Δφ</var>) translations in angular <em>seconds</em>.
+ *   However Apache SIS needs all those values to be converted to <strong>radians</strong>.
+ *   The translations will be applied by {@link org.apache.sis.referencing.operation.transform.InterpolatedTransform}
  *   directly on the given (<var>λ</var>,<var>φ</var>) coordinates.
  *   </p></li>
  *
  *   <li><p><b>Datum shift by geocentric translations</b><br>
- *   For datum shifts in France, the (<var>x</var>,<var>y</var>) arguments are longitude and latitude in angular degrees
- *   but the translations are (<var>ΔX</var>, <var>ΔY</var>, <var>ΔZ</var>) geocentric offsets in <em>metres</em>.
+ *   France interpolation grid is defined with longitude (λ) and latitude (φ) inputs in angular <em>degrees</em>
+ *   and gives (<var>ΔX</var>, <var>ΔY</var>, <var>ΔZ</var>) geocentric translations in <em>metres</em>.
  *   Those offsets will not be added directly to the given (<var>λ</var>,<var>φ</var>) coordinates since there is
  *   a geographic/geocentric conversion in the middle
  *   (see {@link org.apache.sis.referencing.operation.transform.InterpolatedGeocentricTransform}).
@@ -83,6 +82,9 @@ public abstract class DatumShiftGrid imp
 
     /**
      * Coordinate of the center of the cell at grid index (0,0).
+     * This is usually a geographic coordinate (<var>λ₀</var>,<var>φ₀</var>) in <strong>radians</strong>,
+     * but other usages are allowed for users who instantiate
+     * {@link org.apache.sis.referencing.operation.transform.InterpolatedTransform} themselves.
      * The (<var>x₀</var>, <var>y₀</var>) coordinate is often the minimal (<var>x</var>,<var>y</var>) value
      * of the grid, but not necessarily if the <var>Δx</var> or <var>Δy</var> increments are negative.
      */
@@ -105,10 +107,11 @@ public abstract class DatumShiftGrid imp
     protected final int nx, ny;
 
     /**
-     * Creates a new grid.
+     * Creates a new datum shift grid for the given grid geometry.
+     * The actual offset values need to be provided by subclasses.
      *
-     * @param x0  First ordinate (often longitude) of the center of the cell at grid index (0,0).
-     * @param y0  Second ordinate (often latitude) of the center of the cell at grid index (0,0).
+     * @param x0  First ordinate (often longitude in radians) of the center of the cell at grid index (0,0).
+     * @param y0  Second ordinate (often latitude in radians) of the center of the cell at grid index (0,0).
      * @param Δx  Increment in <var>x</var> value between cells at index <var>gridX</var> and <var>gridX</var> + 1.
      * @param Δy  Increment in <var>y</var> value between cells at index <var>gridY</var> and <var>gridY</var> + 1.
      * @param nx  Number of cells along the <var>x</var> axis in the grid.
@@ -124,26 +127,40 @@ public abstract class DatumShiftGrid imp
         this.ny = ny;
         ArgumentChecks.ensureStrictlyPositive("nx", nx);
         ArgumentChecks.ensureStrictlyPositive("ny", ny);
-        /*
-         * The intend of DoubleDouble arithmetic here is to avoid rounding errors on the assumption that
-         * the Δx and Δy values are defined in base 10 in the grid. For example 1 / 1E-5 gives 99999.9…,
-         * while DoubleDouble below gives the expected result.  Since we use Math.floor(double) for grid
-         * indices computation, the difference is significant.
-         */
-        final DoubleDouble dd = new DoubleDouble(Δx);
-        dd.inverseDivide(1, 0);
-        scaleX = dd.value;
-        dd.value = Δy;
-        dd.error = DoubleDouble.errorForWellKnownValue(Δy);
-        dd.inverseDivide(1, 0);
-        scaleY = dd.value;
+        scaleX = 1 / Δx;
+        scaleY = 1 / Δy;
     }
 
     /**
-     * Returns the domain of validity of the (<var>x</var>,<var>y</var>) coordinates that can be specified to the
-     * {@link #offsetAt(double, double, double[])} method. Coordinates outside that domain of validity will still
+     * Creates a new datum shift grid with the same grid geometry than the given grid.
+     *
+     * @param other The other datum shift grid from which to copy the grid geometry.
+     */
+    protected DatumShiftGrid(final DatumShiftGrid other) {
+        x0 = other.x0;
+        y0 = other.y0;
+        nx = other.nx;
+        ny = other.ny;
+        scaleX = other.scaleX;
+        scaleY = other.scaleY;
+    }
+
+    /**
+     * Returns the number of dimensions of the translation vectors interpolated by this datum shift grid.
+     * The number of dimension is usually 2 or 3, but other values are allowed.
+     *
+     * @return Number of dimensions of translation vectors.
+     */
+    public abstract int getShiftDimensions();
+
+    /**
+     * Returns the domain of validity of the (<var>x</var>,<var>y</var>) coordinate values that can be specified
+     * to the {@link #offsetAt offsetAt(x, y, …)} method. Coordinates outside that domain of validity will still
      * be accepted, but the result of offset computation may be very wrong.
      *
+     * <p>In the datum shift grids used by {@link org.apache.sis.referencing.operation.transform.InterpolatedTransform},
+     * the domain of validity is longitude and latitude in <strong>radians</strong>.</p>
+     *
      * @return The domain covered by this grid.
      */
     public Envelope getDomainOfValidity() {
@@ -160,55 +177,63 @@ public abstract class DatumShiftGrid imp
     }
 
     /**
-     * Returns an average offset value for the given dimension. The default implementation computes the average of all
-     * values returned by {@link #getCellValue getCellValue(…)}, but subclasses may override with more specific values.
+     * Returns an average offset value for the given dimension.
+     * Those average values shall provide a good "first guess" before to interpolate the actual offset value
+     * at the (<var>x</var>,<var>y</var>) coordinate. This "first guess" is needed for inverse transform.
+     *
+     * <div class="section">Default implementation</div>
+     * The default implementation computes the average of all values returned by
+     * {@link #getCellValue getCellValue(dim, …)}, but subclasses may override with more specific values.
      *
      * <div class="note"><b>Example:</b>
-     * The <cite>"France geocentric interpolation"</cite> (ESPG:9655) fixes those "average" values to -168, -60
-     * and +320 metres for dimensions 0 (geocentric X), 1 (geocentric Y) and 2 (geocentric Z) respectively.</div>
+     * In the <cite>"France geocentric interpolation"</cite> (ESPG:9655) operation method, those "average" values
+     * are fixed by definition to -168, -60 and +320 metres for dimensions 0, 1 and 2 respectively
+     * (geocentric <var>X</var>, <var>Y</var> and <var>Z</var>).</div>
      *
-     * @param dim The dimension for which to get an average value.
+     * @param dim  The dimension for which to get an average value,
+     *             from 0 inclusive to {@link #getShiftDimensions()} exclusive.
      * @return A value close to the average for the given dimension.
      */
     public double getAverageOffset(final int dim) {
-        double sum = 0;
+        final DoubleDouble sum = new DoubleDouble();
         for (int gridY=0; gridY<ny; gridY++) {
             for (int gridX=0; gridX<nx; gridX++) {
-                sum += getCellValue(dim, gridX, gridY);
+                sum.add(getCellValue(dim, gridX, gridY));
             }
         }
-        return sum / (nx * ny);
+        return sum.value / (nx * ny);
     }
 
     /**
-     * Interpolates the translation to apply for the given coordinate.
-     * This method usually returns an array of length 2 or 3, but it could be of any length
-     * (provided that this length never change). The values in the returned array are often
-     * for the same dimensions than <var>x</var> and <var>y</var>, but not necessarily.
+     * Interpolates the translation to apply for the given coordinate. The result is stored in the
+     * given {@code offsets} array, which shall have a length of at least {@link #getShiftDimensions()}.
+     * The computed translation values are often for the same dimensions than the given <var>x</var> and <var>y</var>
+     * values, but not necessarily.
      * See the class javadoc for use cases.
      *
      * <div class="section">Default implementation</div>
      * The default implementation performs the following steps for each dimension {@code dim},
-     * where the number of dimension is determined by the length of the {@code offsets} array:
+     * where the number of dimension is determined by {@link #getShiftDimensions()}.
      * <ol>
      *   <li>Convert the given (<var>x</var>,<var>y</var>) coordinate into grid coordinate
      *       using the formula documented in {@link #scaleX} and {@link #scaleY} fields.</li>
      *   <li>Clamp the grid coordinate into the [0 … {@link #nx} - 2] and [0 … {@link #ny} - 2] ranges, inclusive.</li>
      *   <li>Using {@link #getCellValue(int, int, int)}, get the four cell values around the coordinate.</li>
-     *   <li>Apply a bilinear interpolation and store the result in {@code offset[dim]}.</li>
+     *   <li>Apply a bilinear interpolation and store the result in {@code offsets[dim]}.</li>
      * </ol>
      *
-     * @param x       First ordinate (often longitude, but not necessarily) of the point for which to get the offset.
-     * @param y       Second ordinate (often latitude, but not necessarily) of the point for which to get the offset.
-     * @param offset  A pre-allocated array where to write the offset vector.
+     * @param x        First ordinate (often longitude, but not necessarily) of the point for which to get the offset.
+     * @param y        Second ordinate (often latitude, but not necessarily) of the point for which to get the offset.
+     * @param offsets  A pre-allocated array where to write the translation vector.
      */
-    public void offsetAt(double x, double y, double[] offset) {
+    public void offsetAt(double x, double y, double[] offsets) {
         final int gridX = Math.max(0, Math.min(nx - 2, (int) Math.floor(x = (x - x0) * scaleX)));
         final int gridY = Math.max(0, Math.min(ny - 2, (int) Math.floor(y = (y - y0) * scaleY)));
         x -= gridX;
         y -= gridY;
-        for (int dim=0; dim<offset.length; dim++) {
-            offset[dim] = (1-y) * ((1-x) * getCellValue(dim, gridX, gridY  ) + x*getCellValue(dim, gridX+1, gridY  ))
+        final int n = getShiftDimensions();
+        for (int dim = 0; dim < n; dim++) {
+            offsets[dim] = (1-y) * ((1-x) * getCellValue(dim, gridX, gridY  ) + x*getCellValue(dim, gridX+1, gridY  ))
                            + y  * ((1-x) * getCellValue(dim, gridX, gridY+1) + x*getCellValue(dim, gridX+1, gridY+1));
         }
     }
@@ -216,43 +241,11 @@ public abstract class DatumShiftGrid imp
     /**
      * Returns the offset stored at the given grid indices along the given dimension.
      *
-     * @param dim    The dimension of the offset component to get.
+     * @param dim    The dimension of the offset component to get,
+     *               from 0 inclusive to {@link #getShiftDimensions()} exclusive.
      * @param gridX  The grid index along the <var>x</var> axis, from 0 inclusive to {@link #nx} exclusive.
      * @param gridY  The grid index along the <var>y</var> axis, from 0 inclusive to {@link #ny} exclusive.
      * @return The offset at the given dimension in the grid cell at the given index.
      */
     protected abstract double getCellValue(int dim, int gridX, int gridY);
-
-    /**
-     * Returns {@code true} if the given grid contains the same data than this grid.
-     *
-     * @param  other The other object to compare with this datum shift grid.
-     * @return {@code true} if the given object is non-null, of the same class than this {@code DatumShiftGrid}
-     *         and contains the same data.
-     */
-    @Override
-    public boolean equals(final Object other) {
-        if (other != null && other.getClass() == getClass()) {
-            final DatumShiftGrid that = (DatumShiftGrid) other;
-            return nx == that.nx
-                && ny == that.ny
-                && Numerics.equals(x0,     that.x0)
-                && Numerics.equals(y0,     that.y0)
-                && Numerics.equals(scaleX, that.scaleX)
-                && Numerics.equals(scaleY, that.scaleY);
-        }
-        return false;
-    }
-
-    /**
-     * Returns a hash code value for this datum shift grid.
-     */
-    @Override
-    public int hashCode() {
-        return Numerics.hashCode(
-                 Double.doubleToLongBits(x0) + 31*
-                (Double.doubleToLongBits(y0) + 31*
-                (Double.doubleToLongBits(scaleX) + 31*
-                 Double.doubleToLongBits(scaleY))));
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedGeocentricTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedGeocentricTransform.java?rev=1715198&r1=1715197&r2=1715198&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedGeocentricTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedGeocentricTransform.java [UTF-8] Thu Nov 19 15:37:28 2015
@@ -25,6 +25,7 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.internal.referencing.provider.DatumShiftGridFile;
 import org.apache.sis.internal.referencing.provider.FranceGeocentricInterpolation;
 import org.apache.sis.internal.referencing.provider.GeocentricAffineBetweenGeographic;
 import org.apache.sis.internal.referencing.provider.Molodensky;
@@ -197,7 +198,7 @@ public class InterpolatedGeocentricTrans
      * Otherwise a more neutral (but non-standard) descriptor is returned.
      */
     private static ParameterDescriptorGroup descriptor(final DatumShiftGrid grid) {
-        if (grid instanceof FranceGeocentricInterpolation.Grid) {
+        if (grid instanceof DatumShiftGridFile) {
             return FranceGeocentricInterpolation.PARAMETERS;        // Defined by EPSG.
         }
         synchronized (InterpolatedGeocentricTransform.class) {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java?rev=1715198&r1=1715197&r2=1715198&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java [UTF-8] Thu Nov 19 15:37:28 2015
@@ -87,7 +87,8 @@ public final strictfp class FranceGeocen
     public void testGrid() throws URISyntaxException, IOException, FactoryException {
         final URL file = FranceGeocentricInterpolationTest.class.getResource("GR3DF97A.txt");
         assertNotNull("Test file \"GR3DF97A.txt\" not found.", file);
-        final FranceGeocentricInterpolation.Grid grid = FranceGeocentricInterpolation.Grid.load(Paths.get(file.toURI()));
+        final DatumShiftGridFile grid = FranceGeocentricInterpolation.getOrLoad(
+                Paths.get(file.toURI()), new double[] {168, 60, -320}, 0.001);
         /*
          * Verify envelope.
          */