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: Add a note in situations where `GridGeometry` crosses the anti-meridian. Documentation and minor accuracy improvement.
Date Fri, 25 Sep 2020 17:25: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 636534f  Add a note in situations where `GridGeometry` crosses the anti-meridian.
Documentation and minor accuracy improvement.
636534f is described below

commit 636534f7e3572a0111b71553df096624248bc058
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Sep 25 19:15:46 2020 +0200

    Add a note in situations where `GridGeometry` crosses the anti-meridian.
    Documentation and minor accuracy improvement.
---
 .../java/org/apache/sis/coverage/grid/GridExtent.java  |  5 +++--
 .../org/apache/sis/coverage/grid/GridGeometry.java     | 18 ++++++++++++++----
 .../org/apache/sis/coverage/grid/package-info.java     |  1 +
 .../apache/sis/coverage/grid/GridDerivationTest.java   | 15 +++++++--------
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index f0288b5..0e97c1b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -910,8 +910,9 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
         final int dimension = getDimension();
         GeneralEnvelope envelope = new GeneralEnvelope(dimension);
         for (int i=0; i<dimension; i++) {
-            // The +1.0 is for making high coordinate exclusive. See GridExtent(GridExtent,
int...) for a discussion.
-            envelope.setRange(i, coordinates[i], coordinates[i + dimension] + 1.0);
+            long high = coordinates[i + dimension];
+            if (high != Long.MAX_VALUE) high++;             // Make the coordinate exclusive
before cast.
+            envelope.setRange(i, coordinates[i], high);     // Possible loss of precision
in cast to `double` type.
         }
         envelope = Envelopes.transform(cornerToCRS, envelope);
         if (envelope.isEmpty()) try {
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 6b8a98b..f9d79b9 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
@@ -1553,13 +1553,16 @@ public class GridGeometry implements LenientComparable, Serializable
{
                 final TableAppender table = new TableAppender(buffer, "  ");
                 final AngleFormat nf = new AngleFormat("DD°MM′SS″", locale);
                 final GeographicBoundingBox bbox = geographicBBox();
+                double westBoundLongitude = Double.NaN;
+                double eastBoundLongitude = Double.NaN;
                 final Instant[] times = timeRange();
                 vocabulary.appendLabel(Vocabulary.Keys.LowerBound, table);
                 table.setCellAlignment(TableAppender.ALIGN_RIGHT);
                 if (bbox != null) {
                     nf.setRoundingMode(RoundingMode.FLOOR);
-                    table.nextColumn(); table.append(nf.format(new  Latitude(bbox.getSouthBoundLatitude())));
-                    table.nextColumn(); table.append(nf.format(new Longitude(bbox.getWestBoundLongitude())));
+                    westBoundLongitude = bbox.getWestBoundLongitude();
+                    table.nextColumn(); table.append(nf.format(new Latitude(bbox.getSouthBoundLatitude())));
+                    table.nextColumn(); table.append(nf.format(new Longitude(westBoundLongitude)));
                 }
                 if (times.length >= 1) {
                     table.nextColumn();
@@ -1571,14 +1574,21 @@ public class GridGeometry implements LenientComparable, Serializable
{
                 table.setCellAlignment(TableAppender.ALIGN_RIGHT);
                 if (bbox != null) {
                     nf.setRoundingMode(RoundingMode.CEILING);
-                    table.nextColumn(); table.append(nf.format(new  Latitude(bbox.getNorthBoundLatitude())));
-                    table.nextColumn(); table.append(nf.format(new Longitude(bbox.getEastBoundLongitude())));
+                    eastBoundLongitude = bbox.getEastBoundLongitude();
+                    table.nextColumn(); table.append(nf.format(new Latitude(bbox.getNorthBoundLatitude())));
+                    table.nextColumn(); table.append(nf.format(new Longitude(eastBoundLongitude)));
                 }
                 if (times.length >= 2) {
                     table.nextColumn();
                     table.append(times[1].toString());
                 }
                 table.flush();
+                if (eastBoundLongitude < westBoundLongitude) {
+                    vocabulary.appendLabel(Vocabulary.Keys.Note, buffer);
+                    buffer.append(' ')
+                          .append(org.apache.sis.internal.metadata.Resources.forLocale(locale).getString(
+                                  org.apache.sis.internal.metadata.Resources.Keys.BoxCrossesAntiMeridian));
+                }
                 writeNodes();
             }
             /*
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/package-info.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/package-info.java
index 4ba9038..e5a9187 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/package-info.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/package-info.java
@@ -40,6 +40,7 @@
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
+ * @author  Alexis Manin (Geomatys)
  * @version 1.1
  * @since   1.0
  * @module
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 7dd4a08..e1849f7 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
@@ -53,6 +53,7 @@ import static org.apache.sis.coverage.grid.GridGeometryTest.assertExtentEquals;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Alexis Manin (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @version 1.1
  * @since   1.0
  * @module
@@ -400,7 +401,7 @@ public final strictfp class GridDerivationTest extends TestCase {
      * argument to {@link GridDerivation#subgrid(GridGeometry)}.
      */
     @Test
-    public void testSubgridCrossingAntiMeridian() {
+    public void testAntiMeridianCrossingInSubgrid() {
         final GridGeometry grid = new GridGeometry(
                 new GridExtent(200, 180), PixelInCell.CELL_CORNER,
                 MathTransforms.linear(new Matrix3(
@@ -424,7 +425,7 @@ public final strictfp class GridDerivationTest extends TestCase {
      * to {@link GridDerivation} constructor.
      */
     @Test
-    public void testBasegridCrossingAntiMeridian() {
+    public void testAntiMeridianCrossingInBaseGrid() {
         /*
          * Longitudes from 100°E to 240°E (in WGS84 geographic CRS), which is equivalent
to 100°E to 120°W.
          * That [100 … 240]°E range is compatible with the [0 … 360]° longitude range
declared in the CRS.
@@ -433,9 +434,8 @@ public final strictfp class GridDerivationTest extends TestCase {
         final GridGeometry grid = new GridGeometry(
                 new GridExtent(null, null, new long[] {8400, 4860}, true), PixelInCell.CELL_CENTER,
                 MathTransforms.linear(new Matrix3(
-                        0.016664682775860015,  0,  100.00833234138793,
-                    0,  0.016663238016868958,      -20.991668380991566,
-                    0, 0, 1)),
+                        0.016664682775860015,  0,  100.00833234138793,   0,
+                        0.016663238016868958,      -20.991668380991566,  0, 0, 1)),
                 HardCodedCRS.WGS84.forConvention(AxesConvention.POSITIVE_RANGE));
         /*
          * 180°W to 180″E (the world) and 80°S to 80°N in Mercator projection.
@@ -444,9 +444,8 @@ public final strictfp class GridDerivationTest extends TestCase {
         final GridGeometry areaOfInterest = new GridGeometry(
                 new GridExtent(null, null, new long[] {256, 256}, false), PixelInCell.CELL_CORNER,
                 MathTransforms.linear(new Matrix3(
-                        156543.03392804097,  0,  -2.0037508342789244E7,
-                    0, -121066.95890409155,       1.5496570739723722E7,
-                    0, 0, 1)),
+                         156543.03392804097,  0,  -2.0037508342789244E7,  0,
+                        -121066.95890409155,       1.5496570739723722E7,  0, 0, 1)),
                 HardCodedConversions.mercator());
         /*
          * Since the area of interest covers the world (in longitude), the intersection should


Mime
View raw message