sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Declare ISO 19115 metadata standards in DataStores that implement some mappings. We omit this declaration when the DataStore has very few reliable information (for example when it tried to guess the FeatureType from a SQL schema), or when the standard may be declared in the parsed data (e.g. a XML file).
Date Mon, 27 May 2019 11:07:22 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 617e2e5fd2200f078810ca0ba46a48d49520291a
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon May 27 10:47:39 2019 +0200

    Declare ISO 19115 metadata standards in DataStores that implement some mappings.
    We omit this declaration when the DataStore has very few reliable information
    (for example when it tried to guess the FeatureType from a SQL schema),
    or when the standard may be declared in the parsed data (e.g. a XML file).
---
 .../org/apache/sis/console/MetadataCommand.java    |  5 ++-
 .../storage/earthobservation/LandsatReader.java    |  3 +-
 .../apache/sis/storage/geotiff/GeoTiffStore.java   |  1 +
 .../apache/sis/storage/netcdf/MetadataReader.java  |  4 ++-
 .../sis/internal/storage/MetadataBuilder.java      | 38 ++++++++++++++++++++--
 .../org/apache/sis/internal/storage/csv/Store.java |  1 +
 .../apache/sis/internal/storage/gpx/Metadata.java  | 13 +++++++-
 7 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
b/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
index 8c40331..d9c540f 100644
--- a/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
+++ b/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
@@ -40,7 +40,7 @@ final class MetadataCommand extends FormattedOutputCommand {
      */
     static EnumSet<Option> options() {
         return EnumSet.of(Option.FORMAT, Option.LOCALE, Option.TIMEZONE,
-                Option.ENCODING, Option.COLORS, Option.HELP, Option.DEBUG);
+                Option.ENCODING, Option.COLORS, Option.VERBOSE, Option.HELP, Option.DEBUG);
     }
 
     /**
@@ -89,6 +89,9 @@ final class MetadataCommand extends FormattedOutputCommand {
      */
     @Override
     Predicate<TreeTable.Node> getNodeFilter() {
+        if (options.containsKey(Option.VERBOSE)) {
+            return null;
+        }
         return (node) -> !"metadataStandard".equals(node.getValue(TableColumn.IDENTIFIER));
     }
 }
diff --git a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
index 2822a97..79170f9 100644
--- a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
+++ b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
@@ -47,7 +47,6 @@ import org.opengis.util.FactoryException;
 import org.apache.sis.measure.Units;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.metadata.iso.DefaultIdentifier;
-import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.content.DefaultAttributeGroup;
 import org.apache.sis.metadata.iso.content.DefaultBand;
 import org.apache.sis.metadata.iso.content.DefaultCoverageDescription;
@@ -954,6 +953,7 @@ final class LandsatReader {
          * then continue adding some more specific metadata elements by ourself. For example
information about
          * bands are splitted in 3 different AttributeGroups based on their grid size.
          */
+        metadata.setISOStandards(true);
         final DefaultMetadata result = metadata.build(false);
         if (result != null) {
             /*
@@ -978,7 +978,6 @@ final class LandsatReader {
                     }
                 }
             }
-            result.setMetadataStandards(Citations.ISO_19115);
             result.transition(DefaultMetadata.State.FINAL);
         }
         return result;
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
index e59a393..31d0191 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
@@ -214,6 +214,7 @@ public class GeoTiffStore extends DataStore implements Aggregate {
             if (id != null) {
                 builder.addTitleOrIdentifier(id.toString(), MetadataBuilder.Scope.ALL);
             }
+            builder.setISOStandards(true);
             metadata = builder.build(true);
         }
         return metadata;
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index 6d34580..9818d05 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -1045,13 +1045,16 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value,
start, lengt
          * Add the dimension information, if any. This metadata node
          * is built from the netCDF CoordinateSystem objects.
          */
+        boolean hasGrids = false;
         for (final Grid cs : decoder.getGrids()) {
             if (cs.getSourceDimensions() >= Grid.MIN_DIMENSION &&
                 cs.getTargetDimensions() >= Grid.MIN_DIMENSION)
             {
                 addSpatialRepresentationInfo(cs);
+                hasGrids = true;
             }
         }
+        setISOStandards(hasGrids);
         addFileIdentifier();
         /*
          * Deperture: UnidataDD2MI.xsl puts the source in Metadata.dataQualityInfo.lineage.statement.
@@ -1065,7 +1068,6 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value,
start, lengt
         }
         decoder.setSearchPath(searchPath);
         final DefaultMetadata metadata = build(false);
-        metadata.setMetadataStandards(Citations.ISO_19115);
         addCompleteMetadata(createURI(stringValue(METADATA_LINK)));
         metadata.transition(DefaultMetadata.State.FINAL);
         return metadata;
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 d80516d..1afdc34 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
@@ -89,6 +89,7 @@ import org.apache.sis.metadata.iso.content.DefaultFeatureCatalogueDescription;
 import org.apache.sis.metadata.iso.content.DefaultRangeElementDescription;
 import org.apache.sis.metadata.iso.content.DefaultImageDescription;
 import org.apache.sis.metadata.iso.content.DefaultFeatureTypeInfo;
+import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.citation.AbstractParty;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
@@ -189,6 +190,15 @@ public class MetadataBuilder {
      */
     private final Map<Object,Object> sharedValues = new HashMap<>();
 
+    /**
+     * Whether to add ISO 19115-1 and ISO 19115-2 entries in "metadata standards" node.
+     * Those entries will be added only if the metadata object would be otherwise non-empty.
+     * A value of 1 will add ISO 19115-1. A value of 2 will add both ISO 19115-1 and ISO
19115-2.
+     *
+     * @see #setISOStandards(boolean)
+     */
+    private byte standardISO;
+
     // Other fields declared below together with closely related methods.
 
     /**
@@ -2933,6 +2943,21 @@ parse:      for (int i = 0; i < length;) {
     }
 
     /**
+     * Sets the metadata standards to ISO 19115-1, and optionally to ISO 19115-2 too.
+     * Those metadata citations are added only if the metadata object is otherwise non-empty.
+     * Storage location is:
+     *
+     * <ul>
+     *   <li>{@code metadata/metadataStandards}</li>
+     * </ul>
+     *
+     * @param  part2  whether to set ISO 19115-2 in addition to ISO 19115-1.
+     */
+    public final void setISOStandards(final boolean part2) {
+        standardISO = part2 ? (byte) 2 : (byte) 1;
+    }
+
+    /**
      * Returns the metadata (optionally as an unmodifiable object), or {@code null} if none.
      * If {@code freeze} is {@code true}, then the returned metadata instance can not be
modified.
      *
@@ -2950,8 +2975,17 @@ parse:      for (int i = 0; i < length;) {
         newLineage();
         final DefaultMetadata md = metadata;
         metadata = null;
-        if (freeze && md != null) {
-            md.transition(DefaultMetadata.State.FINAL);
+        if (md != null) {
+            if (standardISO != 0) {
+                List<Citation> c = Citations.ISO_19115;
+                if (standardISO == 1) {
+                    c = Collections.singletonList(c.get(0));
+                }
+                md.setMetadataStandards(c);
+            }
+            if (freeze) {
+                md.transition(DefaultMetadata.State.FINAL);
+            }
         }
         return md;
     }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
index 4ed2d15..7895203 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
@@ -662,6 +662,7 @@ final class Store extends URIDataStore implements FeatureSet {
             }
             builder.addFeatureType(featureType, null);
             addTitleOrIdentifier(builder);
+            builder.setISOStandards(false);
             metadata = builder.build(true);
         }
         return metadata;
diff --git a/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
b/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
index 6077ce7..7c3daac 100644
--- a/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
+++ b/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Metadata.java
@@ -45,6 +45,7 @@ import org.opengis.util.InternationalString;
 import org.apache.sis.io.TableAppender;
 import org.apache.sis.internal.simple.SimpleMetadata;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
 import org.apache.sis.metadata.iso.identification.DefaultKeywords;
 import org.apache.sis.metadata.iso.extent.Extents;
@@ -81,7 +82,7 @@ import org.opengis.metadata.citation.Responsibility;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.8
  * @module
  */
@@ -422,6 +423,16 @@ public final class Metadata extends SimpleMetadata {
     }
 
     /**
+     * Citation(s) for the standard(s) to which the metadata conform.
+     *
+     * @return ISO 19115-1 citation.
+     */
+    @Override
+    public Collection<Citation> getMetadataStandards() {
+        return Collections.singleton(Citations.ISO_19115.get(0));
+    }
+
+    /**
      * Compares this {@code Metadata} with the given object for equality.
      *
      * @param  obj  the object to compare with this {@code Metadata}.


Mime
View raw message