sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: Improve comments about the adjustment done for PixelInCell.CELL_CENTER when deriving a GridGeometry from another one.
Date Wed, 24 Apr 2019 13:57:17 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 b24e5d818b42737ace6a6340f01f534a0b9a2195
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Apr 24 14:24:00 2019 +0200

    Improve comments about the adjustment done for PixelInCell.CELL_CENTER when deriving a
GridGeometry from another one.
---
 .../org/apache/sis/coverage/grid/GridGeometry.java  |  6 ++++++
 .../apache/sis/coverage/grid/GridGeometryTest.java  |  9 +++++----
 .../operation/transform/MathTransforms.java         | 21 ++++++++-------------
 .../operation/transform/TranslationTransform.java   |  9 +++++++++
 4 files changed, 28 insertions(+), 17 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 73c0942..d61e583 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
@@ -269,6 +269,12 @@ public class GridGeometry implements Serializable {
             resolution  = other.resolution;
             nonLinears  = other.nonLinears;
         } else {
+            /*
+             * The `toOther` transform applies on `cornerToCRS` because the corner of upper-left
pixel before scaling
+             * is still the corner of upper-left pixel after scaling, while "pixel center"
is no longer the center of
+             * the same pixel. We adjust `toOther` instead than invoking `PixelTranslation.translate(cornerToCRS,
…)`
+             * because we do not know which of `cornerToCRS` or `gridToCRS` has less NaN
values.
+             */
             final MathTransform centerShift = MathTransforms.concatenate(
                     MathTransforms.uniformTranslation(dimension, +0.5), toOther,
                     MathTransforms.uniformTranslation(dimension, -0.5));
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 d0ac7e1..0030616 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
@@ -140,11 +140,12 @@ public final strictfp class GridGeometryTest extends TestCase {
 
     /**
      * Tests the {@link GridGeometry#GridGeometry(GridGeometry, GridExtent, MathTransform)}
constructor.
+     * The math transform used for this test map to pixel corners.
      *
      * @throws TransformException if an error occurred while using the "grid to CRS" transform.
      */
     @Test
-    public void testFromOther() throws TransformException {
+    public void testFromOtherDefinedAtCorner() throws TransformException {
         long[]        low       = new long[] {  1,   3, 2};
         long[]        high      = new long[] {101, 203, 4};
         GridExtent    extent    = new GridExtent(null, low, high, false);
@@ -169,7 +170,7 @@ public final strictfp class GridGeometryTest extends TestCase {
      * We check envelopes as a more intuitive way to verify consistency than inspecting the
math transforms.
      */
     @Test
-    public void testFromOtherConsistency() {
+    public void testFromOtherDefinedAtCenter() {
         GridExtent extent = new GridExtent(126, 197);
         GridGeometry grid = new GridGeometry(extent, PixelInCell.CELL_CENTER, MathTransforms.identity(2),
HardCodedCRS.WGS84);
         GeneralEnvelope expected = new GeneralEnvelope(new double[] {-0.5, -0.5}, new double[]
{125.5, 196.5});
@@ -181,8 +182,8 @@ public final strictfp class GridGeometryTest extends TestCase {
         grid = grid.derive().resize(extent, 0.1, 0.1).build();
         assertEnvelopeEquals(expected, grid.getEnvelope(), STRICT);
         /*
-         * If we try to create a grid geometry with identical properties, the envelope computed
by that grid geometry would
-         * be different than the envelope computed above if the "grid to CRS" transforms
are not correctly adjusted.
+         * If we create a grid geometry with identical properties, the envelope computed
by that grid geometry would
+         * be different than the envelope computed above if the "grid to CRS" transform is
not correctly adjusted.
          */
         final GridGeometry alternative = new GridGeometry(grid.getExtent(), PixelInCell.CELL_CENTER,
                  grid.getGridToCRS(PixelInCell.CELL_CENTER), grid.getCoordinateReferenceSystem());
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
index 3ef0fca..8d3d046 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
@@ -18,7 +18,6 @@ package org.apache.sis.referencing.operation.transform;
 
 import java.util.Map;
 import java.util.List;
-import java.util.Arrays;
 import java.util.Collections;
 import java.awt.geom.AffineTransform;
 import org.opengis.util.FactoryException;
@@ -80,7 +79,7 @@ public final class MathTransforms extends Static {
      *   <li>If {@code dimension == 2}, then the returned transform implements {@link
MathTransform2D}.</li>
      * </ul>
      *
-     * @param  dimension  the dimension of the transform to be returned.
+     * @param  dimension  number of dimensions of the transform to be returned.
      * @return an identity transform of the specified dimension.
      */
     public static LinearTransform identity(final int dimension) {
@@ -95,9 +94,9 @@ public final class MathTransforms extends Static {
      *
      * <blockquote><var>y</var> = <var>x</var> + {@code offset}</blockquote>
      *
-     * @param  dimension  the input and output dimensions.
+     * @param  dimension  number of input and output dimensions.
      * @param  offset     the {@code offset} term in the linear equation.
-     * @return the linear transform for the given offset.
+     * @return an affine transform applying the specified translation.
      *
      * @since 1.0
      */
@@ -110,20 +109,16 @@ public final class MathTransforms extends Static {
             case 0:  return IdentityTransform.create(0);
             case 1:  return LinearTransform1D.create(1, offset);
             case 2:  return new AffineTransform2D(1, 0, 0, 1, offset, offset);
-            default: {
-                final double[] vector = new double[dimension];
-                Arrays.fill(vector, offset);
-                return new TranslationTransform(vector);
-            }
+            default: return new TranslationTransform(dimension, offset);
         }
     }
 
     /**
-     * Creates a transform which applies the given translation.
+     * Creates an affine transform which applies the given translation.
      * The source and target dimensions of the transform are the length of the given vector.
      *
      * @param  vector  the translation vector.
-     * @return a transform applying the given translation.
+     * @return an affine transform applying the specified translation.
      *
      * @since 1.0
      */
@@ -140,11 +135,11 @@ public final class MathTransforms extends Static {
     }
 
     /**
-     * Creates a transform which applies the given scale.
+     * Creates an affine transform which applies the given scale.
      * The source and target dimensions of the transform are the length of the given vector.
      *
      * @param  factors  the scale factors.
-     * @return a transform applying the given scale.
+     * @return an affine transform applying the specified scales.
      *
      * @since 1.0
      */
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
index fbf79a0..8ea54b0 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
@@ -58,6 +58,15 @@ final class TranslationTransform extends AbstractLinearTransform implements
Exte
     private final double[] errors;
 
     /**
+     * Constructs an uniform translation transform for the given offset applied on all dimensions.
+     */
+    TranslationTransform(final int dimension, double offset) {
+        offsets = new double[dimension];
+        Arrays.fill(offsets, offset);
+        errors = null;
+    }
+
+    /**
      * Constructs a translation transform for the given offset vector.
      */
     TranslationTransform(final double[] offsets) {


Mime
View raw message