sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Avoid to log the same warning twice when the netCDF reader fail to decode a grid mapping.
Date Mon, 27 May 2019 11:07:23 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

commit cb8a759c43ab3f40495801f69fccae2326e39e3d
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon May 27 10:53:01 2019 +0200

    Avoid to log the same warning twice when the netCDF reader fail to decode a grid mapping.
---
 .../apache/sis/internal/netcdf/GridMapping.java    | 37 +++++++++++++++++-----
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridMapping.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridMapping.java
index b6b9d6f..f088b83 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridMapping.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridMapping.java
@@ -128,14 +128,17 @@ final class GridMapping {
             if (gm != null) {
                 return gm;
             }
-            final Node mapping = variable.decoder.findNode(name);
-            if (mapping != null) {
-                gm = parseProjectionParameters(mapping);
-                if (gm == null) {
-                    gm = parseGeoTransform(mapping);
+            /*
+             * Value may be null if we already tried and failed to process that grid.
+             * We detect those cases in order to avoid logging the same warning twice.
+             */
+            if (!gridMapping.containsKey(name)) {
+                final Node mapping = variable.decoder.findNode(name);
+                if (mapping != null) {
+                    gm = parse(mapping);
                 }
+                gridMapping.put(name, gm);                      // Store even if null.
                 if (gm != null) {
-                    gridMapping.put(name, gm);
                     return gm;
                 }
             }
@@ -146,7 +149,12 @@ final class GridMapping {
          */
         GridMapping gm = gridMapping.get(variable);
         if (gm == null) {
-            gm = parseProjectionParameters(variable);
+            final String name = variable.getName();
+            gm = gridMapping.get(name);
+            if (gm == null && !gridMapping.containsKey(name)) {
+                gm = parse(variable);
+                gridMapping.put(name, gm);                      // Store even if null.
+            }
             if (gm == null) {
                 gm = parseNonStandard(variable);
             }
@@ -158,6 +166,19 @@ final class GridMapping {
     }
 
     /**
+     * Parses the map projection parameters defined as attribute associated to the given
variable.
+     * This method tries to parse CF-compliant attributes first. If none are found, non-standard
+     * extensions (for example GDAL usage) are tried next.
+     */
+    private static GridMapping parse(final Node mapping) {
+        GridMapping gm = parseProjectionParameters(mapping);
+        if (gm == null) {
+            gm = parseGeoTransform(mapping);
+        }
+        return gm;
+    }
+
+    /**
      * If the netCDF variable defines explicitly the map projection method and its parameters,
returns those parameters.
      * Otherwise returns {@code null}. The given {@code node} argument is typically a dummy
variable referenced by value
      * of the {@value CF#GRID_MAPPING} attribute on the real data variable (as required by
CF-conventions), but may also
@@ -460,7 +481,7 @@ final class GridMapping {
      * @param  variable  the variable for which to create a grid geometry.
      * @param  template  template to use for completing missing information.
      * @param  anchor    whether we computed "grid to CRS" transform relative to pixel center
or pixel corner.
-     * @return the grid geometry with modified CRS and "grid to CRS" transform, or {@code
null} if case of failure.
+     * @return the grid geometry with modified CRS and "grid to CRS" transform, or {@code
null} in case of failure.
      */
     GridGeometry adaptGridCRS(final Variable variable, final GridGeometry template, final
PixelInCell anchor) {
         CoordinateReferenceSystem givenCRS = crs;


Mime
View raw message