You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2023/04/18 18:28:10 UTC
[sis] 01/04: Add a convenience method for building a `GridGeometry` from only an envelope.
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 54302eaec10eb83224417ff1d037f47b33b7f406
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Apr 18 17:17:58 2023 +0200
Add a convenience method for building a `GridGeometry` from only an envelope.
---
.../sis/coverage/grid/GridCoverageBuilder.java | 2 +-
.../org/apache/sis/coverage/grid/GridGeometry.java | 21 +++++++++++++++++++++
.../sis/coverage/grid/GridDerivationTest.java | 6 +++---
.../apache/sis/coverage/grid/GridGeometryTest.java | 5 +++++
.../java/org/apache/sis/storage/CoverageQuery.java | 3 +--
5 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
index 4119687eac..c495a84f89 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
@@ -238,7 +238,7 @@ public class GridCoverageBuilder {
* @see GridGeometry#GridGeometry(GridExtent, Envelope, GridOrientation)
*/
public GridCoverageBuilder setDomain(final Envelope domain) {
- return setDomain(domain == null ? null : new GridGeometry(null, domain, GridOrientation.HOMOTHETY));
+ return setDomain(domain == null ? null : new GridGeometry(domain));
}
/**
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 d2c22a6718..1f3f6207b8 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
@@ -708,6 +708,27 @@ public class GridGeometry implements LenientComparable, Serializable {
resolution = null;
}
+ /**
+ * Creates a grid geometry with only an envelope.
+ *
+ * @param envelope the envelope together with CRS of the "real world" coordinates.
+ * @throws IllegalArgumentException if the envelope has no CRS and only NaN coordinate values.
+ *
+ * @since 1.4
+ */
+ public GridGeometry(final Envelope envelope) {
+ ArgumentChecks.ensureNonNull("envelope", envelope);
+ this.envelope = ImmutableEnvelope.castOrCopy(envelope);
+ if (this.envelope.isAllNaN() && this.envelope.getCoordinateReferenceSystem() == null) {
+ throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1, "envelope"));
+ }
+ extent = null;
+ gridToCRS = null;
+ cornerToCRS = null;
+ resolution = null;
+ nonLinears = 0;
+ }
+
/**
* Creates a new grid geometry from the given components.
* This constructor performs no verification (unless assertions are enabled).
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java
index 9d1f538e96..407836eca7 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java
@@ -873,8 +873,8 @@ public final class GridDerivationTest extends TestCase {
Envelope2D domain = new Envelope2D(HardCodedCRS.WGS84, 10, 20, 110, 70);
Envelope2D request = new Envelope2D(HardCodedCRS.WGS84, -5, 25, 100, 90);
Envelope2D expected = new Envelope2D(HardCodedCRS.WGS84, 10, 25, 85, 65);
- GridGeometry grid1 = new GridGeometry(null, domain, GridOrientation.HOMOTHETY);
- GridGeometry grid2 = new GridGeometry(null, request, GridOrientation.HOMOTHETY);
+ GridGeometry grid1 = new GridGeometry(domain);
+ GridGeometry grid2 = new GridGeometry(request);
GridGeometry subgrid = grid1.derive().subgrid(grid2).build();
assertTrue(subgrid.isEnvelopeOnly());
assertEnvelopeEquals(expected, subgrid.getEnvelope(), STRICT);
@@ -884,7 +884,7 @@ public final class GridDerivationTest extends TestCase {
*/
request.setCoordinateReferenceSystem(HardCodedCRS.WGS84_LATITUDE_FIRST);
request.setRect(25, -5, 90, 100);
- grid2 = new GridGeometry(null, request, GridOrientation.HOMOTHETY);
+ grid2 = new GridGeometry(request);
subgrid = grid1.derive().subgrid(grid2).build();
assertSame(HardCodedCRS.WGS84, subgrid.getCoordinateReferenceSystem());
assertTrue(subgrid.isEnvelopeOnly());
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index a4149ed31f..ea7759a1f0 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -381,6 +381,11 @@ public final class GridGeometryTest extends TestCase {
* The use of `DISPLAY` mode in this particular case should be equivalent ro `REFLECTION_Y`.
*/
assertEquals(grid, new GridGeometry(extent, aoi, GridOrientation.DISPLAY));
+ /*
+ * Test when only an envelope is specified.
+ * The grid orientation should have no effect.
+ */
+ assertEnvelopeEquals(aoi, new GridGeometry(null, aoi, GridOrientation.DISPLAY).getEnvelope());
}
/**
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/CoverageQuery.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/CoverageQuery.java
index 190d2a2b8d..efa20e0e15 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/CoverageQuery.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/CoverageQuery.java
@@ -33,7 +33,6 @@ import org.apache.sis.measure.AngleFormat;
import org.apache.sis.coverage.SampleDimension;
import org.apache.sis.coverage.grid.GridCoverage;
import org.apache.sis.coverage.grid.GridGeometry;
-import org.apache.sis.coverage.grid.GridRoundingMode;
import org.apache.sis.coverage.grid.GridCoverageProcessor;
import org.apache.sis.coverage.grid.DimensionalityReduction;
import org.apache.sis.coverage.grid.IllegalGridGeometryException;
@@ -124,7 +123,7 @@ public class CoverageQuery extends Query implements Cloneable, Serializable {
public void setSelection(final Envelope domain) {
GridGeometry g = null;
if (domain != null) {
- g = new GridGeometry(null, null, domain, GridRoundingMode.NEAREST);
+ g = new GridGeometry(domain);
}
setSelection(g);
}