sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] branch geoapi-4.0 updated: GridGeometry : add rounding parameter
Date Fri, 11 Jan 2019 14:57:03 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new bedebb4  GridGeometry : add rounding parameter
bedebb4 is described below

commit bedebb4ce458449040bead6e3373bbb20291e817
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Fri Jan 11 16:55:24 2019 +0100

    GridGeometry : add rounding parameter
---
 .../java/org/apache/sis/coverage/grid/GridGeometry.java  | 11 +++++++----
 .../org/apache/sis/coverage/grid/SubgridCalculator.java  | 16 ++++++++++------
 .../org/apache/sis/coverage/grid/GridGeometryTest.java   |  8 ++++----
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 272d191..9212df5 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -679,17 +679,18 @@ public class GridGeometry implements Serializable {
      * For dimensionality reduction, see {@link #reduce(int...)}.</p>
      *
      * @param  areaOfInterest  the desired spatiotemporal region in any CRS (transformations
will be applied as needed).
+     * @param  roundingMode  the grid extent envelope rounding mode.
      * @return a grid extent of the same dimension than the grid geometry which intersects
the given area of interest.
      * @throws IncompleteGridGeometryException if this grid geometry has no extent or no
"grid to CRS" transform.
      * @throws IllegalGridGeometryException if an error occurred while converting the envelope
coordinates to grid coordinates.
      *
      * @see #subgrid(Envelope, double...)
      */
-    public GridExtent subExtent(final Envelope areaOfInterest) {
+    public GridExtent subExtent(final Envelope areaOfInterest, final GridRoundingMode roundingMode)
{
         ArgumentChecks.ensureNonNull("areaOfInterest", areaOfInterest);
         requireGridToCRS();
         try {
-            return new SubgridCalculator(this, cornerToCRS, areaOfInterest, null).extent;
+            return new SubgridCalculator(this, cornerToCRS, areaOfInterest, null, roundingMode).extent;
         } catch (FactoryException | TransformException e) {
             throw new IllegalGridGeometryException(e, "areaOfInterest");
         }
@@ -1052,6 +1053,7 @@ public class GridGeometry implements Serializable {
      *
      * @param  areaOfInterest    the desired spatiotemporal region in any CRS (transformations
will be applied as needed),
      *                           or {@code null} for not restricting the sub-grid to a sub-area.
+     * @param  roundingMode  the grid extent envelope rounding mode.
      * @param  targetResolution  the desired resolution in the same units and order than
the axes of the given envelope,
      *                           or {@code null} or an empty array if no subsampling is
desired.
      * @return a grid geometry over the specified sub-region of this grid geometry with the
specified resolution.
@@ -1061,10 +1063,11 @@ public class GridGeometry implements Serializable {
      * @see #subExtent(Envelope)
      * @see GridExtent#subsample(int[])
      */
-    public GridGeometry subgrid(final Envelope areaOfInterest, double... targetResolution)
{
+    public GridGeometry subgrid(final Envelope areaOfInterest, final GridRoundingMode roundingMode,
+            double... targetResolution) {
         requireGridToCRS();
         try {
-            final SubgridCalculator sub = new SubgridCalculator(this, cornerToCRS, areaOfInterest,
targetResolution);
+            final SubgridCalculator sub = new SubgridCalculator(this, cornerToCRS, areaOfInterest,
targetResolution, roundingMode);
             if (sub.toSubsampled != null || sub.extent != extent) {
                 return new GridGeometry(this, sub.extent, sub.toSubsampled);
             }
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
index 234c73c..4db895e 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
@@ -113,9 +113,11 @@ final class SubgridCalculator {
      * @param  areaOfInterest  the desired spatiotemporal region in any CRS, or {@code null}
for the whole area.
      * @param  resolution      the desired resolution in the same units and order than the
axes of the AOI envelope,
      *                         or {@code null} or an empty array if no subsampling is desired.
+     * @param  roundingMode    the grid extent envelope rounding mode.
      * @throws TransformException if an error occurred while converting the envelope coordinates
to grid coordinates.
      */
-    SubgridCalculator(final GridGeometry grid, MathTransform cornerToCRS, final Envelope
areaOfInterest, double[] resolution)
+    SubgridCalculator(final GridGeometry grid, MathTransform cornerToCRS, final Envelope
areaOfInterest,
+            double[] resolution, final GridRoundingMode roundingMode)
             throws TransformException, FactoryException
     {
         /*
@@ -144,7 +146,7 @@ final class SubgridCalculator {
         GeneralEnvelope indices = null;
         if (areaOfInterest != null) {
             indices = Envelopes.transform(cornerToCRS.inverse(), areaOfInterest);
-            setExtent(indices, extent);
+            setExtent(indices, extent, roundingMode);
         }
         if (indices == null || indices.getDimension() != dimension) {
             indices = new GeneralEnvelope(dimension);
@@ -191,7 +193,7 @@ final class SubgridCalculator {
              */
             if (modified) {
                 final GridExtent unscaled = extent;
-                setExtent(indices, null);
+                setExtent(indices, null, roundingMode);
                 m = Matrices.createIdentity(dimension + 1);
                 for (int k=0; k<resolution.length; k++) {
                     final double s = resolution[k];
@@ -230,13 +232,15 @@ final class SubgridCalculator {
     }
 
     /**
-     * Sets {@link #extent} to the given envelope, rounded to nearest integers.
+     * Sets {@link #extent} to the given envelope.
      *
      * @param  indices    the envelope to use for setting the grid extent.
      * @param  enclosing  the enclosing grid extent if a subsampling is not yet applied,
{@code null} otherwise.
+     * @param  roundingMode  the grid extent envelope rounding mode.
      */
-    private void setExtent(final GeneralEnvelope indices, final GridExtent enclosing) {
-        final GridExtent sub = new GridExtent(indices, GridRoundingMode.NEAREST, null, enclosing,
modifiedDimensions);
+    private void setExtent(final GeneralEnvelope indices, final GridExtent enclosing,
+            final GridRoundingMode roundingMode) {
+        final GridExtent sub = new GridExtent(indices, roundingMode, null, enclosing, modifiedDimensions);
         if (!sub.equals(extent)) {
             extent = sub;
         }
diff --git a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index 0533f1b..6209f8d 100644
--- a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -265,7 +265,7 @@ public final strictfp class GridGeometryTest extends TestCase {
         envelope.setRange(0, -70.001, +80.002);
         envelope.setRange(1,   4.997,  15.003);
         assertExtentEquals(new long[] {370,  40,  4},
-                           new long[] {389, 339, 10}, grid.subExtent(envelope));
+                           new long[] {389, 339, 10}, grid.subExtent(envelope, GridRoundingMode.NEAREST));
     }
 
     /**
@@ -299,7 +299,7 @@ public final strictfp class GridGeometryTest extends TestCase {
         final GeneralEnvelope envelope = new GeneralEnvelope(HardCodedCRS.WGS84);
         envelope.setRange(0, -70.001, +80.002);
         envelope.setRange(1,  -4.997,  15.003);
-        final GridExtent actual = grid.subExtent(envelope);
+        final GridExtent actual = grid.subExtent(envelope, GridRoundingMode.NEAREST);
         assertEquals(extent.getAxisType(0), actual.getAxisType(0));
         assertExtentEquals(new long[] { 56, 69, 2},
                            new long[] {130, 73, 4}, actual);
@@ -329,7 +329,7 @@ public final strictfp class GridGeometryTest extends TestCase {
          */
         envelope.setRange(0, -50, +30);
         envelope.setRange(1,   8,  12);
-        grid = grid.subgrid(envelope, 1, 2);
+        grid = grid.subgrid(envelope, GridRoundingMode.NEAREST, 1, 2);
         assertExtentEquals(new long[] {94, 40}, new long[] {95, 119}, grid.getExtent());
         assertEnvelopeEquals(envelope, grid.getEnvelope(), STRICT);
         assertMatrixEquals("gridToCRS", new Matrix3(
@@ -341,7 +341,7 @@ public final strictfp class GridGeometryTest extends TestCase {
          * It will force GridGeometry to adjust the translation term to compensate. We verify
that the adustment
          * is correct by verifying that we still get the same envelope.
          */
-        grid = grid.subgrid(envelope, 3, 2);
+        grid = grid.subgrid(envelope, GridRoundingMode.NEAREST, 3, 2);
         assertExtentEquals(new long[] {94, 13}, new long[] {95, 39}, grid.getExtent());
         assertEnvelopeEquals(envelope, grid.getEnvelope(), STRICT);
         MathTransform cornerToCRS = grid.getGridToCRS(PixelInCell.CELL_CORNER);


Mime
View raw message