sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Do not build a GridGeometry if a "resampling_interval" attribute was required but not found.
Date Wed, 20 Feb 2019 22:52:46 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 f8a6001f657fac884d539b278a7e069a7da4e4d6
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Feb 20 23:52:01 2019 +0100

    Do not build a GridGeometry if a "resampling_interval" attribute was required but not
found.
---
 .../main/java/org/apache/sis/internal/netcdf/Convention.java   |  5 ++---
 .../src/main/java/org/apache/sis/internal/netcdf/Variable.java | 10 ++++++++--
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
index 1e57a3f..fc79692 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
@@ -236,11 +236,10 @@ public class Convention {
      * This feature is an extension to CF-conventions.</p>
      *
      * @param  axis  the axis for which to get the "grid indices to data indices" scale factor.
-     * @return the "grid indices to data indices" scale factor, or 1 if none.
+     * @return the "grid indices to data indices" scale factor, or {@link Double#NaN} if
none.
      */
     public double gridToDataIndices(final Variable axis) {
-        final double n = axis.getAttributeAsNumber("resampling_interval");
-        return (n > 0) ? 1/n : 1;
+        return axis.getAttributeAsNumber("resampling_interval");
     }
 
     /**
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 971d233..20bf721 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.internal.netcdf;
 
-import java.util.Arrays;
 import java.util.Set;
 import java.util.Map;
 import java.util.HashSet;
@@ -120,6 +119,9 @@ public abstract class Variable extends NamedElement {
      * This is usually null, meaning that there is an exact match between grid indices and
data indices. This array may
      * be non-null if the localization grid has smaller dimensions than the dimensions of
this variable, as documented
      * in {@link Convention#nameOfDimension(Variable, int)} javadoc.
+     *
+     * <p>Some values in this array may be {@link Double#NaN} if the {@code "resampling_interval"}
attribute
+     * was not found.</p>
      */
     private double[] gridToDataIndices;
 
@@ -408,7 +410,6 @@ public abstract class Variable extends NamedElement {
                                 if (name != null) {
                                     if (gridToDataIndices == null) {
                                         gridToDataIndices = new double[axes.size()];
-                                        Arrays.fill(gridToDataIndices, 1);
                                     }
                                     gridToDataIndices[j] = convention.gridToDataIndices(axis);
                                     final boolean overwrite = isRequested && requestedByConvention.add(dim);
@@ -493,6 +494,11 @@ public abstract class Variable extends NamedElement {
                 }
             }
             if (needsResize) {
+                if (gridToDataIndices != null) {
+                    for (final double s : gridToDataIndices) {
+                        if (!(s > 0)) return null;                  // "resampling_interval"
attributes not found.
+                    }
+                }
                 extent = extent.resize(sizes);
                 grid = grid.derive().resize(extent, gridToDataIndices).build();
                 /*


Mime
View raw message