sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1798308 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/ storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/ storage/sis-geotiff/src/main/java/org/apache/sis/sto...
Date Sat, 10 Jun 2017 12:15:26 GMT
Author: desruisseaux
Date: Sat Jun 10 12:15:26 2017
New Revision: 1798308

URL: http://svn.apache.org/viewvc?rev=1798308&view=rev
Log:
Use MetadataBuilder for "spatial representation info" ISO 19115 node created from NetCDF files.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
    sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java?rev=1798308&r1=1798307&r2=1798308&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
[UTF-8] Sat Jun 10 12:15:26 2017
@@ -244,12 +244,12 @@ public class DefaultDimension extends IS
     }
 
     /**
-     * Returns the enhancement/ modifier of the dimension name.
+     * Returns the enhancement / modifier of the dimension name.
      *
      * <div class="note"><b>Example:</b>
      * dimensionName = "column", dimensionTitle = "longitude"</div>
      *
-     * @return the enhancement/ modifier of the dimension name.
+     * @return the enhancement / modifier of the dimension name.
      *
      * @since 0.5
      */
@@ -260,9 +260,9 @@ public class DefaultDimension extends IS
     }
 
     /**
-     * Sets the enhancement/ modifier of the dimension name.
+     * Sets the enhancement / modifier of the dimension name.
      *
-     * @param  newValue  the new enhancement/ modifier of the dimension name.
+     * @param  newValue  the new enhancement / modifier of the dimension name.
      *
      * @since 0.5
      */

Modified: sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java?rev=1798308&r1=1798307&r2=1798308&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
[UTF-8] Sat Jun 10 12:15:26 2017
@@ -932,11 +932,11 @@ final class LandsatReader {
             final int width  = gridSizes[i  ];
             final int height = gridSizes[i+1];
             if (width != 0 || height != 0) {
-                metadata.newGridRepresentation();
-                metadata.setAxisName((short) 0, DimensionNameType.SAMPLE);
-                metadata.setAxisName((short) 1, DimensionNameType.LINE);
-                metadata.setAxisLength((short) 0, width);
-                metadata.setAxisLength((short) 1, height);
+                metadata.newGridRepresentation(MetadataBuilder.GridType.GEORECTIFIED);
+                metadata.setAxisName(0, DimensionNameType.SAMPLE);
+                metadata.setAxisName(1, DimensionNameType.LINE);
+                metadata.setAxisLength(0, width);
+                metadata.setAxisLength(1, height);
             }
         }
         /*

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java?rev=1798308&r1=1798307&r2=1798308&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
[UTF-8] Sat Jun 10 12:15:26 2017
@@ -748,6 +748,7 @@ final class CRSBuilder {
      * @throws NumberFormatException if a numeric value was stored as a string and can not
be parsed.
      */
     final void complete(final MetadataBuilder metadata) {
+        metadata.newGridRepresentation(MetadataBuilder.GridType.GEORECTIFIED);
         /*
          * ASCII reference to published documentation on the overall configuration of the
GeoTIFF file.
          * Often the projected CRS name, despite GeoKeys.PCSCitation being already for that
purpose.

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java?rev=1798308&r1=1798307&r2=1798308&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
[UTF-8] Sat Jun 10 12:15:26 2017
@@ -50,7 +50,6 @@ import org.opengis.referencing.crs.Verti
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.metadata.iso.DefaultMetadata;
-import org.apache.sis.metadata.iso.spatial.*;
 import org.apache.sis.metadata.iso.citation.*;
 import org.apache.sis.metadata.iso.identification.*;
 import org.apache.sis.metadata.iso.lineage.DefaultLineage;
@@ -625,33 +624,29 @@ split:  while ((start = CharSequences.sk
     }
 
     /**
-     * Creates a {@code <gmd:spatialRepresentationInfo>} element from the given grid
geometries.
+     * Adds information about axes and cell geometry.
+     * This is the {@code <gmd:spatialRepresentationInfo>} element in XML.
      *
      * @param  cs  the grid geometry (related to the NetCDF coordinate system).
-     * @return the grid spatial representation info.
      */
-    private GridSpatialRepresentation createSpatialRepresentationInfo(final GridGeometry
cs) {
-        final DefaultGridSpatialRepresentation grid = new DefaultGridSpatialRepresentation();
-        grid.setNumberOfDimensions(cs.getTargetDimensions());
+    private void addSpatialRepresentationInfo(final GridGeometry cs) {
         final Axis[] axes = cs.getAxes();
-        for (int i=axes.length; --i>=0;) {
-            final Axis axis = axes[i];
-            if (axis.sourceDimensions.length != 0) {
-                final DefaultDimension dimension = new DefaultDimension();
-                dimension.setDimensionSize(axis.sourceSizes[0]);
-                final AttributeNames.Dimension attributeNames = axis.attributeNames;
-                if (attributeNames != null) {
-                    dimension.setDimensionName(attributeNames.DEFAULT_NAME_TYPE);
-                    final Number value = decoder.numericValue(attributeNames.RESOLUTION);
-                    if (value != null) {
-                        dimension.setResolution((value instanceof Double) ? (Double) value
: value.doubleValue());
-                    }
+        for (int i=axes.length; i>0;) {
+            final int dim = axes.length - i;
+            final Axis axis = axes[--i];
+            if (axis.sourceSizes.length == 1) {
+                setAxisLength(dim, axis.sourceSizes[0]);
+            }
+            final AttributeNames.Dimension attributeNames = axis.attributeNames;
+            if (attributeNames != null) {
+                setAxisName(dim, attributeNames.DEFAULT_NAME_TYPE);
+                final Number value = decoder.numericValue(attributeNames.RESOLUTION);
+                if (value != null) {
+                    setAxisResolution(dim, value.doubleValue());
                 }
-                grid.getAxisDimensionProperties().add(dimension);
             }
         }
-        grid.setCellGeometry(CellGeometry.AREA);
-        return grid;
+        setCellGeometry(CellGeometry.AREA);
     }
 
     /**
@@ -754,7 +749,7 @@ split:  while ((start = CharSequences.sk
     }
 
     /**
-     * Adds information about all NetCDF variables. This is the {@code <gmd:contentInfo>}
elements in GML.
+     * Adds information about all NetCDF variables. This is the {@code <gmd:contentInfo>}
element in XML.
      * This method groups variables by their domains, i.e. variables having the same set
of axes are grouped together.
      */
     private void addContentInfo() {
@@ -794,7 +789,7 @@ split:  while ((start = CharSequences.sk
 
     /**
      * Adds metadata about a sample dimension (or band) from the given variable.
-     * This is the {@code <gmd:dimension>} element in GML.
+     * This is the {@code <gmd:dimension>} element in XML.
      *
      * @param  variable  the NetCDF variable.
      */
@@ -834,7 +829,7 @@ split:  while ((start = CharSequences.sk
 
     /**
      * Adds metadata about the meaning of a sample value.
-     * This is the {@code <gmd:rangeElementDescription>} element in GML.
+     * This is the {@code <gmd:rangeElementDescription>} element in XML.
      *
      * <p><b>Note:</b> ISO 19115 range elements are approximatively equivalent
to
      * {@code org.apache.sis.coverage.Category} in the {@code sis-coverage} module.</p>
@@ -892,6 +887,15 @@ split:  while ((start = CharSequences.sk
         }
         addContentInfo();
         /*
+         * Add the dimension information, if any. This metadata node
+         * is built from the NetCDF CoordinateSystem objects.
+         */
+        for (final GridGeometry cs : decoder.getGridGeometries()) {
+            if (cs.getSourceDimensions() >= Variable.MIN_DIMENSION && cs.getTargetDimensions()
>= Variable.MIN_DIMENSION) {
+                addSpatialRepresentationInfo(cs);
+            }
+        }
+        /*
          * Add history in Metadata.dataQualityInfo.lineage.statement as specified by UnidataDD2MI.xsl.
          * However Metadata.resourceLineage.statement could be a more appropriate place.
          * See https://issues.apache.org/jira/browse/SIS-361
@@ -909,15 +913,6 @@ split:  while ((start = CharSequences.sk
             }
         }
         decoder.setSearchPath(searchPath);
-        /*
-         * Add the dimension information, if any. This metadata node
-         * is built from the NetCDF CoordinateSystem objects.
-         */
-        for (final GridGeometry cs : decoder.getGridGeometries()) {
-            if (cs.getSourceDimensions() >= Variable.MIN_DIMENSION && cs.getTargetDimensions()
>= Variable.MIN_DIMENSION) {
-                metadata.getSpatialRepresentationInfo().add(createSpatialRepresentationInfo(cs));
-            }
-        }
         metadata.setMetadataStandards(Citations.ISO_19115);
         return metadata;
     }

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1798308&r1=1798307&r2=1798308&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] Sat Jun 10 12:15:26 2017
@@ -61,8 +61,10 @@ import org.apache.sis.metadata.iso.exten
 import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
 import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.extent.DefaultGeographicDescription;
+import org.apache.sis.metadata.iso.spatial.DefaultGridSpatialRepresentation;
 import org.apache.sis.metadata.iso.spatial.DefaultDimension;
 import org.apache.sis.metadata.iso.spatial.DefaultGeorectified;
+import org.apache.sis.metadata.iso.spatial.DefaultGeoreferenceable;
 import org.apache.sis.metadata.iso.content.DefaultAttributeGroup;
 import org.apache.sis.metadata.iso.content.DefaultSampleDimension;
 import org.apache.sis.metadata.iso.content.DefaultCoverageDescription;
@@ -128,6 +130,14 @@ public class MetadataBuilder {
     private PartyType partyType = PartyType.UNKNOWN;
 
     /**
+     * Whether the next grid should be an instance of {@link DefaultGeorectified} or {@link
DefaultGeoreferenceable}.
+     *
+     * @see #gridRepresentation()
+     * @see #newGridRepresentation(GridType)
+     */
+    private GridType gridType = GridType.UNSPECIFIED;
+
+    /**
      * {@code true} if the next {@code CoverageDescription} to create will be a description
of measurements
      * in the electromagnetic spectrum. In that case, the coverage description will actually
be an instance
      * of {@code ImageDescription}.
@@ -405,17 +415,21 @@ public class MetadataBuilder {
     /**
      * Information about the grid shape, or {@code null} if none.
      */
-    private DefaultGeorectified gridRepresentation;
+    private DefaultGridSpatialRepresentation gridRepresentation;
 
     /**
      * Creates a grid representation object if it does not already exists, then returns it.
      *
      * @return the grid representation object (never {@code null}).
-     * @see #newGridRepresentation()
+     * @see #newGridRepresentation(GridType)
      */
-    private DefaultGeorectified gridRepresentation() {
+    private DefaultGridSpatialRepresentation gridRepresentation() {
         if (gridRepresentation == null) {
-            gridRepresentation = new DefaultGeorectified();
+            switch (gridType) {
+                case GEORECTIFIED:     gridRepresentation = new DefaultGeorectified(); break;
+                case GEOREFERENCEABLE: gridRepresentation = new DefaultGeoreferenceable();
break;
+                default:               gridRepresentation = new DefaultGridSpatialRepresentation();
break;
+            }
         }
         return gridRepresentation;
     }
@@ -698,14 +712,38 @@ public class MetadataBuilder {
     }
 
     /**
+     * The type of grid spatial representation (georectified, georeferenceable or unspecified).
+     */
+    public enum GridType {
+        /**
+         * Grid is an instance of {@link org.opengis.metadata.spatial.Georectified}.
+         */
+        GEORECTIFIED,
+
+        /**
+         * Grid is an instance of {@link org.opengis.metadata.spatial.Georeferenceable}.
+         */
+        GEOREFERENCEABLE,
+
+        /**
+         * Grid is neither georectified or georeferenceable.
+         * A plain {@link org.opengis.metadata.spatial.GridSpatialRepresentation} instance
will be used.
+         */
+        UNSPECIFIED
+    }
+
+    /**
      * Commits all pending information under the metadata "spatial representation" node (dimensions,
<i>etc</i>).
      * If there is no pending spatial representation information, then invoking this method
has no effect.
      * If new spatial representation info are added after this method call, they will be
stored in a new element.
      *
      * <p>This method does not need to be invoked unless a new "spatial representation
info" node,
      * separated from the previous one, is desired.</p>
+     *
+     * @param type  whether the next grid should be an instance of {@link DefaultGeorectified}
or {@link DefaultGeoreferenceable}.
      */
-    public final void newGridRepresentation() {
+    public final void newGridRepresentation(final GridType type) {
+        ArgumentChecks.ensureNonNull("type", type);
         if (gridRepresentation != null) {
             final int n = gridRepresentation.getAxisDimensionProperties().size();
             if (n != 0) {
@@ -714,6 +752,7 @@ public class MetadataBuilder {
             addIfNotPresent(metadata.getSpatialRepresentationInfo(), gridRepresentation);
             gridRepresentation = null;
         }
+        gridType = type;
     }
 
     /**
@@ -1145,8 +1184,7 @@ public class MetadataBuilder {
                     if (list == null) {
                         group = new DefaultKeywords();
                         group.setType(type);
-                        final InternationalString c = trim(thesaurusName);
-                        group.setThesaurusName(sharedCitation(c));
+                        group.setThesaurusName(sharedCitation(trim(thesaurusName)));
                         list = group.getKeywords();
                     }
                     list.add(i18n);
@@ -1752,7 +1790,7 @@ parse:      for (int i = 0; i < length;)
      */
     public final void setPointInPixel(final PixelOrientation value) {
         if (value != null) {
-            gridRepresentation().setPointInPixel(value);
+            ((DefaultGeorectified) gridRepresentation()).setPointInPixel(value);
         }
     }
 
@@ -1769,7 +1807,7 @@ parse:      for (int i = 0; i < length;)
     public final void setGridToCRS(final CharSequence value) {
         final InternationalString i18n = trim(value);
         if (i18n != null) {
-            gridRepresentation().setTransformationDimensionDescription(i18n);
+            ((DefaultGeorectified) gridRepresentation()).setTransformationDimensionDescription(i18n);
         }
     }
 
@@ -1779,7 +1817,7 @@ parse:      for (int i = 0; i < length;)
      * @param  index  index of the desired dimension.
      * @return dimension at the given index.
      */
-    private DefaultDimension axis(final short index) {
+    private DefaultDimension axis(final int index) {
         final List<Dimension> axes = gridRepresentation().getAxisDimensionProperties();
         for (int i=axes.size(); i <= index; i++) {
             axes.add(new DefaultDimension());
@@ -1795,10 +1833,10 @@ parse:      for (int i = 0; i < length;)
      *   <li>{@code metadata/spatialRepresentationInfo/axisDimensionProperties/dimensionName}</li>
      * </ul>
      *
-     * @param  dimension  the axis dimension, as a {@code short} for avoiding excessive values.
+     * @param  dimension  the axis dimension.
      * @param  name       the name to set for the given dimension.
      */
-    public final void setAxisName(final short dimension, final DimensionNameType name) {
+    public final void setAxisName(final int dimension, final DimensionNameType name) {
         axis(dimension).setDimensionName(name);
     }
 
@@ -1810,14 +1848,31 @@ parse:      for (int i = 0; i < length;)
      *   <li>{@code metadata/spatialRepresentationInfo/axisDimensionProperties/dimensionSize}</li>
      * </ul>
      *
-     * @param  dimension  the axis dimension, as a {@code short} for avoiding excessive values.
+     * @param  dimension  the axis dimension.
      * @param  length     number of cell values along the given dimension.
      */
-    public final void setAxisLength(final short dimension, final int length) {
+    public final void setAxisLength(final int dimension, final int length) {
         axis(dimension).setDimensionSize(shared(length));
     }
 
     /**
+     * Sets the degree of detail in the given dimension.
+     * Storage location is:
+     *
+     * <ul>
+     *   <li>{@code metadata/spatialRepresentationInfo/axisDimensionProperties/resolution}</li>
+     * </ul>
+     *
+     * @param  dimension   the axis dimension.
+     * @param  resolution  the degree of detail in the grid dataset, or NaN for no-operation.
+     */
+    public final void setAxisResolution(final int dimension, final double resolution) {
+        if (!Double.isNaN(resolution)) {
+            axis(dimension).setResolution(shared(resolution));
+        }
+    }
+
+    /**
      * Sets the name or number that uniquely identifies instances of bands of wavelengths
on which a sensor operates.
      * If a coverage contains more than one band, additional bands can be created by calling
      * {@link #newSampleDimension()} before to call this method.
@@ -2300,7 +2355,7 @@ parse:      for (int i = 0; i < length;)
      */
     public final DefaultMetadata build(final boolean freeze) {
         newIdentification();
-        newGridRepresentation();
+        newGridRepresentation(GridType.UNSPECIFIED);
         newFeatureTypes();
         newCoverage(false);
         newAcquisition();



Mime
View raw message