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: Make GridDerivation.subgrid(…) consistent with GridDerivation.slice(…) regarding IncompleteGridGeometryException being thrown if `areaOfInterest` has a CRS but `GridGeometry` has none.
Date Mon, 08 Apr 2019 08:12:46 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 a8631e1  Make GridDerivation.subgrid(…) consistent with GridDerivation.slice(…)
regarding IncompleteGridGeometryException being thrown if `areaOfInterest` has a CRS but `GridGeometry`
has none.
a8631e1 is described below

commit a8631e1215cd0a22780d3ba3bc4dc329e4a272e6
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Apr 8 10:11:12 2019 +0200

    Make GridDerivation.subgrid(…) consistent with GridDerivation.slice(…) regarding IncompleteGridGeometryException
being thrown if `areaOfInterest` has a CRS but `GridGeometry` has none.
---
 .../apache/sis/coverage/grid/GridDerivation.java   | 29 +++++++++++++++++-----
 .../org/apache/sis/coverage/grid/GridGeometry.java |  2 +-
 2 files changed, 24 insertions(+), 7 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 1c7ef9c..b5f62e0 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
@@ -459,6 +459,10 @@ public class GridDerivation {
      *       before to invoke this method.</li>
      *   <li>This method does not reduce the number of dimensions of the grid geometry.
      *       For dimensionality reduction, see {@link GridGeometry#reduce(int...)}.</li>
+     *   <li>If the given envelope is known to be expressed in the same CRS than the
grid geometry,
+     *       then the {@linkplain Envelope#getCoordinateReferenceSystem() CRS of the envelope}
+     *       can be left unspecified ({@code null}). It may give a slight performance improvement
+     *       by avoiding the check for coordinate transformation.</li>
      * </ul>
      *
      * @param  areaOfInterest  the desired spatiotemporal region in any CRS (transformations
will be applied as needed),
@@ -469,7 +473,8 @@ public class GridDerivation {
      *                         (zero or missing values mean no sub-sampling, extraneous values
are ignored).
      * @return {@code this} for method call chaining.
      * @throws DisjointExtentException if the given area of interest does not intersect the
grid extent.
-     * @throws IncompleteGridGeometryException if the base grid geometry has no extent or
no "grid to CRS" transform.
+     * @throws IncompleteGridGeometryException if the base grid geometry has no extent, no
"grid to CRS" transform,
+     *         or no CRS (unless {@code areaOfInterest} has no CRS neither, in which case
the CRS are assumed the same).
      * @throws IllegalGridGeometryException if an error occurred while converting the envelope
coordinates to grid coordinates.
      * @throws IllegalStateException if a {@link #subgrid(GridGeometry) subgrid(…)} or
{@link #slice(DirectPosition) slice(…)}
      *         method has already been invoked.
@@ -486,9 +491,22 @@ public class GridDerivation {
              * to the 'gridToCRS' transform.  We should not transform the envelope here -
only concatenate the
              * transforms - because transforming envelopes twice would add errors.
              */
-            final CoordinateOperation baseToAOI = Envelopes.findOperation(base.envelope,
areaOfInterest);
-            if (baseToAOI != null) {
-                cornerToCRS = MathTransforms.concatenate(cornerToCRS, baseToAOI.getMathTransform());
+            MathTransform baseToAOI = null;
+            if (areaOfInterest != null) {
+                final CoordinateReferenceSystem crs = areaOfInterest.getCoordinateReferenceSystem();
+                if (crs != null) {
+                    CoordinateOperation op = Envelopes.findOperation(base.envelope, areaOfInterest);
+                    if (op == null) {
+                        /*
+                         * If above call to `Envelopes.findOperation(…)` failed, then `base.envelope`
CRS is probably null.
+                         * Try with a call to `getCoordinateReferenceSystem()` for throwing
IncompleteGridGeometryException,
+                         * unless the user overrode that method in which case we will use
its value.
+                         */
+                        op = CRS.findOperation(base.getCoordinateReferenceSystem(), crs,
null);
+                    }
+                    baseToAOI = op.getMathTransform();
+                    cornerToCRS = MathTransforms.concatenate(cornerToCRS, baseToAOI);
+                }
             }
             /*
              * If the envelope dimensions do not encompass all grid dimensions, the transform
is probably non-invertible.
@@ -505,8 +523,7 @@ public class GridDerivation {
             dimension = baseExtent.getDimension();      // Non-null since 'base.requireGridToCRS()'
succeed.
             GeneralEnvelope indices = null;
             if (areaOfInterest != null) {
-                final MathTransform domainToAOI = (baseToAOI != null) ? baseToAOI.getMathTransform()
: null;
-                indices = new WraparoundAdjustment(base.envelope, domainToAOI, cornerToCRS.inverse()).shift(areaOfInterest);
+                indices = new WraparoundAdjustment(base.envelope, baseToAOI, cornerToCRS.inverse()).shift(areaOfInterest);
                 clipExtent(indices);
             }
             if (indices == null || indices.getDimension() != dimension) {
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 08ca843..1009186 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
@@ -935,7 +935,7 @@ 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
or position.
-     * Note that this implies that {@link #envelope} is non-null.
+     * Note that this implies that {@link #envelope} is non-null (but not necessarily that
its CRS is non-null).
      *
      * @param  center  {@code true} for "center to CRS" transform, {@code false} for "corner
to CRS" transform.
      * @return {@link #gridToCRS} or {@link #cornerToCRS}.


Mime
View raw message