This is an automated email from the ASF dual-hosted git repository.
amanin 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 1ff7519 fix(Referencing): improve common CRS suggestion to return
base geographic system when possible.
1ff7519 is described below
commit 1ff75191ea5e49147432dce6a39d6e3d1004968b
Author: Alexis Manin <[email protected]>
AuthorDate: Thu Oct 10 17:14:28 2019 +0200
fix(Referencing): improve common CRS suggestion to return base geographic
system when possible.
---
.../src/main/java/org/apache/sis/referencing/CRS.java | 6 +++---
.../src/test/java/org/apache/sis/referencing/CRSTest.java | 14 ++++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
index 53cfa2a..3e53ab0 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
@@ -435,7 +435,7 @@ public final class CRS extends Static {
* Suggests a coordinate reference system which could be a common target
for coordinate operations having the
* given sources. This method compares the {@linkplain
#getGeographicBoundingBox(CoordinateReferenceSystem)
* domain of validity} of all given CRSs. If a CRS has a domain of
validity that contains the domain of all other
- * CRS, than that CRS is returned. Otherwise this method verifies if a
{@linkplain GeneralDerivedCRS#getBaseCRS()
+ * CRS, then that CRS is returned. Otherwise this method verifies if a
{@linkplain GeneralDerivedCRS#getBaseCRS()
* base CRS} (usually a {@linkplain
org.apache.sis.referencing.crs.DefaultGeographicCRS geographic CRS} instance)
* would be suitable. If no suitable CRS is found, then this method
returns {@code null}.
*
@@ -478,7 +478,7 @@ public final class CRS extends Static {
* on some knowledge about what the CRS is, abandon.
*/
if (!(crs instanceof GeodeticCRS)) {
- return null;
+ continue;
}
/*
* Geodetic CRS (geographic or geocentric) can generally be
presumed valid in a worldwide area.
@@ -561,7 +561,7 @@ public final class CRS extends Static {
* but using base CRS instead. For example if the list of source
CRS had some projected CRS, we
* will try with the geographic CRS on which those projected CRS
are based.
*/
- if (maxInsideArea < roiArea) {
+ if (Double.isNaN(roiArea) || maxInsideArea < roiArea) {
if (tryDerivedCRS) break;
// Do not try twice.
final SingleCRS[] derivedCRS = new SingleCRS[sourceCRS.length];
for (int i=0; i < derivedCRS.length; i++) {
diff --git
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
index cd64b83..d2b7b88 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
@@ -212,6 +212,20 @@ public final strictfp class CRSTest extends TestCase {
*/
assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1],
CRS.suggestCommonTarget(regionOfInterest, crs));
+
+ final ProjectedCRS utm13N = CommonCRS.WGS84.universal(20, 13);
+ final ProjectedCRS utm42S = CommonCRS.WGS84.universal(-2, 42);
+ assertSame("CRS suggestion should fallback on common base geographic
system when possible.",
+ CommonCRS.WGS84.geographic(), CRS.suggestCommonTarget(null,
utm13N, utm42S));
+
+ assertNotNull(
+ "Disjoint systems should return a geographic suggestion when
possible",
+ CRS.suggestCommonTarget(null,
+ CommonCRS.WGS84.universal(-7, 19),
+ CommonCRS.NAD27.universal(20, -101),
+ CommonCRS.NAD27.universal(18, -20)
+ )
+ );
}
/**