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

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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 32c2cdd  GridDerivation.slice(DirectPosition) shall perform its 
computation using the transform mapping pixel center, not pixel corner. This is 
different than GridDerivation.subgrid(Envelope) which needs to continue to use 
pixel corner.
32c2cdd is described below

commit 32c2cddf1397ec5fa3a0969709e3bd8720eabe7f
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri Mar 29 11:07:42 2019 +0100

    GridDerivation.slice(DirectPosition) shall perform its computation using 
the transform mapping pixel center, not pixel corner.
    This is different than GridDerivation.subgrid(Envelope) which needs to 
continue to use pixel corner.
---
 .../org/apache/sis/coverage/grid/GridDerivation.java     | 16 ++++++++--------
 .../java/org/apache/sis/coverage/grid/GridGeometry.java  | 12 +++++++-----
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
index c3eea61..f43c008 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
@@ -113,7 +113,7 @@ public class GridDerivation {
      *
      * <p>This extent is initialized to {@code base.extent} if no slice, scale 
or sub-grid has been requested.
      * This field may be {@code null} if the base grid geometry does not 
define any extent.
-     * A successful call to {@link GridGeometry#requireGridToCRS()} guarantees 
that this field is non-null.</p>
+     * A successful call to {@link GridGeometry#requireGridToCRS(boolean)} 
guarantees that this field is non-null.</p>
      *
      * @see #getIntersection()
      */
@@ -477,7 +477,7 @@ public class GridDerivation {
      */
     public GridDerivation subgrid(final Envelope areaOfInterest, double... 
resolution) {
         ensureSubgridNotSet();
-        MathTransform cornerToCRS = base.requireGridToCRS();
+        MathTransform cornerToCRS = base.requireGridToCRS(false);
         subGridSetter = "subgrid";
         try {
             /*
@@ -731,11 +731,11 @@ public class GridDerivation {
      */
     public GridDerivation slice(final DirectPosition slicePoint) {
         ArgumentChecks.ensureNonNull("slicePoint", slicePoint);
-        MathTransform cornerToCRS = base.requireGridToCRS();
+        MathTransform gridToCRS = base.requireGridToCRS(true);
         subGridSetter = "slice";
         try {
             if (toBase != null) {
-                cornerToCRS = MathTransforms.concatenate(toBase, cornerToCRS);
+                gridToCRS = MathTransforms.concatenate(toBase, gridToCRS);
             }
             if (base.envelope != null) {
                 final CoordinateReferenceSystem sourceCRS = 
base.envelope.getCoordinateReferenceSystem();
@@ -743,14 +743,14 @@ public class GridDerivation {
                     final CoordinateReferenceSystem targetCRS = 
slicePoint.getCoordinateReferenceSystem();
                     if (targetCRS != null) {
                         final CoordinateOperation operation = 
CRS.findOperation(sourceCRS, targetCRS, null);
-                        cornerToCRS = MathTransforms.concatenate(cornerToCRS, 
operation.getMathTransform());
+                        gridToCRS = MathTransforms.concatenate(gridToCRS, 
operation.getMathTransform());
                     }
                 }
             }
-            final int dimension = cornerToCRS.getTargetDimensions();
+            final int dimension = gridToCRS.getTargetDimensions();
             ArgumentChecks.ensureDimensionMatches("slicePoint", dimension, 
slicePoint);
-            cornerToCRS = dropUnusedDimensions(cornerToCRS, dimension);
-            DirectPosition gridPoint = 
cornerToCRS.inverse().transform(slicePoint, null);
+            gridToCRS = dropUnusedDimensions(gridToCRS, dimension);
+            DirectPosition gridPoint = 
gridToCRS.inverse().transform(slicePoint, null);
             if (scaledExtent != null) {
                 scaledExtent = scaledExtent.slice(gridPoint, 
modifiedDimensions);
             }
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 2c48f0e..08ca843 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
@@ -934,19 +934,21 @@ public class GridGeometry implements Serializable {
 
     /**
      * Verifies that this grid geometry defines an {@linkplain #extent} and a 
{@link #cornerToCRS} transform.
-     * They are the information required for mapping the grid to a 
spatiotemporal envelope.
+     * They are the information required for mapping the grid to a 
spatiotemporal envelope or position.
      * Note that this implies that {@link #envelope} is non-null.
      *
-     * @return {@link #cornerToCRS}.
+     * @param  center  {@code true} for "center to CRS" transform, {@code 
false} for "corner to CRS" transform.
+     * @return {@link #gridToCRS} or {@link #cornerToCRS}.
      */
-    final MathTransform requireGridToCRS() throws 
IncompleteGridGeometryException {
+    final MathTransform requireGridToCRS(final boolean center) throws 
IncompleteGridGeometryException {
         if (extent == null) {
             throw incomplete(EXTENT, Resources.Keys.UnspecifiedGridExtent);
         }
-        if (cornerToCRS == null) {
+        final MathTransform mt = center ? gridToCRS : cornerToCRS;
+        if (mt == null) {
             throw incomplete(GRID_TO_CRS, Resources.Keys.UnspecifiedTransform);
         }
-        return cornerToCRS;
+        return mt;
     }
 
     /**

Reply via email to