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 2019/02/27 10:02:45 UTC
[sis] branch geoapi-4.0 updated: Better handling of NaN values when
computing the area of interest of a coordinate operation between two CRS.
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 678c3d3 Better handling of NaN values when computing the area of interest of a coordinate operation between two CRS.
678c3d3 is described below
commit 678c3d3361732f0c3b6fc825430bc83b2f92233a
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Feb 27 10:59:50 2019 +0100
Better handling of NaN values when computing the area of interest of a coordinate operation between two CRS.
---
.../internal/referencing/ServicesForMetadata.java | 43 ++++++++++++++--------
.../operation/CoordinateOperationContext.java | 24 +++++++++---
.../operation/CoordinateOperationSorter.java | 2 +-
3 files changed, 47 insertions(+), 22 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
index 952dafc..b0f3b63 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
@@ -88,6 +88,7 @@ import org.apache.sis.metadata.iso.extent.DefaultVerticalExtent;
import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
import org.apache.sis.metadata.iso.extent.DefaultSpatialTemporalExtent;
import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
+import org.apache.sis.measure.Latitude;
import org.apache.sis.measure.Longitude;
import org.apache.sis.internal.metadata.AxisDirections;
import org.apache.sis.internal.metadata.ReferencingServices;
@@ -210,22 +211,34 @@ public final class ServicesForMetadata extends ReferencingServices {
southBoundLatitude = envelope.getMinimum(1);
northBoundLatitude = envelope.getMaximum(1);
}
- if (Math.abs(eastBoundLongitude - westBoundLongitude) >= (Longitude.MAX_VALUE - Longitude.MIN_VALUE)) {
- westBoundLongitude = Longitude.MIN_VALUE;
- eastBoundLongitude = Longitude.MAX_VALUE;
- } else {
- /*
- * The envelope transformation at the beginning of this method intentionally avoided to apply datum shift.
- * This implies that the prime meridian has not been changed and may be something else than Greenwich.
- * We need to take it in account manually.
- */
- if (normalizedCRS != null) {
- final double rotation = CRS.getGreenwichLongitude(normalizedCRS);
- westBoundLongitude += rotation;
- eastBoundLongitude += rotation;
+ /*
+ * The envelope transformation at the beginning of this method intentionally avoided to apply datum shift.
+ * This implies that the prime meridian has not been changed and may be something else than Greenwich.
+ * We need to take it in account manually.
+ *
+ * Note that there is no need to normalize the longitudes back to the [-180 … +180]° range after the rotation, or
+ * to verify if the longitude span is 360°. Those verifications will be done automatically by target.setBounds(…).
+ */
+ if (normalizedCRS != null) {
+ final double rotation = CRS.getGreenwichLongitude(normalizedCRS);
+ westBoundLongitude += rotation;
+ eastBoundLongitude += rotation;
+ }
+ /*
+ * In the particular case where this method is invoked (indirectly) for Envelopes.findOperation(…) purposes,
+ * replace NaN values by the whole world. We do that only for Envelopes.findOperation(…) since we know that
+ * the geographic bounding box will be used for choosing a CRS, and a conservative approach is to select the
+ * CRS valid in the widest area. If this method is invoked for other usages, then we keep NaN values because
+ * we don't know the context (union, intersection, something else?).
+ */
+ if (findOpCaller != null) {
+ if (Double.isNaN(southBoundLatitude)) southBoundLatitude = Latitude.MIN_VALUE;
+ if (Double.isNaN(northBoundLatitude)) northBoundLatitude = Latitude.MAX_VALUE;
+ if (Double.isNaN(eastBoundLongitude) || Double.isNaN(westBoundLongitude)) {
+ // Conservatively set the two bounds because may be spanning the anti-meridian.
+ eastBoundLongitude = Longitude.MIN_VALUE;
+ westBoundLongitude = Longitude.MAX_VALUE;
}
- westBoundLongitude = Longitude.normalize(westBoundLongitude);
- eastBoundLongitude = Longitude.normalize(eastBoundLongitude);
}
if (target == null) {
target = new DefaultGeographicBoundingBox();
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java
index c0ef168..80eaba0 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java
@@ -24,7 +24,8 @@ import org.opengis.referencing.operation.CoordinateOperation;
import org.apache.sis.metadata.iso.extent.DefaultExtent;
import org.apache.sis.metadata.iso.extent.Extents;
import org.apache.sis.internal.util.CollectionsExt;
-import org.apache.sis.util.Emptiable;
+import org.apache.sis.measure.Latitude;
+import org.apache.sis.measure.Longitude;
import org.apache.sis.util.ArgumentChecks;
@@ -105,15 +106,26 @@ public class CoordinateOperationContext implements Serializable {
* This is a convenience method for a frequently-used operation.
*
* @param areaOfInterest the area of interest, or {@code null} if none.
- * @return the operation context, or {@code null} if the given bounding box was null or undefined.
+ * @return the operation context, or {@code null} if the given bounding box was null, undefined
+ * or covers the whole world (in which case Apache SIS does not need that we specify a context).
*
* @since 1.0
*/
public static CoordinateOperationContext fromBoundingBox(final GeographicBoundingBox areaOfInterest) {
- if (areaOfInterest != null && !(areaOfInterest instanceof Emptiable && ((Emptiable) areaOfInterest).isEmpty())) {
- final CoordinateOperationContext context = new CoordinateOperationContext();
- context.setAreaOfInterest(areaOfInterest);
- return context;
+ if (areaOfInterest != null) {
+ /*
+ * If the area of interest covers the world, we omit creating a context in order to make
+ * easier for DefaultCoordinateOperationFactory to detect that it can use its cache.
+ */
+ if (areaOfInterest.getSouthBoundLatitude() > Latitude.MIN_VALUE ||
+ areaOfInterest.getNorthBoundLatitude() < Latitude.MAX_VALUE ||
+ areaOfInterest.getWestBoundLongitude() > Longitude.MIN_VALUE ||
+ areaOfInterest.getEastBoundLongitude() < Longitude.MAX_VALUE)
+ {
+ final CoordinateOperationContext context = new CoordinateOperationContext();
+ context.setAreaOfInterest(areaOfInterest);
+ return context;
+ }
}
return null;
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationSorter.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationSorter.java
index 5cd45d50e..0dcdf27 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationSorter.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationSorter.java
@@ -40,7 +40,7 @@ final class CoordinateOperationSorter implements Comparable<CoordinateOperationS
/**
* Intersection between the domain of validity of the operation and the area of interest,
- * as a negative value for sorting widest area first. May be {@link Double#NaN}.
+ * as a negative value for sorting widest areas first and unknown areas ({@link Double#NaN}) last.
*/
private final double area;