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: Add a convenience method for specifying temporal resolution in metadata.
Date Fri, 26 Oct 2018 16:08: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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 055e4fd  Add a convenience method for specifying temporal resolution in metadata.
055e4fd is described below

commit 055e4fd5a680f54bbf9da4693fe1182530ac97bc
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Oct 26 18:08:24 2018 +0200

    Add a convenience method for specifying temporal resolution in metadata.
---
 .../apache/sis/internal/simple/SimpleDuration.java | 77 ++++++++++++++++++++++
 .../sis/internal/storage/MetadataBuilder.java      | 22 ++++++-
 2 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/SimpleDuration.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/SimpleDuration.java
new file mode 100644
index 0000000..909a3f5
--- /dev/null
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/SimpleDuration.java
@@ -0,0 +1,77 @@
+/*
+ * 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.simple;
+
+import org.apache.sis.internal.util.Numerics;
+import org.opengis.temporal.Duration;
+
+
+/**
+ * A temporary implementation of {@link Duration}.
+ * Will probably be deleted in some future version.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class SimpleDuration implements Duration {
+    /**
+     * Duration in days.
+     */
+    public final double duration;
+
+    /**
+     * Creates a new duration.
+     *
+     * @param  duration  the duration in days.
+     */
+    public SimpleDuration(final double duration) {
+        this.duration = duration;
+    }
+
+    /**
+     * Returns a string representation of this duration.
+     *
+     * @return the duration with its unit of measurement.
+     */
+    @Override
+    public String  toString() {
+        return duration + " days";
+    }
+
+    /**
+     * Returns a hash code value for this duration.
+     */
+    @Override
+    public int hashCode() {
+        return Double.hashCode(duration) ^ 37;
+    }
+
+    /**
+     * Compares this duration with the given object for equality.
+     *
+     * @param  other  the object to compare with this duration.
+     */
+    @Override
+    public boolean equals(final Object other) {
+        if (other instanceof SimpleDuration) {
+            return Numerics.equals(duration, ((SimpleDuration) other).duration);
+        }
+        return false;
+    }
+}
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
index 82070b6..336302c 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
@@ -33,6 +33,7 @@ import javax.measure.quantity.Length;
 import org.opengis.util.MemberName;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
+import org.opengis.geometry.Envelope;
 import org.opengis.geometry.Geometry;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Role;
@@ -65,6 +66,7 @@ import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.geometry.AbstractEnvelope;
+import org.apache.sis.internal.simple.SimpleDuration;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.metadata.iso.DefaultIdentifier;
 import org.apache.sis.metadata.iso.DefaultMetadataScope;
@@ -1758,10 +1760,10 @@ parse:      for (int i = 0; i < length;) {
      * @param  envelope  the extent to add in the metadata, or {@code null} for no-operation.
      * @throws TransformException if an error occurred while converting the given envelope
to extents.
      */
-    public final void addExtent(final AbstractEnvelope envelope) throws TransformException
{
+    public final void addExtent(final Envelope envelope) throws TransformException {
         if (envelope != null) {
             addReferenceSystem(envelope.getCoordinateReferenceSystem());
-            if (!envelope.isAllNaN()) {
+            if (!(envelope instanceof AbstractEnvelope && ((AbstractEnvelope) envelope).isAllNaN()))
{
                 extent().addElements(envelope);
             }
         }
@@ -1978,6 +1980,22 @@ parse:      for (int i = 0; i < length;) {
     }
 
     /**
+     * Adds a temporal resolution in days.
+     * Storage location is:
+     *
+     * <ul>
+     *   <li>{@code metadata/identificationInfo/temporalResolution}</li>
+     * </ul>
+     *
+     * @param  duration  the resolution in days, or {@code NaN} for no-operation.
+     */
+    public final void addTemporalResolution(final double duration) {
+        if (!Double.isNaN(duration)) {
+            addIfNotPresent(identification().getTemporalResolutions(), new SimpleDuration(duration));
+        }
+    }
+
+    /**
      * Sets identification of grid data as point or cell.
      * Storage location is:
      *


Mime
View raw message