sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1779720 - /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
Date Sat, 21 Jan 2017 10:49:28 GMT
Author: desruisseaux
Date: Sat Jan 21 10:49:28 2017
New Revision: 1779720

URL: http://svn.apache.org/viewvc?rev=1779720&view=rev
Log:
Fix a test failure when CRS.suggestTargetCRS(...) test is executed without connection to the
EPSG database.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1779720&r1=1779719&r2=1779720&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] Sat Jan 21 10:49:28 2017
@@ -302,6 +302,7 @@ public final class CRS extends Static {
     public static CoordinateReferenceSystem suggestTargetCRS(GeographicBoundingBox regionOfInterest,
                                                              CoordinateReferenceSystem...
sourceCRS)
     {
+        CoordinateReferenceSystem bestCRS = null;
         /*
          * Compute the union of the domain of validity of all CRS. If a CRS does not specify
a domain of validity,
          * then assume that the CRS is valid for the whole world if the CRS is geodetic or
return null otherwise.
@@ -312,7 +313,7 @@ public final class CRS extends Static {
         final GeographicBoundingBox[] domains = new GeographicBoundingBox[sourceCRS.length];
         for (int i=0; i < sourceCRS.length; i++) {
             final CoordinateReferenceSystem crs = sourceCRS[i];
-            GeographicBoundingBox bbox = getGeographicBoundingBox(crs);
+            final GeographicBoundingBox bbox = getGeographicBoundingBox(crs);
             if (bbox == null) {
                 /*
                  * If no domain of validity is specified and we can not fallback
@@ -322,28 +323,22 @@ public final class CRS extends Static {
                     return null;
                 }
                 /*
-                 * If no region of interest has been specified, conservatively assume that
the caller is
-                 * interested in a worldwide area. Since we have a Geodetic CRS, we will
not find better.
-                 */
-                if (regionOfInterest == null) {
-                    return crs;
-                }
-                /*
                  * Geodetic CRS (geographic or geocentric) can generally be presumed valid
in a worldwide area.
-                 * Since the caller has specified an area of interest, that will be taken
as our validity domain.
                  * The 'worldwide' flag is a little optimization for remembering that we
do not need to compute
                  * the union anymore, but we still need to continue the loop for fetching
all bounding boxes.
                  */
-                bbox = regionOfInterest;
+                bestCRS = crs;
                 worldwide = true;
-            } else if (!worldwide) {
-                if (domain == null) {
-                    domain = new DefaultGeographicBoundingBox(bbox);
-                } else {
-                    domain.add(bbox);
+            } else {
+                domains[i] = bbox;
+                if (!worldwide) {
+                    if (domain == null) {
+                        domain = new DefaultGeographicBoundingBox(bbox);
+                    } else {
+                        domain.add(bbox);
+                    }
                 }
             }
-            domains[i] = bbox;
         }
         /*
          * At this point we got the union of the domain of validity of all CRS. We are interested
only in the
@@ -375,7 +370,6 @@ public final class CRS extends Static {
          *   - Otherwise (i.e. if the region of interest is likely to be wider than the projected
CRS
          *     domain of validity), then the geographic CRS will be returned.
          */
-        CoordinateReferenceSystem bestCRS = null;
         final double roiArea  = Extents.area(regionOfInterest);   // NaN if 'regionOfInterest'
is null.
         double maxInsideArea  = 0;
         double minOutsideArea = Double.POSITIVE_INFINITY;
@@ -383,23 +377,25 @@ public final class CRS extends Static {
         do {
             for (int i=0; i < domains.length; i++) {
                 final GeographicBoundingBox bbox = domains[i];
-                double insideArea  = Extents.area(bbox);
-                double outsideArea = 0;
-                if (regionOfInterest != null) {
-                    if (domain == null) {
-                        domain = new DefaultGeographicBoundingBox(bbox);
-                    } else {
-                        domain.setBounds(bbox);
+                if (bbox != null) {
+                    double insideArea  = Extents.area(bbox);
+                    double outsideArea = 0;
+                    if (regionOfInterest != null) {
+                        if (domain == null) {
+                            domain = new DefaultGeographicBoundingBox(bbox);
+                        } else {
+                            domain.setBounds(bbox);
+                        }
+                        domain.intersect(regionOfInterest);
+                        final double area = insideArea;
+                        insideArea = Extents.area(domain);
+                        outsideArea = area - insideArea;
+                    }
+                    if (insideArea > maxInsideArea || (insideArea == maxInsideArea &&
outsideArea < minOutsideArea)) {
+                        maxInsideArea  = insideArea;
+                        minOutsideArea = outsideArea;
+                        bestCRS        = sourceCRS[i];
                     }
-                    domain.intersect(regionOfInterest);
-                    final double area = insideArea;
-                    insideArea = Extents.area(domain);
-                    outsideArea = area - insideArea;
-                }
-                if (insideArea > maxInsideArea || (insideArea == maxInsideArea &&
outsideArea < minOutsideArea)) {
-                    maxInsideArea  = insideArea;
-                    minOutsideArea = outsideArea;
-                    bestCRS        = sourceCRS[i];
                 }
             }
             /*
@@ -416,8 +412,8 @@ public final class CRS extends Static {
                     if (crs instanceof GeneralDerivedCRS) {
                         final SingleCRS baseCRS = ((GeneralDerivedCRS) crs).getBaseCRS();
                         bbox = getGeographicBoundingBox(baseCRS);
-                        if (bbox == null) {
-                            bbox = regionOfInterest;
+                        if (bbox == null && bestCRS == null && baseCRS instanceof
GeodeticCRS) {
+                            bestCRS = baseCRS;
                         }
                         tryDerivedCRS = true;
                         derivedCRS[i] = baseCRS;



Mime
View raw message