sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Rename GridExtent.getCentroid() as GridExtent.getPointOfInterest() and change its return value for making more obvious that this is not in the unit of a spatio-temporal CRS.
Date Wed, 19 Dec 2018 18:54:50 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 58634c69c850989bc6a14684c75646e80884d8a2
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Dec 19 08:54:53 2018 +0100

    Rename GridExtent.getCentroid() as GridExtent.getPointOfInterest() and change its return
value for making more obvious that this is not in the unit of a spatio-temporal CRS.
---
 .../java/org/apache/sis/console/TransformCommand.java     |  2 +-
 .../java/org/apache/sis/coverage/grid/GridChange.java     |  2 +-
 .../java/org/apache/sis/coverage/grid/GridExtent.java     |  8 +++-----
 .../java/org/apache/sis/coverage/grid/GridGeometry.java   | 15 ++++++++++++---
 .../sis/internal/referencing/DirectPositionView.java      | 10 ++++++++++
 .../operation/transform/SpecializableTransform.java       |  2 +-
 6 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
b/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
index 1a86901..90f03cd 100644
--- a/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
+++ b/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
@@ -586,7 +586,7 @@ final class TransformCommand extends FormattedOutputCommand {
         if (toDomainOfValidity != null && (bbox = CRS.getGeographicBoundingBox(operation))
!= null) {
             domainOfValidity = new ImmutableEnvelope(bbox);
             domainCoordinate = new double[toDomainOfValidity.getTargetDimensions()];
-            positionInDomain = new DirectPositionView.Double(domainCoordinate, 0, domainCoordinate.length);
+            positionInDomain = new DirectPositionView.Double(domainCoordinate);
         } else {
             domainOfValidity = null;
             domainCoordinate = null;
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridChange.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridChange.java
index 2079205..4566fea 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridChange.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridChange.java
@@ -142,7 +142,7 @@ public class GridChange implements Serializable {
             if (matrix != null) {
                 resolution = GridGeometry.resolution(matrix, 1);
             } else {
-                resolution = GridGeometry.resolution(mapCenters.derivative(domain.getCentroid()),
0);
+                resolution = GridGeometry.resolution(mapCenters, domain);
             }
             for (int i=resolution.length; --i >= 0;) {
                 if (resolution[i] != 1) {
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 72865e6..0a5b984 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -25,7 +25,6 @@ import java.io.Serializable;
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import org.opengis.util.FactoryException;
-import org.opengis.geometry.DirectPosition;
 import org.opengis.metadata.spatial.DimensionNameType;
 import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CoordinateSystem;
@@ -43,7 +42,6 @@ import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.geometry.AbstractEnvelope;
 import org.apache.sis.geometry.GeneralEnvelope;
 import org.apache.sis.geometry.Envelopes;
-import org.apache.sis.geometry.GeneralDirectPosition;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.transform.TransformSeparator;
 import org.apache.sis.io.TableAppender;
@@ -516,11 +514,11 @@ public class GridExtent implements Serializable {
      *
      * @return the grid coordinates of a representative point.
      */
-    public DirectPosition getCentroid() {
+    public double[] getPointOfInterest() {
         final int dimension = getDimension();
-        final GeneralDirectPosition center = new GeneralDirectPosition(dimension);
+        final double[] center = new double[dimension];
         for (int i=0; i<dimension; i++) {
-            center.setOrdinate(i, ((double) coordinates[i] + (double) coordinates[i + dimension]
+ 1.0) * 0.5);
+            center[i] = ((double) coordinates[i] + (double) coordinates[i + dimension] +
1.0) * 0.5;
         }
         return center;
     }
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 8a45473..ce7db8a 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
@@ -44,6 +44,7 @@ import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
 import org.apache.sis.referencing.operation.transform.TransformSeparator;
+import org.apache.sis.internal.referencing.DirectPositionView;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.raster.Resources;
 import org.apache.sis.util.collection.TreeTable;
@@ -311,7 +312,7 @@ public class GridGeometry implements Serializable {
         if (matrix != null) {
             resolution = resolution(matrix, 1);
         } else if (extent != null && gridToCRS != null) try {
-            resolution = resolution(gridToCRS.derivative(extent.getCentroid()), 0);
+            resolution = resolution(gridToCRS, extent);
         } catch (TransformException e) {
             recoverableException(e);
         }
@@ -392,7 +393,8 @@ public class GridGeometry implements Serializable {
             env.setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem());
             this.envelope = new ImmutableEnvelope(env);
             if (scales == null) try {
-                scales = gridToCRS.derivative(extent.getCentroid());    // 'gridToCRS' can
not be null if 'cornerToCRS' is non-null.
+                // 'gridToCRS' can not be null if 'cornerToCRS' is non-null.
+                scales = gridToCRS.derivative(new DirectPositionView.Double(extent.getPointOfInterest()));
                 numToIgnore = 0;
             } catch (TransformException e) {
                 recoverableException(e);
@@ -675,7 +677,7 @@ public class GridGeometry implements Serializable {
      * <ul>
      *   <li>{@link Double#NaN} if {@code allowEstimates} is {@code false}.</li>
      *   <li>An arbitrary representative resolution otherwise.
-     *       Current implementation computes the resolution at {@linkplain GridExtent#getCentroid()
grid center},
+     *       Current implementation computes the resolution at {@link GridExtent#getPointOfInterest()
grid center},
      *       but different implementations may use alternative algorithms.</li>
      * </ul>
      *
@@ -720,6 +722,13 @@ public class GridGeometry implements Serializable {
     }
 
     /**
+     * Returns an estimation of the resolution at the point of interest of the given extent.
+     */
+    static double[] resolution(final MathTransform gridToCRS, final GridExtent domain) throws
TransformException {
+        return resolution(gridToCRS.derivative(new DirectPositionView.Double(domain.getPointOfInterest())),
0);
+    }
+
+    /**
      * Indicates whether the <cite>grid to CRS</cite> conversion is linear for
all the specified CRS axes.
      * The conversion from grid coordinates to real world coordinates is often linear for
some dimensions,
      * typically the horizontal ones at indices 0 and 1. But the vertical dimension (usually
at index 2)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DirectPositionView.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DirectPositionView.java
index 61acef8..7bdf5e4 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DirectPositionView.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DirectPositionView.java
@@ -101,6 +101,16 @@ public abstract class DirectPositionView extends AbstractDirectPosition
{
          * Creates a new direct position wrapping the given array.
          *
          * @param  ordinates  the ordinate values.
+         */
+        public Double(final double[] ordinates) {
+            super(0, ordinates.length);
+            this.ordinates = ordinates;
+        }
+
+        /**
+         * Creates a new direct position wrapping the given array.
+         *
+         * @param  ordinates  the ordinate values.
          * @param  offset     the first value index in the ordinates array.
          * @param  dimension  the number of valid ordinate values.
          */
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
index 3b36a46..2d7522b 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
@@ -662,7 +662,7 @@ class SpecializableTransform extends AbstractMathTransform implements
Serializab
             ptDst = global.transform(ptSrc, ptDst);
             final SubArea domain = SubArea.find(forward.domains, ptDst);
             if (domain != null) {
-                ptDst = domain.inverse.transform(new DirectPositionView.Double(source, 0,
source.length), ptDst);
+                ptDst = domain.inverse.transform(new DirectPositionView.Double(source), ptDst);
             }
             return ptDst;
         }


Mime
View raw message