sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Invocation of GridDerivation.rescale needs to use the inverse of the scale factor defined in "resampling_interval" attribute.
Date Tue, 12 Mar 2019 15:07:32 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new c70d212  Invocation of GridDerivation.rescale needs to use the inverse of the scale
factor defined in "resampling_interval" attribute.
c70d212 is described below

commit c70d212527ff8e1a51d7a8e3b0ccc870adfbe0bd
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Mar 12 16:06:14 2019 +0100

    Invocation of GridDerivation.rescale needs to use the inverse of the scale factor defined
in "resampling_interval" attribute.
---
 .../java/org/apache/sis/coverage/grid/GridDerivation.java     | 11 +++++++++--
 .../main/java/org/apache/sis/internal/netcdf/Variable.java    |  8 ++++++--
 2 files changed, 15 insertions(+), 4 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 0265a26..bd037e5 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
@@ -249,12 +249,19 @@ public class GridDerivation {
     }
 
     /**
-     * Requests a grid geometry having a different range of grid indices resulting from application
of the given scale factors.
+     * Requests a grid geometry where cell sizes have been scaled by the given factors, which
result in a change of grid size.
      * The new grid geometry is given a <cite>"grid to CRS"</cite> transform
computed as the concatenation of given scale factors
      * (applied on grid indices) followed by the {@linkplain GridGeometry#getGridToCRS(PixelInCell)
grid to CRS} transform of the
      * grid geometry specified at construction time. The resulting grid extent can be specified
explicitly (typically as an extent
      * computed by {@link GridExtent#resize(long...)}) or computed automatically by this
method.
      *
+     * <div class="note"><b>Example:</b>
+     * if the original grid geometry had an extent of [0 … 5] in <var>x</var>
and [0 … 8] in <var>y</var>, then a call to
+     * {@code resize(null, 0.1, 0.1)} will build a grid geometry with an extent of [0 … 50]
in <var>x</var> and [0 … 80] in <var>y</var>.
+     * This new extent covers the same geographic area than the old extent but with pixels
having a size of 0.1 times the old pixels size.
+     * The <cite>grid to CRS</cite> transform of the new grid geometry will be
pre-concatenated with scale factors of 0.1 in compensation
+     * for the shrink in pixels size.</div>
+     *
      * <p>Notes:</p>
      * <ul>
      *   <li>This method can be invoked only once.</li>
@@ -302,7 +309,7 @@ public class GridDerivation {
             Arrays.fill(scales, actual, n, 1);
         }
         this.toBase = MathTransforms.scale(scales);
-        this.scales = scales;
+        this.scales = scales;                           // No clone needed since the array
has been copied above.
         /*
          * If the user did not specified explicitly the resulting grid extent, compute it
now.
          * This operation should never fail since we use known implementation of MathTransform,
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 19f7d4a..c1c9466 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
@@ -506,16 +506,20 @@ public abstract class Variable extends NamedElement {
                 }
             }
             if (needsResize) {
+                double[] dataToGridIndices = null;
                 if (gridToDataIndices != null) {
-                    for (final double s : gridToDataIndices) {
+                    dataToGridIndices = new double[gridToDataIndices.length];
+                    for (int i=0; i<dataToGridIndices.length; i++) {
+                        final double s = gridToDataIndices[i];
                         if (!(s > 0)) {
                             warning(Variable.class, "getGridGeometry", Resources.Keys.ResamplingIntervalNotFound_2,
getFilename(), getName());
                             return null;
                         }
+                        dataToGridIndices[i] = 1 / s;
                     }
                 }
                 extent = extent.resize(sizes);
-                grid = grid.derive().resize(extent, gridToDataIndices).build();
+                grid = grid.derive().resize(extent, dataToGridIndices).build();
                 /*
                  * Note: the 'gridToDataIndices' array was computed as a side-effect of the
call to 'getGrid(decoder)'.
                  * This is one reason why we keep the call to 'getGrid(…)' inside this
'getGridGeometry(…)' method.


Mime
View raw message