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: Fix GCOM-C unit of measurement. Avoid displaying extraneous fraction digits.
Date Fri, 13 Mar 2020 15:56:07 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 19a38a2  Fix GCOM-C unit of measurement. Avoid displaying extraneous fraction digits.
19a38a2 is described below

commit 19a38a2b6791becc92585a9cead4234e2e7cf314
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Mar 13 16:37:14 2020 +0100

    Fix GCOM-C unit of measurement. Avoid displaying extraneous fraction digits.
---
 .../org/apache/sis/gui/coverage/StatusBar.java     | 26 +++++++++++++++++++---
 .../apache/sis/internal/earth/netcdf/GCOM_C.java   | 24 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/StatusBar.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/StatusBar.java
index f3fe06b..4a00b6b 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/StatusBar.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/StatusBar.java
@@ -117,6 +117,16 @@ final class StatusBar extends HBox implements EventHandler<MouseEvent>
{
     private double[] precisions;
 
     /**
+     * A multiplication factory slightly greater than 1 applied on {@link #precisions}.
+     * The intent is to avoid that a precision like 0.09999 is interpreted as requiring
+     * two decimal digits instead of 1. For avoiding that, we add a small value to the
+     * precision: <var>precision</var> += <var>precision</var> ×
ε, which we compact as
+     * <var>precision</var> *= (1 + ε). The ε value is chosen to represent
an increase
+     * of no more than 0.5 pixel between the lower and upper indices of the grid.
+     */
+    private double[] inflatePrecisions;
+
+    /**
      * The object to use for formatting coordinate values.
      */
     private final CoordinateFormat format;
@@ -197,11 +207,18 @@ final class StatusBar extends HBox implements EventHandler<MouseEvent>
{
          * become the coordinates of the original `GridGeometry` before to apply `gridToCRS`.
          */
         if (request != null) {
-            final double[] origin = new double[request.getDimension()];
-            for (int i=0; i<origin.length; i++) {
+            final int n = request.getDimension();
+            if (inflatePrecisions == null || inflatePrecisions.length != n) {
+                inflatePrecisions = new double[n];
+            }
+            final double[] origin = new double[n];
+            for (int i=0; i<n; i++) {
                 origin[i] = request.getLow(i);
+                inflatePrecisions[i] = (0.5 / request.getSize(i)) + 1;
             }
             gridToCRS = MathTransforms.concatenate(MathTransforms.translation(origin), gridToCRS);
+        } else {
+            inflatePrecisions = null;
         }
         /*
          * Prepare objects to be reused for each coordinate transformation.
@@ -263,7 +280,10 @@ final class StatusBar extends HBox implements EventHandler<MouseEvent>
{
                         for (int j=derivative.getNumRow(); --j >= 0;) {
                             double p = 0;
                             for (int i=derivative.getNumCol(); --i >= 0;) {
-                                final double e = Math.abs(derivative.getElement(j, i));
+                                double e = Math.abs(derivative.getElement(j, i));
+                                if (inflatePrecisions != null) {
+                                    e *= inflatePrecisions[i];
+                                }
                                 if (e > p) p = e;
                             }
                             precisions[j] = p;
diff --git a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
index 9d38bf8..9796ffe 100644
--- a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
+++ b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
@@ -22,6 +22,8 @@ import java.util.HashMap;
 import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.regex.Pattern;
+import javax.measure.Unit;
+import javax.measure.format.ParserException;
 import org.opengis.referencing.crs.ProjectedCRS;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
@@ -40,6 +42,7 @@ import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.matrix.Matrix3;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.measure.NumberRange;
+import org.apache.sis.measure.Units;
 import ucar.nc2.constants.CF;
 
 
@@ -486,4 +489,25 @@ public final class GCOM_C extends Convention {
         }
         return tr;
     }
+
+    /**
+     * Returns the unit of measurement to use as a fallback if it can not be determined in
a standard way.
+     *
+     * @param  data  the variable for which to get the unit of measurement.
+     * @return the unit of measurement, or {@code null} if none or unknown.
+     * @throws ParserException if the unit symbol can not be parsed.
+     */
+    @Override
+    public Unit<?> getUnitFallback(final Variable data) throws ParserException {
+        if ("Image_data".equals(data.getGroupName())) {
+            final String symbol = data.getAttributeAsString("Unit");
+            if (symbol != null && !symbol.equalsIgnoreCase("NA")) {
+                if (symbol.equalsIgnoreCase("degree")) {
+                    return Units.CELSIUS;
+                }
+                return Units.valueOf(symbol);
+            }
+        }
+        return super.getUnitFallback(data);
+    }
 }


Mime
View raw message