sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Use an EngineeringCRS fallback when a TemporalCRS can not be created because of unknown temporal datum epoch.
Date Tue, 20 Oct 2020 22:35:40 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 9079a67464bd5d9571804566e01e2343fc6a3ecd
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Oct 21 00:34:45 2020 +0200

    Use an EngineeringCRS fallback when a TemporalCRS can not be created because of unknown
temporal datum epoch.
---
 .../java/org/apache/sis/referencing/CommonCRS.java | 39 ++++++++++++++++++----
 .../org/apache/sis/internal/netcdf/CRSBuilder.java | 27 ++++++++++-----
 2 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
index f779f13..aee861f 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
@@ -43,6 +43,7 @@ import org.opengis.referencing.cs.CartesianCS;
 import org.opengis.referencing.cs.SphericalCS;
 import org.opengis.referencing.cs.EllipsoidalCS;
 import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.datum.Datum;
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.GeodeticDatum;
@@ -1847,7 +1848,22 @@ public enum CommonCRS {
          *   <tr><th>Unit:</th> <td>{@link Units#UNITY}</td></tr>
          * </table></blockquote>
          */
-        GRID(new DefaultEngineeringDatum(singletonMap(EngineeringDatum.NAME_KEY, "Cell indices")));
+        GRID(new DefaultEngineeringDatum(singletonMap(EngineeringDatum.NAME_KEY, "Cell indices"))),
+
+        /**
+         * A single-dimensional coordinate system for time in seconds since an unknown epoch.
+         * This definition can be used as a fallback when {@link Temporal} enumeration can
not be used,
+         * for example because the temporal datum epoch is unknown.
+         *
+         * <blockquote><table class="compact">
+         * <caption>Time properties</caption>
+         *   <tr><th>Primary names:</th> <td>"Time"</td></tr>
+         *   <tr><th>Direction:</th>
+         *     <td>{@link AxisDirection#FUTURE}</td></tr>
+         *   <tr><th>Unit:</th> <td>{@link Units#SECOND}</td></tr>
+         * </table></blockquote>
+         */
+        TIME(new DefaultEngineeringDatum(singletonMap(EngineeringDatum.NAME_KEY, "Time")));
 
         /**
          * The datum.
@@ -1875,8 +1891,9 @@ public enum CommonCRS {
             if (crs == null) {
                 final String x, y;
                 final AxisDirection dx, dy;
-                final Map<String,Object> cs = singletonMap(CartesianCS.NAME_KEY, datum.getName());
-                final Map<String,Object> properties = new HashMap<>(cs);
+                final Map<String,Object> pcs = singletonMap(CartesianCS.NAME_KEY, datum.getName());
+                final Map<String,Object> properties = new HashMap<>(pcs);
+                CoordinateSystem cs = null;
                 switch (this) {
                     case GEODISPLAY: {
                         x = "i"; dx = AxisDirection.EAST;
@@ -1894,11 +1911,21 @@ public enum CommonCRS {
                         y = "j"; dy = AxisDirection.ROW_POSITIVE;
                         break;
                     }
+                    case TIME: {
+                        x  = y  = "t";
+                        dx = dy = AxisDirection.FUTURE;
+                        cs = new DefaultTimeCS(pcs, new DefaultCoordinateSystemAxis(
+                                singletonMap(TimeCS.NAME_KEY, x), x, dx, Units.SECOND));
+                        break;
+                    }
                     default: throw new AssertionError(this);
                 }
-                crs = new DefaultEngineeringCRS(properties, datum, new DefaultCartesianCS(cs,
-                        new DefaultCoordinateSystemAxis(singletonMap(CartesianCS.NAME_KEY,
x), x, dx, Units.PIXEL),
-                        new DefaultCoordinateSystemAxis(singletonMap(CartesianCS.NAME_KEY,
y), y, dy, Units.PIXEL)));
+                if (cs == null) {
+                    cs = new DefaultCartesianCS(pcs,
+                            new DefaultCoordinateSystemAxis(singletonMap(CartesianCS.NAME_KEY,
x), x, dx, Units.PIXEL),
+                            new DefaultCoordinateSystemAxis(singletonMap(CartesianCS.NAME_KEY,
y), y, dy, Units.PIXEL));
+                }
+                crs = new DefaultEngineeringCRS(properties, datum, cs);
             }
             return crs;
         }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/CRSBuilder.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/CRSBuilder.java
index 255bad3..7fb9c1c 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/CRSBuilder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/CRSBuilder.java
@@ -806,17 +806,21 @@ previous:   for (int i=components.size(); --i >= 0;) {
 
         /**
          * Creates a {@link TemporalDatum} for <cite>"Unknown datum based on …"</cite>.
+         * This method may left the datum to {@code null} if the epoch is unknown.
+         * In such case, {@link #createCRS createCRS(…)} will create an engineering CRS
instead.
          */
         @Override void createDatum(DatumFactory factory, Map<String,?> properties)
throws FactoryException {
             final Axis axis = getFirstAxis();
             axis.getUnit();                                     // Force epoch parsing if
not already done.
-            Instant epoch = axis.coordinates.epoch;
-            final CommonCRS.Temporal c = CommonCRS.Temporal.forEpoch(epoch);
-            if (c != null) {
-                datum = c.datum();
-            } else {
-                properties = properties("Time since " + epoch);
-                datum = factory.createTemporalDatum(properties, TemporalUtilities.toDate(epoch));
+            final Instant epoch = axis.coordinates.epoch;
+            if (epoch != null) {
+                final CommonCRS.Temporal c = CommonCRS.Temporal.forEpoch(epoch);
+                if (c != null) {
+                    datum = c.datum();
+                } else {
+                    properties = properties("Time since " + epoch);
+                    datum = factory.createTemporalDatum(properties, TemporalUtilities.toDate(epoch));
+                }
             }
         }
 
@@ -831,10 +835,17 @@ previous:   for (int i=components.size(); --i >= 0;) {
 
         /**
          * Creates the coordinate reference system from datum and coordinate system computed
in previous steps.
+         * It should be a temporal CRS. But if the temporal datum can not be created because
epoch was unknown,
+         * this method fallbacks on an engineering CRS.
          */
         @Override void createCRS(CRSFactory factory, Map<String,?> properties) throws
FactoryException {
             properties = properties(getFirstAxis().coordinates.getUnitsString());
-            referenceSystem =  factory.createTemporalCRS(properties, datum, coordinateSystem);
+            if (datum != null) {
+                referenceSystem =  factory.createTemporalCRS(properties, datum, coordinateSystem);
+            } else {
+                referenceSystem =  factory.createEngineeringCRS(properties,
+                        CommonCRS.Engineering.TIME.datum(), coordinateSystem);
+            }
         }
     }
 


Mime
View raw message