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 fc849c95c36ef2914873646e44e7a2bcf18f38be
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Sat Feb 26 17:33:06 2022 +0100

    Try harder to determine if a netCDF variable is an axis.
---
 .../java/org/apache/sis/internal/netcdf/Convention.java     |  4 +---
 .../main/java/org/apache/sis/internal/netcdf/Variable.java  |  7 +++++--
 .../org/apache/sis/internal/netcdf/impl/VariableInfo.java   | 10 +++++++---
 .../apache/sis/internal/netcdf/ucar/VariableWrapper.java    | 13 +++++++++----
 4 files changed, 22 insertions(+), 12 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 0fd1d73..b8449c2 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,9 +236,7 @@ public class Convention {
         }
         final int n = variable.getNumDimensions();
         if (n == 1) {
-            if (variable.getAxisType() == null && 
variable.getAttributeValue(CF.AXIS) == null) {
-                return VariableRole.FEATURE;
-            }
+            return VariableRole.FEATURE;
         } else if (n != 0) {
             final DataType dataType = variable.getDataType();
             int numVectors = 0;                 // Number of dimension having 
more than 1 value.
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 f002f85..201b56b 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
@@ -501,6 +501,8 @@ public abstract class Variable extends Node {
     /**
      * Returns whether this variable is used as a coordinate system axis.
      * By netCDF convention, coordinate system axes have the name of one of 
the dimensions defined in the netCDF header.
+     * It may also be identified by the {@code "axis"} on this variable, or by 
the {@code "coordinates"} attributes on
+     * other variables.
      *
      * <p>This method has protected access because it should not be invoked 
directly. Code using variable role should
      * invoke {@link Convention#roleOf(Variable)} instead, for allowing 
specialization by {@link Convention}.</p>
@@ -512,9 +514,10 @@ public abstract class Variable extends Node {
     protected abstract boolean isCoordinateSystemAxis();
 
     /**
-     * Returns the value of {@code "_CoordinateAxisType"} attribute.
+     * Returns the value of {@code "_CoordinateAxisType"} or {@code "axis"} 
attribute, or {@code null} if none.
+     * Note that a {@code null} value does not mean that this variable is not 
an axis.
      *
-     * @return Value of {@code "_CoordinateAxisType"} attribute, or {@code 
null} if none.
+     * @return {@code "_CoordinateAxisType"} or {@code "axis"} attribute 
value, or {@code null} if none.
      */
     protected abstract String getAxisType();
 
diff --git 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index 17534ce..fcc5f72 100644
--- 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -67,7 +67,7 @@ import org.apache.sis.math.Vector;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   0.3
  * @module
  */
@@ -491,11 +491,15 @@ final class VariableInfo extends Variable implements 
Comparable<VariableInfo> {
     }
 
     /**
-     * Returns the value of the {@code "_CoordinateAxisType"} attribute, or 
{@code null} if none.
+     * Returns the value of the {@code "_CoordinateAxisType"} or {@code 
"axis"} attribute, or {@code null} if none.
+     * Note that a {@code null} value does not mean that this variable is not 
an axis.
      */
     @Override
     protected String getAxisType() {
-        final Object value = getAttributeValue(_Coordinate.AxisType, 
"_coordinateaxistype");
+        Object value = getAttributeValue(_Coordinate.AxisType, 
"_coordinateaxistype");
+        if (value == null) {
+            value = getAttributeValue(CF.AXIS);
+        }
         return (value != null) ? value.toString() : null;
     }
 
diff --git 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
index 9bae8f6..8a2e4cd 100644
--- 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
+++ 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
@@ -53,6 +53,7 @@ import org.apache.sis.measure.MeasurementRange;
 import org.apache.sis.measure.NumberRange;
 import org.apache.sis.measure.Units;
 import ucar.nc2.constants.AxisType;
+import ucar.nc2.constants.CF;
 
 
 /**
@@ -60,7 +61,7 @@ import ucar.nc2.constants.AxisType;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   0.3
  * @module
  */
@@ -230,11 +231,14 @@ final class VariableWrapper extends 
org.apache.sis.internal.netcdf.Variable {
     @Override
     protected boolean isCoordinateSystemAxis() {
         // `isCoordinateVariable()` is not sufficient in the case of "runtime" 
axis.
-        return variable.isCoordinateVariable() || (variable instanceof 
CoordinateAxis);
+        return variable.isCoordinateVariable() || (variable instanceof 
CoordinateAxis)
+                || variable.hasAttribute(_Coordinate.AxisType)
+                || variable.hasAttribute(CF.AXIS);
     }
 
     /**
-     * Returns the value of the {@code "_CoordinateAxisType"} attribute, or 
{@code null} if none.
+     * Returns the value of the {@code "_CoordinateAxisType"} or {@code 
"axis"} attribute, or {@code null} if none.
+     * Note that a {@code null} value does not mean that this variable is not 
an axis.
      */
     @Override
     protected String getAxisType() {
@@ -244,7 +248,8 @@ final class VariableWrapper extends 
org.apache.sis.internal.netcdf.Variable {
                 return type.name();
             }
         }
-        return getAttributeAsString(_Coordinate.AxisType);
+        final String type = getAttributeAsString(_Coordinate.AxisType);
+        return (type != null) ? type : getAttributeAsString(CF.AXIS);
     }
 
     /**

Reply via email to