sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 04/05: Change the policy of DatumShiftGrid.getDomainOfValidity(): compute the envelope from cell center, not cell border. This is necessary for avoiding spurious overlaps when two grids are side-by-side (in principle without overlapping) but one grid has larger cells than the other other grid. The 0.5 cell expansion caused the grid with larger cells to overlap the grid with smaller cells. This problem happens with NTv2 datum shift grid.
Date Sat, 15 Feb 2020 17:13:02 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit e16a2c4190200704f9d794e4c21e31d309ff1501
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Feb 15 17:32:57 2020 +0100

    Change the policy of DatumShiftGrid.getDomainOfValidity(): compute the envelope from cell
center, not cell border.
    This is necessary for avoiding spurious overlaps when two grids are side-by-side (in principle
without overlapping)
    but one grid has larger cells than the other other grid. The 0.5 cell expansion caused
the grid with larger cells
    to overlap the grid with smaller cells. This problem happens with NTv2 datum shift grid.
---
 .../sis/referencing/datum/DatumShiftGrid.java      | 25 ++++++++++++++++------
 .../FranceGeocentricInterpolationTest.java         |  8 +++----
 .../internal/referencing/provider/NADCONTest.java  |  8 +++----
 .../internal/referencing/provider/NTv2Test.java    | 16 +++++++-------
 .../src/test/java/org/apache/sis/test/Assume.java  |  2 +-
 5 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java
index 9ad33d9..e5403fd 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DatumShiftGrid.java
@@ -275,12 +275,14 @@ public abstract class DatumShiftGrid<C extends Quantity<C>,
T extends Quantity<T
 
     /**
      * Returns the domain of validity of input coordinates that can be specified to the
-     * {@link #interpolateAt interpolateAt(…)} method. Coordinates outside that domain
of
-     * validity will still be accepted, but the extrapolated results may be very wrong.
+     * {@link #interpolateAt interpolateAt(…)} method. Coordinates outside that domain
+     * will still be accepted, but results will be extrapolations possibly far from reality.
      *
-     * <p>The unit of measurement for the coordinate values in the returned envelope
is
-     * given by {@link #getCoordinateUnit()}. The envelope CRS is not set, but its value
-     * is implicitly the CRS of grid input coordinates.</p>
+     * <p>The envelope coordinates are computed at cell centers; the envelope does
not contain
+     * the margin of 0.5 cell between cell center and cell border at the edges of the envelope.
+     * The unit of measurement for the coordinate values in the returned envelope is given
by
+     * {@link #getCoordinateUnit()}. The envelope CRS is not set, but its value is implicitly
+     * the CRS of grid input coordinates.</p>
      *
      * @return the domain covered by this grid.
      * @throws TransformException if an error occurred while computing the envelope.
@@ -288,7 +290,18 @@ public abstract class DatumShiftGrid<C extends Quantity<C>,
T extends Quantity<T
     public Envelope getDomainOfValidity() throws TransformException {
         final GeneralEnvelope env = new GeneralEnvelope(gridSize.length);
         for (int i=0; i<gridSize.length; i++) {
-            env.setRange(i, -0.5, gridSize[i] - 0.5);
+            /*
+             * Note: a previous version was using the following code in an attempt to encompass
+             * fully all cells (keeping in mind that the `coordinatetoGrid` maps cell centers):
+             *
+             *    env.setRange(i, -0.5, gridSize[i] - 0.5);
+             *
+             * However it was causing spurious overlaps when two grids are side-by-side
+             * (no overlapping) but one grid has larger cells than the other other grid.
+             * The 0.5 cell expansion caused the grid with larger cells to overlap the
+             * grid with smaller cells. This case happens with NTv2 datum shift grid.
+             */
+            env.setRange(i, 0, gridSize[i] - 1);
         }
         return Envelopes.transform(getCoordinateToGrid().inverse(), env);
     }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java
index 8a13416..8f69416 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolationTest.java
@@ -186,10 +186,10 @@ public final strictfp class FranceGeocentricInterpolationTest extends
DatumShift
      */
     private static void verifyGrid(final DatumShiftGridFile<Angle,Length> grid) throws
TransformException {
         final Envelope envelope = grid.getDomainOfValidity();
-        assertEquals("xmin",  2.2 - 0.05, envelope.getMinimum(0), 1E-12);
-        assertEquals("xmax",  2.5 + 0.05, envelope.getMaximum(0), 1E-12);
-        assertEquals("ymin", 48.5 - 0.05, envelope.getMinimum(1), 1E-12);
-        assertEquals("ymax", 49.0 + 0.05, envelope.getMaximum(1), 1E-12);
+        assertEquals("xmin",  2.2, envelope.getMinimum(0), 1E-12);
+        assertEquals("xmax",  2.5, envelope.getMaximum(0), 1E-12);
+        assertEquals("ymin", 48.5, envelope.getMinimum(1), 1E-12);
+        assertEquals("ymax", 49.0, envelope.getMaximum(1), 1E-12);
         /*
          * The values in the NTG_88 document are:
          *
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NADCONTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NADCONTest.java
index 11945ce..aeca2ac 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NADCONTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NADCONTest.java
@@ -145,10 +145,10 @@ public final strictfp class NADCONTest extends DatumShiftTestCase {
          */
         final double cellSize = 0.25;
         final Envelope envelope = grid.getDomainOfValidity();
-        assertEquals("xmin", xmin - cellSize/2, envelope.getMinimum(0), STRICT);
-        assertEquals("xmax", xmax + cellSize/2, envelope.getMaximum(0), STRICT);
-        assertEquals("ymin", ymin - cellSize/2, envelope.getMinimum(1), STRICT);
-        assertEquals("ymax", ymax + cellSize/2, envelope.getMaximum(1), STRICT);
+        assertEquals("xmin", xmin, envelope.getMinimum(0), STRICT);
+        assertEquals("xmax", xmax, envelope.getMaximum(0), STRICT);
+        assertEquals("ymin", ymin, envelope.getMinimum(1), STRICT);
+        assertEquals("ymax", ymax, envelope.getMaximum(1), STRICT);
         assertMatrixEquals("coordinateToGrid",
                 new Matrix3(cellSize,  0,  xmin,
                             0,  cellSize,  ymin,
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
index 27581e4..1077f01 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/NTv2Test.java
@@ -133,10 +133,10 @@ public final strictfp class NTv2Test extends DatumShiftTestCase {
          * The cells are expected to have the same size (360″ or 0.1°) in longitudes and
latitudes.
          */
         final Envelope envelope = grid.getDomainOfValidity();
-        assertEquals("xmin", xmin - cellSize/2, envelope.getMinimum(0), STRICT);
-        assertEquals("xmax", xmax + cellSize/2, envelope.getMaximum(0), STRICT);
-        assertEquals("ymin", ymin - cellSize/2, envelope.getMinimum(1), STRICT);
-        assertEquals("ymax", ymax + cellSize/2, envelope.getMaximum(1), STRICT);
+        assertEquals("xmin", xmin, envelope.getMinimum(0), STRICT);
+        assertEquals("xmax", xmax, envelope.getMaximum(0), STRICT);
+        assertEquals("ymin", ymin, envelope.getMinimum(1), STRICT);
+        assertEquals("ymax", ymax, envelope.getMaximum(1), STRICT);
         assertMatrixEquals("coordinateToGrid",
                 new Matrix3(-cellSize,  0,  xmax,
                             0,  +cellSize,  ymin,
@@ -202,10 +202,10 @@ public final strictfp class NTv2Test extends DatumShiftTestCase {
          */
         final double cellSize = 300;                                    // Number of arc-seconds
in a cell.
         final Envelope envelope = grid.getDomainOfValidity();
-        assertEquals("xmin", (-142.29 - 0.5/cellSize) * DEGREES_TO_SECONDS, envelope.getMinimum(0),
1E-10);
-        assertEquals("xmax", ( -43.96 + 0.5/cellSize) * DEGREES_TO_SECONDS, envelope.getMaximum(0),
1E-10);
-        assertEquals("ymin", (  39.96 - 0.5/cellSize) * DEGREES_TO_SECONDS, envelope.getMinimum(1),
1E-10);
-        assertEquals("ymax", (  84.04 + 0.5/cellSize) * DEGREES_TO_SECONDS, envelope.getMaximum(1),
1E-10);
+        assertEquals("xmin", -142.25 * DEGREES_TO_SECONDS, envelope.getMinimum(0), 1E-10);
+        assertEquals("xmax",  -44.00 * DEGREES_TO_SECONDS, envelope.getMaximum(0), 1E-10);
+        assertEquals("ymin",   40.00 * DEGREES_TO_SECONDS, envelope.getMinimum(1), 1E-10);
+        assertEquals("ymax",   84.00 * DEGREES_TO_SECONDS, envelope.getMaximum(1), 1E-10);
         /*
          * Test a point. This point is located on the 3th grid in the NTv2 file.
          * Consequently if the NTv2 implementation just pickups the first grid,
diff --git a/core/sis-utility/src/test/java/org/apache/sis/test/Assume.java b/core/sis-utility/src/test/java/org/apache/sis/test/Assume.java
index b92957f..7573214 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/test/Assume.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/test/Assume.java
@@ -54,7 +54,7 @@ public final strictfp class Assume extends org.junit.Assume {
         Path path = type.getDirectory();
         assumeNotNull("$SIS_DATA/" + type + " directory not found.", path);
         path = path.resolve(file);
-        assumeTrue("Specified directory not found.", Files.isDirectory(path));
+        assumeTrue("Specified file or directory not found.", Files.exists(path));
         assumeTrue("Specified directory not readable.", Files.isReadable(path));
         return path;
     }


Mime
View raw message