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: Ensure that netCDF reader can parse at least "degrees_N" and "degree_N" in addition of "degrees_north" and "degree_north" (same for east).
Date Tue, 11 Jun 2019 15:54:11 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 8382160  Ensure that netCDF reader can parse at least "degrees_N" and "degree_N"
in addition of "degrees_north" and "degree_north" (same for east).
8382160 is described below

commit 838216033b257e803e5618089cfb29544606020f
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jun 11 17:53:46 2019 +0200

    Ensure that netCDF reader can parse at least "degrees_N" and "degree_N" in addition of
"degrees_north" and "degree_north" (same for east).
---
 .../java/org/apache/sis/measure/UnitsTest.java     |  5 +++
 .../java/org/apache/sis/internal/netcdf/Axis.java  |  9 +++-
 .../org/apache/sis/internal/netcdf/AxisTest.java   | 49 ++++++++++++++++++++++
 .../apache/sis/internal/netcdf/VariableTest.java   | 18 ++++++++
 .../org/apache/sis/test/suite/NetcdfTestSuite.java |  1 +
 5 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java b/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
index cde077a..f2747b3 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
@@ -283,6 +283,11 @@ public final strictfp class UnitsTest extends TestCase {
         assertSame(DEGREE,       valueOf("degrees_east"));
         assertSame(DEGREE,       valueOf("degrees_north"));
         assertSame(DEGREE,       valueOf("degrées_north"));
+        assertSame(DEGREE,       valueOf("degree_north"));
+        assertSame(DEGREE,       valueOf("degrees_N"));
+        assertSame(DEGREE,       valueOf("degree_N"));
+        assertSame(DEGREE,       valueOf("degreesN"));
+        assertSame(DEGREE,       valueOf("degreeN"));
         assertSame(DEGREE,       valueOf("decimal_degree"));
         assertSame(ARC_SECOND,   valueOf("arcsec"));
         assertSame(RADIAN,       valueOf("rad"));
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index 00f359b..402da81 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -234,7 +234,14 @@ public final class Axis extends NamedElement {
                 s = unit.indexOf(' ');
             }
             if (s > 0) {
-                return Types.forCodeName(AxisDirection.class, unit.substring(s+1), false);
+                final String direction = unit.substring(s+1);
+                if (direction.length() == 1) {
+                    switch (Character.toUpperCase(direction.charAt(0))) {
+                        case 'E': return AxisDirection.EAST;
+                        case 'N': return AxisDirection.NORTH;
+                    }
+                }
+                return Types.forCodeName(AxisDirection.class, direction, false);
             }
         }
         return null;
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/AxisTest.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/AxisTest.java
new file mode 100644
index 0000000..6e33d29
--- /dev/null
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/AxisTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.internal.netcdf;
+
+import org.opengis.referencing.cs.AxisDirection;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link Axis}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.7
+ * @since   0.3
+ * @module
+ */
+public final strictfp class AxisTest extends TestCase {
+    /**
+     * Tests {@link Axis#direction(String)}.
+     */
+    @Test
+    public void testDirection() {
+        assertSame(AxisDirection.EAST,  Axis.direction("degrees_east"));
+        assertSame(AxisDirection.NORTH, Axis.direction("degrees_north"));
+        assertSame(AxisDirection.EAST,  Axis.direction("degree_east"));
+        assertSame(AxisDirection.NORTH, Axis.direction("degree_north"));
+        assertSame(AxisDirection.EAST,  Axis.direction("degrees_E"));
+        assertSame(AxisDirection.NORTH, Axis.direction("degrees_N"));
+        assertSame(AxisDirection.EAST,  Axis.direction("degree_E"));
+        assertSame(AxisDirection.NORTH, Axis.direction("degree_N"));
+    }
+}
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
index 5572cc0..d13313a 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
@@ -146,6 +146,24 @@ public strictfp class VariableTest extends TestCase {
     @Test
     public void testParseUnit() throws Exception {
         final Variable variable = selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getVariables()[0];
+        /*
+         * From CF-Conventions:
+         * The recommended unit of latitude is degrees_north. Also acceptable are degree_north,
degree_N, degrees_N, degreeN, and degreesN.
+         * The recommended unit of longitude is degrees_east. Also acceptable are degree_east,
degree_E, degrees_E, degreeE, and degreesE.
+         */
+        assertSame(Units.DEGREE, variable.parseUnit("degrees_north"));
+        assertSame(Units.DEGREE, variable.parseUnit("degrees_east"));
+        assertSame(Units.DEGREE, variable.parseUnit("degree_north"));
+        assertSame(Units.DEGREE, variable.parseUnit("degree_east"));
+        assertSame(Units.DEGREE, variable.parseUnit("degrees_N"));
+        assertSame(Units.DEGREE, variable.parseUnit("degrees_E"));
+        assertSame(Units.DEGREE, variable.parseUnit("degree_N"));
+        assertSame(Units.DEGREE, variable.parseUnit("degree_E"));
+        assertSame(Units.DEGREE, variable.parseUnit("degreesN"));
+        assertSame(Units.DEGREE, variable.parseUnit("degreesE"));
+        assertSame(Units.DEGREE, variable.parseUnit("degreeN"));
+        assertSame(Units.DEGREE, variable.parseUnit("degreeE"));
+
         assertSame(Units.SECOND, variable.parseUnit("s"));
         assertSame(Units.SECOND, variable.parseUnit("second"));
         assertSame(Units.SECOND, variable.parseUnit("seconds"));
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
index 90537e9..b3d3495 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
@@ -33,6 +33,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.netcdf.DataTypeTest.class,
     org.apache.sis.internal.netcdf.DecoderTest.class,
     org.apache.sis.internal.netcdf.VariableTest.class,
+    org.apache.sis.internal.netcdf.AxisTest.class,
     org.apache.sis.internal.netcdf.GridTest.class,
     org.apache.sis.internal.netcdf.SatelliteGroundTrackTest.class,
     org.apache.sis.internal.netcdf.impl.ChannelDecoderTest.class,


Mime
View raw message