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 2019/01/26 17:18:54 UTC

[sis] branch geoapi-4.0 updated (8e12681 -> 6c47bc2)

This is an automated email from the ASF dual-hosted git repository.

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


    from 8e12681  Bug fix: two-dimensional localization grids in some netCDF files were wrongly detected as simplifiable to orthogonal vectors.
     new c1138c1  Replace some "ordinate" words by "coordinate". We will need to perform this replacement for the whole project some day.
     new 0768f1f  The check for source dimension order needs to be robust to the case where the localization grid in a netCDF call contains longitude values crossing the +180/-180° meridian.
     new 341dc1f  Move a method in a location providing better encapsulation.
     new 6c47bc2  Move more methods in order to improve a bit the encapsulation.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../operation/builder/LinearTransformBuilder.java  |  38 ++---
 .../operation/builder/LocalizationGridBuilder.java |   4 +-
 .../java/org/apache/sis/internal/netcdf/Axis.java  | 172 +++++++++++++++------
 .../java/org/apache/sis/internal/netcdf/Grid.java  | 108 ++++++-------
 .../org/apache/sis/internal/netcdf/Variable.java   |  15 ++
 .../apache/sis/internal/netcdf/impl/GridInfo.java  |  23 +--
 .../sis/internal/netcdf/impl/VariableInfo.java     |  12 ++
 .../sis/internal/netcdf/ucar/GridWrapper.java      |  21 +--
 .../sis/internal/netcdf/ucar/VariableWrapper.java  |  12 +-
 .../apache/sis/storage/netcdf/MetadataReader.java  |   4 +-
 10 files changed, 239 insertions(+), 170 deletions(-)


[sis] 04/04: Move more methods in order to improve a bit the encapsulation.

Posted by de...@apache.org.
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

commit 6c47bc29fda3476be5cd0f0c7ef2856e50bd4c59
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Jan 26 17:22:12 2019 +0100

    Move more methods in order to improve a bit the encapsulation.
---
 .../java/org/apache/sis/internal/netcdf/Axis.java  | 113 ++++++++++++++++++++-
 .../java/org/apache/sis/internal/netcdf/Grid.java  |  94 ++++-------------
 .../apache/sis/storage/netcdf/MetadataReader.java  |   4 +-
 3 files changed, 133 insertions(+), 78 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index 5736831..d015017 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -38,10 +38,12 @@ import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.iso.Types;
+import org.apache.sis.util.ArraysExt;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Units;
 import org.apache.sis.math.Vector;
+import org.apache.sis.referencing.operation.builder.LocalizationGridBuilder;
 import ucar.nc2.constants.CDM;
 import ucar.nc2.constants.CF;
 
@@ -115,7 +117,7 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
      * equals to the {@link #sourceDimensions} length. For each element, {@code sourceSizes[i]} shall
      * be equals to the number of grid cells in the grid dimension at index {@code sourceDimensions[i]}.
      */
-    public final int[] sourceSizes;
+    final int[] sourceSizes;
 
     /**
      * Values of coordinates on this axis for given grid indices. This variables is often one-dimensional,
@@ -204,6 +206,71 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
     }
 
     /**
+     * Swaps the two first source dimensions if needed for making the fastest varying dimension first.
+     * This is a helper method for {@link Grid#getAxes()} invoked after all axes of a grid have been created.
+     * This method needs to know other axes in order to avoid collision.
+     *
+     * @param  axes   previously created axes.
+     * @param  count  number of elements to consider in the {@code axes} array.
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
+     *
+     * @see #getDimension()
+     */
+    final void mainDimensionFirst(final Axis[] axes, final int count) throws IOException, DataStoreException {
+        final int d0 = sourceDimensions[0];
+        final int d1 = sourceDimensions[1];
+        boolean s = false;
+        for (int i=0; i<count; i++) {
+            final int[] other = axes[i].sourceDimensions;
+            if (other.length != 0) {
+                final int first = other[0];
+                if  (first == d1) return;          // Swapping would cause a collision.
+                s = (first == d0);
+                if (s) break;                      // Need swapping for avoiding collision.
+            }
+        }
+        if (!s) {
+            final int up0  = sourceSizes[0];
+            final int up1  = sourceSizes[1];
+            final int mid0 = up0 / 2;
+            final int mid1 = up1 / 2;
+            final double inc0 = (coordinates.coordinateForAxis(    0, mid1) -
+                                 coordinates.coordinateForAxis(up0-1, mid1)) / up0;
+            final double inc1 = (coordinates.coordinateForAxis(mid0,     0) -
+                                 coordinates.coordinateForAxis(mid0, up1-1)) / up1;
+            if (!(Math.abs(inc1) > Math.abs(inc0))) {
+                return;
+            }
+        }
+        ArraysExt.swap(sourceSizes,      0, 1);
+        ArraysExt.swap(sourceDimensions, 0, 1);
+    }
+
+    /**
+     * Returns the number of dimension of the localization grid used by this axis.
+     * This method returns 2 if this axis if backed by a localization grid having 2 or more dimensions.
+     * In the netCDF UCAR library, such axes are handled by a {@link ucar.nc2.dataset.CoordinateAxis2D}.
+     *
+     * @return number of dimension of the localization grid used by this axis.
+     */
+    public final int getDimension() {
+        return sourceDimensions.length;
+    }
+
+    /**
+     * Returns the number of cells in the first dimension of the localization grid used by this axis.
+     * If the localization grid has more than one dimension ({@link #getDimension()} {@literal > 1}),
+     * then all additional dimensions are ignored. The first dimension should be the main one.
+     *
+     * @return number of cells in the first (main) dimension of the localization grid.
+     */
+    public final int getLength() {
+        return (sourceSizes.length != 0) ? sourceSizes[0] : 0;
+    }
+
+    /**
      * Returns the name of this axis.
      *
      * @return the name of this element.
@@ -381,7 +448,7 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
     final boolean trySetTransform(final Matrix gridToCRS, final int lastSrcDim, final int tgtDim,
             final List<MathTransform> nonLinears) throws IOException, DataStoreException
     {
-main:   switch (sourceDimensions.length) {
+main:   switch (getDimension()) {
             /*
              * Defined as a matter of principle, but should never happen.
              */
@@ -456,4 +523,46 @@ main:   switch (sourceDimensions.length) {
         nonLinears.add(null);
         return false;
     }
+
+    /**
+     * Tries to create a two-dimensional localization grid using this axis and the given axis.
+     * This method is invoked as a fallback when {@link #trySetTransform(Matrix, int, int, List)}
+     * could not set coefficients in the matrix of an affine transform.
+     *
+     * @param  other  the other axis to use for creating a localization grid.
+     * @return the localization grid, or {@code null} if none can be built.
+     * @throws IOException if an error occurred while reading the data.
+     * @throws DataStoreException if a logical error occurred.
+     */
+    final LocalizationGridBuilder createLocalizationGrid(final Axis other) throws IOException, DataStoreException {
+        if (other.getDimension() == 2) {
+            final int d1 =       sourceDimensions[0];
+            final int d2 =       sourceDimensions[1];
+            final int o1 = other.sourceDimensions[0];
+            final int o2 = other.sourceDimensions[1];
+            if ((o1 == d1 && o2 == d2) || (o1 == d2 && o2 == d1)) {
+                /*
+                 * Found two axes for the same set of dimensions, which implies that they have
+                 * the same shape (width and height).
+                 */
+                final int width  = sourceSizes[0];
+                final int height = sourceSizes[1];
+                final LocalizationGridBuilder grid = new LocalizationGridBuilder(width, height);
+                final Vector v1 =       coordinates.read();
+                final Vector v2 = other.coordinates.read();
+                final double[] target = new double[2];
+                int index = 0;
+                for (int y=0; y<height; y++) {
+                    for (int x=0; x<width; x++) {
+                        target[0] = v1.doubleValue(index);
+                        target[1] = v2.doubleValue(index);
+                        grid.setControlPoint(x, y, target);
+                        index++;
+                    }
+                }
+                return grid;
+            }
+        }
+        return null;
+    }
 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index 3c8f52f..49ce6b7 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -40,8 +40,6 @@ import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.coverage.grid.IllegalGridGeometryException;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.NullArgumentException;
-import org.apache.sis.util.ArraysExt;
-import org.apache.sis.math.Vector;
 
 
 /**
@@ -159,12 +157,11 @@ public abstract class Grid extends NamedElement {
             int i = 0, deferred = workspace.length;
             for (final Axis axis : axes) {
                 // Put one-dimensional axes first, all other axes last.
-                workspace[axis.sourceDimensions.length <= 1 ? i++ : --deferred] = axis;
+                workspace[axis.getDimension() <= 1 ? i++ : --deferred] = axis;
             }
             deferred = workspace.length;        // Will become index of the first axis whose examination has been deferred.
             while (i < workspace.length) {      // Start the loop at the first n-dimensional axis (n > 1).
                 final Axis axis = workspace[i];
-                final int[] sourceDimensions = axis.sourceDimensions;
                 /*
                  * If an axis has a "wraparound" range (for example a longitude axis where the next value after +180°
                  * may be -180°), we will examine it last. The reason is that if a wraparound occurs in the middle of
@@ -175,35 +172,10 @@ public abstract class Grid extends NamedElement {
                 if (i < deferred && axis.isWraparound()) {
                     System.arraycopy(workspace, i+1, workspace, i, --deferred - i);
                     workspace[deferred] = axis;
-                    continue;                                           // Continue the loop without incrementing 'i'.
-                }
-                Boolean swap = null;
-                for (int p=0; p<i; p++) {
-                    final int[] other = workspace[p].sourceDimensions;
-                    if (other.length != 0) {
-                        final int first = other[0];
-                        if (first == sourceDimensions[1]) {swap=false; break;}    // Swapping would cause a collision.
-                        if (first == sourceDimensions[0]) {swap=true;  break;}    // Need swapping for avoiding collision.
-                    }
-                }
-                final int[] sourceSizes = axis.sourceSizes;
-                if (swap == null) {
-                    final int up0  = sourceSizes[0];
-                    final int up1  = sourceSizes[1];
-                    final int mid0 = up0 / 2;
-                    final int mid1 = up1 / 2;
-                    final Variable coordinates = axis.coordinates;
-                    final double inc0 = (coordinates.coordinateForAxis(    0, mid1) -
-                                         coordinates.coordinateForAxis(up0-1, mid1)) / up0;
-                    final double inc1 = (coordinates.coordinateForAxis(mid0,     0) -
-                                         coordinates.coordinateForAxis(mid0, up1-1)) / up1;
-                    swap = Math.abs(inc1) > Math.abs(inc0);
-                }
-                if (swap) {
-                    ArraysExt.swap(sourceSizes,      0, 1);
-                    ArraysExt.swap(sourceDimensions, 0, 1);
+                } else {
+                    axis.mainDimensionFirst(workspace, i);
+                    i++;
                 }
-                i++;
             }
         }
         return axes;
@@ -269,7 +241,7 @@ public abstract class Grid extends NamedElement {
             case 0:  break;
         }
         for (final Axis axis : axes) {
-            if (axis.sourceDimensions.length == 1) {
+            if (axis.getDimension() == 1) {
                 final DimensionNameType name;
                 if (AxisDirections.isVertical(axis.direction)) {
                     name = DimensionNameType.VERTICAL;
@@ -349,51 +321,25 @@ findFree:       for (int srcDim : axis.sourceDimensions) {
             for (int i=0; i<nonLinears.size(); i++) {         // Length of 'nonLinears' may change in this loop.
                 if (nonLinears.get(i) == null) {
                     final Axis axis = axes[deferred[i]];
-                    if (axis.sourceDimensions.length == 2) {
-                        final int d1 = axis.sourceDimensions[0];
-                        final int d2 = axis.sourceDimensions[1];
+                    if (axis.getDimension() == 2) {
                         for (int j=i; ++j < nonLinears.size();) {
                             if (nonLinears.get(j) == null) {
-                                final Axis other = axes[deferred[j]];
-                                if (other.sourceDimensions.length == 2) {
-                                    final int o1 = other.sourceDimensions[0];
-                                    final int o2 = other.sourceDimensions[1];
-                                    if ((o1 == d1 && o2 == d2) || (o1 == d2 && o2 == d1)) {
+                                final int srcDim   = sourceDimensions[i];
+                                final int otherDim = sourceDimensions[j];
+                                if (Math.abs(srcDim - otherDim) == 1) {     // Need axes at consecutive source dimensions.
+                                    final LocalizationGridBuilder grid = axis.createLocalizationGrid(axes[deferred[j]]);
+                                    if (grid != null) {
                                         /*
-                                         * Found two axes for the same set of dimensions, which implies that they have
-                                         * the same shape (width and height).  In current implementation, we also need
-                                         * those axes to be at consecutive source dimensions.
+                                         * Replace the first transform by the two-dimensional localization grid and
+                                         * remove the other transform. Removals need to be done in arrays too.
                                          */
-                                        final int srcDim   = sourceDimensions[i];
-                                        final int otherDim = sourceDimensions[j];
-                                        if (Math.abs(srcDim - otherDim) == 1) {
-                                            final int width  = axis.sourceSizes[0];
-                                            final int height = axis.sourceSizes[1];
-                                            final LocalizationGridBuilder grid = new LocalizationGridBuilder(width, height);
-                                            final Vector v1 =  axis.coordinates.read();
-                                            final Vector v2 = other.coordinates.read();
-                                            final double[] target = new double[2];
-                                            int index = 0;
-                                            for (int y=0; y<height; y++) {
-                                                for (int x=0; x<width; x++) {
-                                                    target[0] = v1.doubleValue(index);
-                                                    target[1] = v2.doubleValue(index);
-                                                    grid.setControlPoint(x, y, target);
-                                                    index++;
-                                                }
-                                            }
-                                            /*
-                                             * Replace the first transform by the two-dimensional localization grid and
-                                             * remove the other transform. Removals need to be done in arrays too.
-                                             */
-                                            nonLinears.set(i, grid.create(factory));
-                                            nonLinears.remove(j);
-                                            final int n = nonLinears.size() - j;
-                                            System.arraycopy(deferred,         j+1, deferred,         j, n);
-                                            System.arraycopy(sourceDimensions, j+1, sourceDimensions, j, n);
-                                            if (otherDim < srcDim) {
-                                                sourceDimensions[i] = otherDim;
-                                            }
+                                        nonLinears.set(i, grid.create(factory));
+                                        nonLinears.remove(j);
+                                        final int n = nonLinears.size() - j;
+                                        System.arraycopy(deferred,         j+1, deferred,         j, n);
+                                        System.arraycopy(sourceDimensions, j+1, sourceDimensions, j, n);
+                                        if (otherDim < srcDim) {
+                                            sourceDimensions[i] = otherDim;
                                         }
                                     }
                                 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index 950819f..2127810 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -724,8 +724,8 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
              * the 'sourceDimensions' and 'sourceSizes' arrays are for the grid dimension which is most closely
              * oriented toward the axis direction.
              */
-            if (axis.sourceSizes.length >= 1) {
-                setAxisLength(dim, axis.sourceSizes[0]);
+            if (axis.getDimension() >= 1) {
+                setAxisLength(dim, axis.getLength());
             }
             final AttributeNames.Dimension attributeNames;
             switch (axis.abbreviation) {


[sis] 02/04: The check for source dimension order needs to be robust to the case where the localization grid in a netCDF call contains longitude values crossing the +180/-180° meridian.

Posted by de...@apache.org.
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

commit 0768f1fe683416a49a47881e6ba94af40d6e86b6
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Jan 26 15:53:28 2019 +0100

    The check for source dimension order needs to be robust to the case where the localization grid in a netCDF call contains longitude values crossing the +180/-180° meridian.
---
 .../java/org/apache/sis/internal/netcdf/Axis.java  | 61 ++++++----------------
 .../java/org/apache/sis/internal/netcdf/Grid.java  | 60 +++++++++++++++++++--
 .../apache/sis/internal/netcdf/impl/GridInfo.java  |  8 ++-
 .../sis/internal/netcdf/ucar/GridWrapper.java      |  9 ++--
 4 files changed, 79 insertions(+), 59 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index 79cce0c..5736831 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -38,7 +38,6 @@ import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.iso.Types;
-import org.apache.sis.util.ArraysExt;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Units;
@@ -125,25 +124,17 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
     final Variable coordinates;
 
     /**
-     * Constructs a new axis associated to an arbitrary number of grid dimension.
-     * In the particular case where the number of dimensions is equals to 2, this constructor will detect
-     * by itself which grid dimension varies fastest and reorder in-place the elements in the given arrays
-     * (those array are modified, not cloned).
+     * Constructs a new axis associated to an arbitrary number of grid dimension. The given arrays are stored
+     * as-in (not cloned) and their content may be modified after construction by {@link Grid#getAxes()}.
      *
-     * @param  owner             provides callback for the conversion from grid coordinates to geodetic coordinates.
      * @param  axis              an implementation-dependent object representing the axis.
      * @param  abbreviation      axis abbreviation, also identifying its type. This is a controlled vocabulary.
      * @param  direction         direction of positive values ("up" or "down"), or {@code null} if unknown.
      * @param  sourceDimensions  the index of the grid dimension associated to this axis.
      * @param  sourceSizes       the number of cell elements along that axis.
-     * @param  previousAxes      other axes built before this axis. May contain null elements. This array will not be modified.
-     * @throws IOException if an I/O operation was necessary but failed.
-     * @throws DataStoreException if a logical error occurred.
-     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
      */
-    public Axis(final Grid owner, final Variable axis, char abbreviation, final String direction,
-                final int[] sourceDimensions, final int[] sourceSizes, final Axis[] previousAxes)
-            throws IOException, DataStoreException
+    public Axis(final Variable axis, char abbreviation, final String direction,
+                final int[] sourceDimensions, final int[] sourceSizes)
     {
         /*
          * Try to get the axis direction from one of the following sources,
@@ -190,38 +181,6 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
         this.sourceDimensions = sourceDimensions;
         this.sourceSizes      = sourceSizes;
         this.coordinates      = axis;
-        /*
-         * The grid dimension which varies fastest should be first.  The code below will swap axes if needed in order to
-         * achieve that goal, except if a previous axis was already using the same order. We avoid collision only in the
-         * first dimension because it is the one used by metadata and by trySetTransform(…).
-         */
-        if (sourceDimensions.length >= 2) {
-            boolean s = false;
-            for (final Axis previous : previousAxes) {
-                if (previous != null && previous.sourceDimensions.length != 0) {
-                    final int first = previous.sourceDimensions[0];
-                    if  (first == sourceDimensions[1]) return;              // Swapping would cause a collision. Avoid that.
-                    s = (first == sourceDimensions[0]);                     // Tell if need swapping for avoiding collision.
-                    if (s) break;
-                }
-            }
-            final int up0 = sourceSizes[0];
-            final int up1 = sourceSizes[1];
-            if (!s) {
-                final int mid0 = up0 / 2;
-                final int mid1 = up1 / 2;
-                final double inc0 = (owner.coordinateForAxis(axis,     0, mid1) -
-                                     owner.coordinateForAxis(axis, up0-1, mid1)) / up0;
-                final double inc1 = (owner.coordinateForAxis(axis, mid0,     0) -
-                                     owner.coordinateForAxis(axis, mid0, up1-1)) / up1;
-                s = Math.abs(inc1) > Math.abs(inc0);
-            }
-            if (s) {
-                sourceSizes[0] = up1;
-                sourceSizes[1] = up0;
-                ArraysExt.swap(sourceDimensions, 0, 1);
-            }
-        }
     }
 
     /**
@@ -272,6 +231,18 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
     }
 
     /**
+     * Returns {@code true} if this axis is likely to have a "wraparound" range. The main case is the longitude
+     * axis with a [-180 … +180]° range or a [0 … 360]° range, where the next value after +180° may be -180°.
+     */
+    final boolean isWraparound() {
+        if (abbreviation == 0) {
+            return AxisDirection.EAST.equals(AxisDirections.absolute(direction)) && Units.isAngular(getUnit());
+        } else {
+            return abbreviation == 'λ';
+        }
+    }
+
+    /**
      * Returns {@code true} if coordinates in this axis seem to map cell corner instead than cell center.
      * A {@code false} value does not necessarily means that the axis maps cell center; it can be unknown.
      * This method assumes a geographic CRS.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index ec4ff5b..1b79253 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -40,6 +40,7 @@ import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.coverage.grid.IllegalGridGeometryException;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.NullArgumentException;
+import org.apache.sis.util.ArraysExt;
 import org.apache.sis.math.Vector;
 
 
@@ -149,6 +150,61 @@ public abstract class Grid extends NamedElement {
     public final Axis[] getAxes() throws IOException, DataStoreException {
         if (axes == null) {
             axes = createAxes();
+            /*
+             * The grid dimension which varies fastest should be first.  The code below will swap axes if needed in order to
+             * achieve that goal, except if a previous axis was already using the same order. We avoid collision only in the
+             * first dimension because it is the one used by metadata and by trySetTransform(…).
+             */
+            final Axis[] workspace = new Axis[axes.length];
+            int i = 0, deferred = workspace.length;
+            for (final Axis axis : axes) {
+                // Put one-dimensional axes first, all other axes last.
+                workspace[axis.sourceDimensions.length <= 1 ? i++ : --deferred] = axis;
+            }
+            deferred = workspace.length;        // Will become index of the first axis whose examination has been deferred.
+            while (i < workspace.length) {      // Start the loop at the first n-dimensional axis (n > 1).
+                final Axis axis = workspace[i];
+                final int[] sourceDimensions = axis.sourceDimensions;
+                /*
+                 * If an axis has a "wraparound" range (for example a longitude axis where the next value after +180°
+                 * may be -180°), we will examine it last. The reason is that if a wraparound occurs in the middle of
+                 * the localization grid, it will confuse the computation based on 'coordinateForAxis(…)' calls below.
+                 * We are better to resolve the latitude axis first, and then resolve the longitude axis with the code
+                 * path checking for dimension collisions, without using coordinateForAxis(…) on longitude axis.
+                 */
+                if (i < deferred && axis.isWraparound()) {
+                    System.arraycopy(workspace, i+1, workspace, i, --deferred - i);
+                    workspace[deferred] = axis;
+                    continue;                                           // Continue the loop without incrementing 'i'.
+                }
+                Boolean swap = null;
+                for (int p=0; p<i; p++) {
+                    final int[] other = workspace[p].sourceDimensions;
+                    if (other.length != 0) {
+                        final int first = other[0];
+                        if (first == sourceDimensions[1]) {swap=false; break;}    // Swapping would cause a collision.
+                        if (first == sourceDimensions[0]) {swap=true;  break;}    // Need swapping for avoiding collision.
+                    }
+                }
+                final int[] sourceSizes = axis.sourceSizes;
+                if (swap == null) {
+                    final int up0  = sourceSizes[0];
+                    final int up1  = sourceSizes[1];
+                    final int mid0 = up0 / 2;
+                    final int mid1 = up1 / 2;
+                    final Variable coordinates = axis.coordinates;
+                    final double inc0 = (coordinateForAxis(coordinates,     0, mid1) -
+                                         coordinateForAxis(coordinates, up0-1, mid1)) / up0;
+                    final double inc1 = (coordinateForAxis(coordinates, mid0,     0) -
+                                         coordinateForAxis(coordinates, mid0, up1-1)) / up1;
+                    swap = Math.abs(inc1) > Math.abs(inc0);
+                }
+                if (swap) {
+                    ArraysExt.swap(sourceSizes,      0, 1);
+                    ArraysExt.swap(sourceDimensions, 0, 1);
+                }
+                i++;
+            }
         }
         return axes;
     }
@@ -157,11 +213,9 @@ public abstract class Grid extends NamedElement {
      * Creates the axes to be returned by {@link #getAxes()}. This method is invoked only once when first needed.
      *
      * @return the CRS axes, in netCDF order (reverse of "natural" order).
-     * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
-     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
      */
-    protected abstract Axis[] createAxes() throws IOException, DataStoreException;
+    protected abstract Axis[] createAxes() throws DataStoreException;
 
     /**
      * Returns a coordinate for the given two-dimensional grid coordinate axis. This is (indirectly) a callback
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
index da24245..8dd2da0 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
@@ -190,12 +190,10 @@ final class GridInfo extends Grid {
      * "two-dimensional axes" (in {@link ucar.nc2.dataset.CoordinateAxis2D} sense).</p>
      *
      * @return the CRS axes, in netCDF order (reverse of "natural" order).
-     * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
-     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
      */
     @Override
-    protected Axis[] createAxes() throws IOException, DataStoreException {
+    protected Axis[] createAxes() throws DataStoreException {
         /*
          * Process the variables in the order the appear in the sequence of bytes that make the netCDF files.
          * This is often the same order than the indices, but not necessarily. The intent is to reduce the
@@ -243,8 +241,8 @@ final class GridInfo extends Grid {
                     }
                 }
             }
-            axes[targetDim] = new Axis(this, axis, abbreviation, axis.getAttributeAsString(CF.POSITIVE),
-                                       ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i), axes);
+            axes[targetDim] = new Axis(axis, abbreviation, axis.getAttributeAsString(CF.POSITIVE),
+                                       ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i));
         }
         if (sortAxes) {
             Arrays.sort(axes);
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
index 1e40003..bbf7556 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.internal.netcdf.ucar;
 
-import java.io.IOException;
 import java.util.List;
 import ucar.nc2.Dimension;
 import ucar.nc2.constants.AxisType;
@@ -126,12 +125,10 @@ final class GridWrapper extends Grid {
      * of {@link CoordinateAxis2D}.</p>
      *
      * @return the CRS axes, in netCDF order (reverse of "natural" order).
-     * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
-     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
      */
     @Override
-    protected Axis[] createAxes() throws IOException, DataStoreException {
+    protected Axis[] createAxes() throws DataStoreException {
         final List<Dimension> domain = netcdfCS.getDomain();
         final List<CoordinateAxis> range = netcdfCS.getCoordinateAxes();
         /*
@@ -183,8 +180,8 @@ final class GridWrapper extends Grid {
                  * package, we can proceed as if the dimension does not exist ('i' not incremented).
                  */
             }
-            axes[targetDim] = new Axis(this, decoder.getWrapperFor(axis), abbreviation, axis.getPositive(),
-                    ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i), axes);
+            axes[targetDim] = new Axis(decoder.getWrapperFor(axis), abbreviation, axis.getPositive(),
+                                       ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i));
         }
         return axes;
     }


[sis] 03/04: Move a method in a location providing better encapsulation.

Posted by de...@apache.org.
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

commit 341dc1f6dc3ceaf6350469c8224632654b14d467
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Jan 26 16:20:26 2019 +0100

    Move a method in a location providing better encapsulation.
---
 .../java/org/apache/sis/internal/netcdf/Grid.java  | 24 ++++------------------
 .../org/apache/sis/internal/netcdf/Variable.java   | 15 ++++++++++++++
 .../apache/sis/internal/netcdf/impl/GridInfo.java  | 15 --------------
 .../sis/internal/netcdf/impl/VariableInfo.java     | 12 +++++++++++
 .../sis/internal/netcdf/ucar/GridWrapper.java      | 12 -----------
 .../sis/internal/netcdf/ucar/VariableWrapper.java  | 12 ++++++++++-
 6 files changed, 42 insertions(+), 48 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index 1b79253..3c8f52f 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -193,10 +193,10 @@ public abstract class Grid extends NamedElement {
                     final int mid0 = up0 / 2;
                     final int mid1 = up1 / 2;
                     final Variable coordinates = axis.coordinates;
-                    final double inc0 = (coordinateForAxis(coordinates,     0, mid1) -
-                                         coordinateForAxis(coordinates, up0-1, mid1)) / up0;
-                    final double inc1 = (coordinateForAxis(coordinates, mid0,     0) -
-                                         coordinateForAxis(coordinates, mid0, up1-1)) / up1;
+                    final double inc0 = (coordinates.coordinateForAxis(    0, mid1) -
+                                         coordinates.coordinateForAxis(up0-1, mid1)) / up0;
+                    final double inc1 = (coordinates.coordinateForAxis(mid0,     0) -
+                                         coordinates.coordinateForAxis(mid0, up1-1)) / up1;
                     swap = Math.abs(inc1) > Math.abs(inc0);
                 }
                 if (swap) {
@@ -218,22 +218,6 @@ public abstract class Grid extends NamedElement {
     protected abstract Axis[] createAxes() throws DataStoreException;
 
     /**
-     * Returns a coordinate for the given two-dimensional grid coordinate axis. This is (indirectly) a callback
-     * method for {@link #getAxes()}. The (<var>i</var>, <var>j</var>) indices are grid indices <em>before</em>
-     * they get reordered by the {@link Axis} constructor. In the netCDF UCAR API, this method maps directly to
-     * {@link ucar.nc2.dataset.CoordinateAxis2D#getCoordValue(int, int)}.
-     *
-     * @param  axis  an implementation-dependent object representing the two-dimensional axis.
-     * @param  j     the fastest varying (right-most) index.
-     * @param  i     the slowest varying (left-most) index.
-     * @return the coordinate at the given index, or {@link Double#NaN} if it can not be computed.
-     * @throws IOException if an I/O operation was necessary but failed.
-     * @throws DataStoreException if a logical error occurred.
-     * @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
-     */
-    protected abstract double coordinateForAxis(Variable axis, int j, int i) throws IOException, DataStoreException;
-
-    /**
      * Returns the coordinate reference system, or {@code null} if none.
      * This method creates the CRS the first time it is invoked and cache the result.
      *
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 3d9ad7b..825d60f 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -685,6 +685,21 @@ public abstract class Variable extends NamedElement {
     }
 
     /**
+     * Returns a coordinate for this two-dimensional grid coordinate axis. This is (indirectly) a callback method
+     * for {@link Grid#getAxes()}. The (<var>i</var>, <var>j</var>) indices are grid indices <em>before</em>
+     * they get reordered by the {@link Grid#getAxes()} method. In the netCDF UCAR API, this method maps directly
+     * to {@link ucar.nc2.dataset.CoordinateAxis2D#getCoordValue(int, int)}.
+     *
+     * @param  j     the fastest varying (right-most) index.
+     * @param  i     the slowest varying (left-most) index.
+     * @return the coordinate at the given index, or {@link Double#NaN} if it can not be computed.
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
+     */
+    protected abstract double coordinateForAxis(int j, int i) throws IOException, DataStoreException;
+
+    /**
      * Sets the scale and offset coefficients in the given "grid to CRS" transform if possible.
      * Source and target dimensions given to this method are in "natural" order (reverse of netCDF order).
      * This method is invoked only for variables that represent a coordinate system axis.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
index 8dd2da0..cf9d66a 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.internal.netcdf.impl;
 
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.Locale;
 import java.util.Map;
@@ -25,7 +24,6 @@ import java.util.TreeMap;
 import java.util.SortedMap;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.internal.netcdf.Axis;
-import org.apache.sis.internal.netcdf.Variable;
 import org.apache.sis.internal.netcdf.Grid;
 import org.apache.sis.internal.netcdf.Resources;
 import org.apache.sis.storage.DataStoreContentException;
@@ -251,19 +249,6 @@ final class GridInfo extends Grid {
     }
 
     /**
-     * Returns a coordinate for the given two-dimensional grid coordinate axis.
-     * This is (indirectly) a callback method for {@link #getAxes()}.
-     *
-     * @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
-     */
-    @Override
-    protected double coordinateForAxis(final Variable axis, final int j, final int i) throws IOException, DataStoreException {
-        final VariableInfo v = (VariableInfo) axis;
-        final int n = v.dimensions[0].length;
-        return v.read().doubleValue(j + n*i);
-    }
-
-    /**
      * Returns a hash code for this grid. A map of {@code GridInfo} is used by
      * {@link ChannelDecoder#getGridGeometries()} for sharing existing instances.
      */
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index fbffe03..daa275e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -813,6 +813,18 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> {
     }
 
     /**
+     * Returns a coordinate for this two-dimensional grid coordinate axis.
+     * This is (indirectly) a callback method for {@link Grid#getAxes()}.
+     *
+     * @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
+     */
+    @Override
+    protected double coordinateForAxis(final int j, final int i) throws IOException, DataStoreException {
+        final int n = dimensions[0].length;
+        return read().doubleValue(j + n*i);
+    }
+
+    /**
      * Returns the meaning of the given ordinal value, or {@code null} if none.
      * Callers must have verified that {@link #isEnumeration()} returned {@code true}
      * before to invoke this method
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
index bbf7556..20f980a 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
@@ -23,11 +23,9 @@ import ucar.nc2.dataset.CoordinateAxis;
 import ucar.nc2.dataset.CoordinateAxis2D;
 import ucar.nc2.dataset.CoordinateSystem;
 import org.apache.sis.internal.netcdf.Axis;
-import org.apache.sis.internal.netcdf.Variable;
 import org.apache.sis.internal.netcdf.Grid;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.ArraysExt;
-import ucar.nc2.VariableIF;
 
 
 /**
@@ -185,14 +183,4 @@ final class GridWrapper extends Grid {
         }
         return axes;
     }
-
-    /**
-     * Returns a coordinate for the given two-dimensional grid coordinate axis.
-     * This is (indirectly) a callback method for {@link #getAxes()}.
-     */
-    @Override
-    protected double coordinateForAxis(final Variable axis, final int j, final int i) {
-        final VariableIF v = ((VariableWrapper) axis).variable;
-        return (v instanceof CoordinateAxis2D) ? ((CoordinateAxis2D) v).getCoordValue(j, i) : Double.NaN;
-    }
 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
index 9bcac37..f91a90e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
@@ -30,6 +30,7 @@ import ucar.nc2.VariableIF;
 import ucar.nc2.dataset.Enhancements;
 import ucar.nc2.dataset.VariableEnhanced;
 import ucar.nc2.dataset.CoordinateAxis1D;
+import ucar.nc2.dataset.CoordinateAxis2D;
 import ucar.nc2.dataset.CoordinateSystem;
 import ucar.nc2.dataset.EnhanceScaleMissing;
 import ucar.nc2.units.SimpleUnit;
@@ -62,7 +63,7 @@ final class VariableWrapper extends Variable {
     /**
      * The netCDF variable. This is typically an instance of {@link VariableEnhanced}.
      */
-    final VariableIF variable;
+    private final VariableIF variable;
 
     /**
      * The variable without enhancements. May be the same instance than {@link #variable}
@@ -421,6 +422,15 @@ final class VariableWrapper extends Variable {
     }
 
     /**
+     * Returns a coordinate for this two-dimensional grid coordinate axis.
+     * This is (indirectly) a callback method for {@link Grid#getAxes()}.
+     */
+    @Override
+    protected double coordinateForAxis(final int j, final int i) {
+        return (variable instanceof CoordinateAxis2D) ? ((CoordinateAxis2D) variable).getCoordValue(j, i) : Double.NaN;
+    }
+
+    /**
      * Sets the scale and offset coefficients in the given "grid to CRS" transform if possible.
      * This method is invoked only for variables that represent a coordinate system axis.
      */


[sis] 01/04: Replace some "ordinate" words by "coordinate". We will need to perform this replacement for the whole project some day.

Posted by de...@apache.org.
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

commit c1138c148bf6466b0682926709231cb8fe58f38b
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Fri Jan 25 15:49:05 2019 +0100

    Replace some "ordinate" words by "coordinate". We will need to perform this replacement for the whole project some day.
---
 .../operation/builder/LinearTransformBuilder.java  | 38 +++++++++++-----------
 .../operation/builder/LocalizationGridBuilder.java |  4 +--
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
index abf76e5..858282e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
@@ -82,7 +82,7 @@ public class LinearTransformBuilder extends TransformBuilder {
     private final int[] gridSize;
 
     /**
-     * The arrays of source ordinate values. Accessed with indices in that order: {@code sources[dimension][point]}.
+     * The arrays of source coordinate values. Accessed with indices in that order: {@code sources[dimension][point]}.
      * This layout allows to create only a few (typically two) large arrays instead of a multitude of small arrays.
      * Example: {x[], y[]}.
      *
@@ -99,7 +99,7 @@ public class LinearTransformBuilder extends TransformBuilder {
     private double[][] sources;
 
     /**
-     * The arrays of target ordinate values. Accessed with indices in that order: {@code targets[dimension][point]}.
+     * The arrays of target coordinate values. Accessed with indices in that order: {@code targets[dimension][point]}.
      * This layout allows to create only a few (typically two) large arrays instead of a multitude of small arrays.
      * Example: {x[], y[], z[]}.
      * This is {@code null} if not yet specified.
@@ -114,7 +114,7 @@ public class LinearTransformBuilder extends TransformBuilder {
 
     /**
      * Number of valid positions in the {@link #sources} or {@link #targets} arrays.
-     * Note that the "valid" positions may contain {@link Double#NaN} ordinate values.
+     * Note that the "valid" positions may contain {@link Double#NaN} coordinate values.
      * This field is only indicative if this {@code LinearTransformBuilder} instance
      * has been created by {@link #LinearTransformBuilder(int...)} because we do not
      * try to detect if user adds a new point or overwrites an existing one.
@@ -148,7 +148,7 @@ public class LinearTransformBuilder extends TransformBuilder {
 
     /**
      * Creates a new linear transform builder for source positions distributed on a regular grid.
-     * This constructor notifies {@code LinearTransformBuilder} that ordinate values of all source positions will
+     * This constructor notifies {@code LinearTransformBuilder} that coordinate values of all source positions will
      * be integers in the [0 … {@code gridSize[0]}-1] range for the first dimension (typically column indices),
      * in the [0 … {@code gridSize[1]}-1] range for the second dimension (typically row indices), <i>etc.</i>
      * The dimension of all source positions is the length of the given {@code gridSize} array.
@@ -156,7 +156,7 @@ public class LinearTransformBuilder extends TransformBuilder {
      * <p>An empty array is equivalent to invoking the no-argument constructor,
      * i.e. no restriction is put on the source coordinates.</p>
      *
-     * @param  gridSize  the number of integer ordinate values in each grid dimension.
+     * @param  gridSize  the number of integer coordinate values in each grid dimension.
      * @throws IllegalArgumentException if a grid size is not strictly positive, or if the product
      *         of all values (∏{@code gridSize}) is greater than {@link Integer#MAX_VALUE}.
      *
@@ -247,7 +247,7 @@ search: for (int j=numPoints; --j >= 0;) {
      * This method should be invoked only when this {@code LinearTransformBuilder} has been created for a grid
      * of known size. Caller must have verified the array length before to invoke this method.
      *
-     * @throws IllegalArgumentException if an ordinate value is illegal.
+     * @throws IllegalArgumentException if a coordinate value is illegal.
      */
     private int flatIndex(final int[] source) {
         assert sources == null;               // This method can not be invoked for randomly distributed points.
@@ -268,7 +268,7 @@ search: for (int j=numPoints; --j >= 0;) {
      * This method should be invoked only when this {@code LinearTransformBuilder} has been created for a grid
      * of known size. Callers must have verified the position dimension before to invoke this method.
      *
-     * @throws IllegalArgumentException if an ordinate value is illegal.
+     * @throws IllegalArgumentException if a coordinate value is illegal.
      *
      * @see ControlPoints#flatIndex(DirectPosition)
      */
@@ -277,10 +277,10 @@ search: for (int j=numPoints; --j >= 0;) {
         int offset = 0;
         for (int i = gridSize.length; i != 0;) {
             final int size = gridSize[--i];
-            final double ordinate = source.getOrdinate(i);
-            final int index = (int) ordinate;
-            if (index != ordinate) {
-                throw new IllegalArgumentException(Errors.format(Errors.Keys.NotAnInteger_1, ordinate));
+            final double coordinate = source.getOrdinate(i);
+            final int index = (int) coordinate;
+            if (index != coordinate) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.NotAnInteger_1, coordinate));
             }
             if (index < 0 || index >= size) {
                 throw new IllegalArgumentException(Errors.format(Errors.Keys.ValueOutOfRange_4, "source", 0, size-1, index));
@@ -452,7 +452,7 @@ search: for (int j=numPoints; --j >= 0;) {
      * together with arbitrary target dimension.</p>
      *
      * <p>If this builder has been created with the {@link #LinearTransformBuilder(int...)} constructor,
-     * then the ordinate values of all source positions shall be integers in the [0 … {@code gridSize[0]}-1]
+     * then the coordinate values of all source positions shall be integers in the [0 … {@code gridSize[0]}-1]
      * range for the first dimension (typically column indices), in the [0 … {@code gridSize[1]}-1] range for
      * the second dimension (typically row indices), <i>etc</i>. This constraint does not apply for builders
      * created with the {@link #LinearTransformBuilder()} constructor.</p>
@@ -461,7 +461,7 @@ search: for (int j=numPoints; --j >= 0;) {
      *         Source positions are assumed precise and target positions are assumed uncertain.
      * @throws IllegalArgumentException if the given positions contain NaN or infinite coordinate values.
      * @throws IllegalArgumentException if this builder has been {@linkplain #LinearTransformBuilder(int...)
-     *         created for a grid} but some source ordinates are not indices in that grid.
+     *         created for a grid} but some source coordinates are not indices in that grid.
      * @throws MismatchedDimensionException if some positions do not have the expected number of dimensions.
      *
      * @since 0.8
@@ -662,9 +662,9 @@ search:         for (int j=domain(); --j >= 0;) {
                     int offset = 0;
                     while (i != 0) {
                         final int size = gridSize[--i];
-                        final double ordinate = source.getOrdinate(i);
-                        final int index = (int) ordinate;
-                        if (index < 0 || index >= size || index != ordinate) {
+                        final double coordinate = source.getOrdinate(i);
+                        final int index = (int) coordinate;
+                        if (index < 0 || index >= size || index != coordinate) {
                             return -1;
                         }
                         offset = offset * size + index;
@@ -789,7 +789,7 @@ search:         for (int j=domain(); --j >= 0;) {
      *                 If this builder has been created with the {@link #LinearTransformBuilder()} constructor, then no constraint apply.
      * @param  target  the target coordinates, assumed uncertain.
      * @throws IllegalArgumentException if this builder has been {@linkplain #LinearTransformBuilder(int...) created for a grid}
-     *         but some source ordinates are out of index range, or if {@code target} contains NaN of infinite numbers.
+     *         but some source coordinates are out of index range, or if {@code target} contains NaN of infinite numbers.
      * @throws MismatchedDimensionException if the source or target position does not have the expected number of dimensions.
      *
      * @since 0.8
@@ -859,7 +859,7 @@ search:         for (int j=domain(); --j >= 0;) {
      *                 If this builder has been created with the {@link #LinearTransformBuilder()} constructor, then no constraint apply.
      * @return the target coordinates associated to the given source, or {@code null} if none.
      * @throws IllegalArgumentException if this builder has been {@linkplain #LinearTransformBuilder(int...) created for a grid}
-     *         but some source ordinates are out of index range.
+     *         but some source coordinates are out of index range.
      * @throws MismatchedDimensionException if the source position does not have the expected number of dimensions.
      *
      * @since 0.8
@@ -908,7 +908,7 @@ search:         for (int j=domain(); --j >= 0;) {
     }
 
     /**
-     * Returns the vector of source ordinate names.
+     * Returns the vector of source coordinates.
      * It is caller responsibility to ensure that this builder is not backed by a grid.
      */
     final Vector[] sources() {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
index 6b15576..60a2583 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
@@ -353,7 +353,7 @@ public class LocalizationGridBuilder extends TransformBuilder {
      * @param  gridX   the column index in the grid where to store the given target position.
      * @param  gridY   the row index in the grid where to store the given target position.
      * @param  target  the target coordinates, assumed uncertain.
-     * @throws IllegalArgumentException if the {@code x} or {@code y} ordinate value is out of grid range.
+     * @throws IllegalArgumentException if the {@code x} or {@code y} coordinate value is out of grid range.
      * @throws MismatchedDimensionException if the target position does not have the expected number of dimensions.
      */
     public void setControlPoint(final int gridX, final int gridY, final double... target) {
@@ -368,7 +368,7 @@ public class LocalizationGridBuilder extends TransformBuilder {
      * @param  gridX  the column index in the grid where to read the target position.
      * @param  gridY  the row index in the grid where to read the target position.
      * @return the target coordinates associated to the given source, or {@code null} if none.
-     * @throws IllegalArgumentException if the {@code x} or {@code y} ordinate value is out of grid range.
+     * @throws IllegalArgumentException if the {@code x} or {@code y} coordinate value is out of grid range.
      */
     public double[] getControlPoint(final int gridX, final int gridY) {
         tmp[0] = gridX;