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: Take in account the geographic area of data shown when building the list of CRS.
Date Sun, 19 Apr 2020 22:19:08 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 939ec62  Take in account the geographic area of data shown when building the list
of CRS.
939ec62 is described below

commit 939ec62d1ad3a61f4ff9ffa475ed04d0fcb760c6
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Apr 20 00:18:00 2020 +0200

    Take in account the geographic area of data shown when building the list of CRS.
---
 .../apache/sis/gui/coverage/CoverageExplorer.java  |  2 +-
 .../org/apache/sis/gui/referencing/CRSChooser.java | 26 ++------
 .../gui/referencing/RecentReferenceSystems.java    | 18 ++++--
 .../java/org/apache/sis/gui/referencing/Utils.java | 75 ++++++++++++++++++++++
 4 files changed, 94 insertions(+), 27 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
index 987191a..5e6f2b3 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
@@ -326,7 +326,7 @@ public class CoverageExplorer extends Widget {
     private void notifyCoverageChange(final GridCoverage data) {
         if (data != null) {
             final GridGeometry gg = data.getGridGeometry();
-//          referenceSystems.areaOfInterest.set(gg.isDefined(GridGeometry.ENVELOPE) ? gg.getEnvelope()
: null);
+            referenceSystems.areaOfInterest.set(gg.isDefined(GridGeometry.ENVELOPE) ? gg.getEnvelope()
: null);
             if (gg.isDefined(GridGeometry.CRS)) {
                 referenceSystems.setPreferred(true, gg.getCoordinateReferenceSystem());
             }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
index e3f98a1..28a4eab 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
@@ -46,7 +46,6 @@ import javafx.util.Duration;
 import org.opengis.geometry.Envelope;
 import org.opengis.util.FactoryException;
 import org.opengis.metadata.extent.Extent;
-import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.referencing.crs.GeodeticCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.GeocentricCRS;
@@ -60,7 +59,6 @@ import org.opengis.referencing.crs.CRSAuthorityFactory;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.OperationMethod;
-import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.gui.BackgroundThreads;
 import org.apache.sis.internal.gui.ExceptionReporter;
@@ -68,7 +66,6 @@ import org.apache.sis.internal.gui.IdentityValueFactory;
 import org.apache.sis.internal.gui.Resources;
 import org.apache.sis.internal.gui.Styles;
 import org.apache.sis.geometry.ImmutableEnvelope;
-import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.Exceptions;
@@ -152,16 +149,8 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem>
{
      *                         for the {@linkplain CRS#getAuthorityFactory(String) Apache
SIS default factory}.
      * @param  areaOfInterest  geographic area for which to choose a CRS, or {@code null}
if no restriction.
      */
-    public CRSChooser(final CRSAuthorityFactory factory, Envelope areaOfInterest) {
-        if (areaOfInterest == null) {
-            this.areaOfInterest = null;
-        } else try {
-            final DefaultGeographicBoundingBox bbox = new DefaultGeographicBoundingBox();
-            bbox.setBounds(areaOfInterest);
-            this.areaOfInterest = new ImmutableEnvelope(bbox);
-        } catch (TransformException e) {
-            throw new IllegalArgumentException(e);
-        }
+    public CRSChooser(final CRSAuthorityFactory factory, final Envelope areaOfInterest) {
+        this.areaOfInterest = Utils.toGeographic(CRSChooser.class, "<init>", areaOfInterest);
         final Locale         locale     = Locale.getDefault();
         final Resources      i18n       = Resources.forLocale(locale);
         final Vocabulary     vocabulary = Vocabulary.getResources(locale);
@@ -348,13 +337,10 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem>
{
         String text  = Extents.getDescription(domainOfValidity, locale);
         String tip   = text;
         Color  color = Styles.NORMAL_TEXT;
-        if (areaOfInterest != null) {
-            final GeographicBoundingBox bbox = Extents.getGeographicBoundingBox(domainOfValidity);
-            if (bbox != null && !areaOfInterest.intersects(new ImmutableEnvelope(bbox)))
{
-                tip   = Resources.forLocale(locale).getString(Resources.Keys.DoesNotCoverAOI);
-                text  = Styles.WARNING_ICON + " " + (text != null ? text : tip);
-                color = Styles.ERROR_TEXT;
-            }
+        if (!Utils.intersects(areaOfInterest, domainOfValidity)) {
+            tip   = Resources.forLocale(locale).getString(Resources.Keys.DoesNotCoverAOI);
+            text  = Styles.WARNING_ICON + " " + (text != null ? text : tip);
+            color = Styles.ERROR_TEXT;
         }
         domain.setTextFill(color);
         domain.setText(text);
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
index 6bff9f8..9670f14 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
@@ -18,7 +18,6 @@ package org.apache.sis.gui.referencing;
 
 import java.util.List;
 import java.util.ArrayList;
-import javafx.beans.InvalidationListener;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.value.ChangeListener;
@@ -117,6 +116,11 @@ public class RecentReferenceSystems {
     public final ObjectProperty<Envelope> areaOfInterest;
 
     /**
+     * Area of interest converted to geographic coordinates, or {@code null} if none.
+     */
+    private ImmutableEnvelope geographicAOI;
+
+    /**
      * The comparison criterion for considering two reference systems as a duplication.
      * The default value is {@link ComparisonMode#ALLOW_VARIANT}, i.e. axis orders are ignored.
      */
@@ -192,9 +196,11 @@ public class RecentReferenceSystems {
         areaOfInterest       = new SimpleObjectProperty<>(this, "areaOfInterest");
         duplicationCriterion = new NonNullObjectProperty<>(this, "duplicationCriterion",
ComparisonMode.ALLOW_VARIANT);
         controlValues        = new ArrayList<>();
-        final InvalidationListener pl = (e) -> modified();
-        areaOfInterest.addListener(pl);
-        duplicationCriterion.addListener(pl);
+        duplicationCriterion.addListener((e) -> modified());
+        areaOfInterest.addListener((e,o,n) -> {
+            geographicAOI = Utils.toGeographic(RecentReferenceSystems.class, "areaOfInterest",
n);
+            modified();
+        });
     }
 
     /**
@@ -463,7 +469,7 @@ public class RecentReferenceSystems {
             systemsOrCodes.addAll(Math.min(systemsOrCodes.size(), NUM_CORE_SYSTEMS), referenceSystems);
             // Duplicated values will be filtered by the background task below.
             isModified = true;
-            final ImmutableEnvelope domain = ImmutableEnvelope.castOrCopy(areaOfInterest.get());
+            final ImmutableEnvelope domain = geographicAOI;
             final ComparisonMode mode = duplicationCriterion.get();
             BackgroundThreads.execute(new Task<List<ReferenceSystem>>() {
                 /** Filters the {@link ReferenceSystem}s in a background thread. */
@@ -553,7 +559,7 @@ public class RecentReferenceSystems {
                 return;
             }
             if (newValue == OTHER) {
-                final CRSChooser chooser = new CRSChooser(factory, areaOfInterest.get());
+                final CRSChooser chooser = new CRSChooser(factory, geographicAOI);
                 newValue = chooser.showDialog(GUIUtilities.getWindow(property)).orElse(null);
                 if (newValue == null) {
                     newValue = oldValue;
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/Utils.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/Utils.java
new file mode 100644
index 0000000..ba451d4
--- /dev/null
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/Utils.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.gui.referencing;
+
+import org.opengis.geometry.Envelope;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
+import org.apache.sis.metadata.iso.extent.Extents;
+import org.apache.sis.geometry.ImmutableEnvelope;
+import org.apache.sis.internal.system.Modules;
+import org.apache.sis.util.logging.Logging;
+
+
+/**
+ * Utility methods shared by classes in this package only.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+final class Utils {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private Utils() {
+    }
+
+    /**
+     * Converts an arbitrary envelope to an envelope with (longitude, latitude) axis order
in degrees.
+     * The datum is unspecified. This is used for approximate comparisons of geographic area.
+     */
+    static ImmutableEnvelope toGeographic(final Class<?> caller, final String method,
final Envelope areaOfInterest) {
+        if (areaOfInterest != null) try {
+            final DefaultGeographicBoundingBox bbox = new DefaultGeographicBoundingBox();
+            bbox.setBounds(areaOfInterest);
+            return new ImmutableEnvelope(bbox);
+        } catch (TransformException e) {
+            Logging.recoverableException(Logging.getLogger(Modules.APPLICATION), caller,
method, e);
+        }
+        return null;
+    }
+
+    /**
+     * Returns {@code true} if the specified domain of validity (typically obtained from
a CRS) intersects the
+     * area of interest. If any information is missing, then this method conservatively returns
{@code true}.
+     * The reason for returning {@code true} is because it will usually result in no action
from the caller,
+     * while {@code false} results in warning emitted or CRS filtered out.
+     */
+    static boolean intersects(final ImmutableEnvelope areaOfInterest, final Extent domainOfValidity)
{
+        if (areaOfInterest != null) {
+            final GeographicBoundingBox bbox = Extents.getGeographicBoundingBox(domainOfValidity);
+            if (bbox != null) {
+                return areaOfInterest.intersects(new ImmutableEnvelope(bbox));
+            }
+        }
+        return true;
+    }
+}


Mime
View raw message