sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Make `GridGeometry.translate(…)` more robust to cases where not all properties are defined.
Date Sun, 11 Jul 2021 20:17:12 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 e1b1ae895bfd76f156922a5f2d58af5d7f46499e
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sun Jul 11 22:05:23 2021 +0200

    Make `GridGeometry.translate(…)` more robust to cases where not all properties are defined.
---
 .../org/apache/sis/coverage/grid/GridGeometry.java | 29 ++++++++++++++--------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index b477e72..0b4a1bc 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -1308,19 +1308,26 @@ public class GridGeometry implements LenientComparable, Serializable
{
      */
     public GridGeometry translate(final long... translation) {
         ArgumentChecks.ensureNonNull("translation", translation);
-        final double[] vector = new double[getDimension()];
-        boolean isZero = true;
-        for (int i=Math.min(vector.length, translation.length); --i >= 0;) {
-            isZero &= (translation[i] == 0);
-            vector[i] = Math.negateExact(translation[i]);
+        GridExtent te = extent;
+        if (te != null) {
+            te = te.translate(translation);
+            if (te == extent) return this;
         }
-        if (isZero) {
-            return this;
-        } else try {
-            return new GridGeometry(this, extent.translate(translation), MathTransforms.translation(vector));
-        } catch (TransformException e) {
-            throw new AssertionError(e);
+        MathTransform t1 = gridToCRS;
+        MathTransform t2 = cornerToCRS;
+        if (t1 != null || t2 != null) {
+            boolean isZero = true;
+            final double[] vector = new double[getDimension()];
+            for (int i=Math.min(vector.length, translation.length); --i >= 0;) {
+                isZero &= (translation[i] == 0);
+                vector[i] = Math.negateExact(translation[i]);
+            }
+            if (isZero) return this;
+            final MathTransform t = MathTransforms.translation(vector);
+            t1 = MathTransforms.concatenate(t, t1);
+            t2 = MathTransforms.concatenate(t, t2);
         }
+        return new GridGeometry(te, t1, t2, envelope, resolution, nonLinears);
     }
 
     /**

Mime
View raw message