sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1801065 - in /sis/branches/JDK8/storage: sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ sis-storage/src/main/java/org/apache/sis/internal/storage/
Date Thu, 06 Jul 2017 14:40:35 GMT
Author: desruisseaux
Date: Thu Jul  6 14:40:34 2017
New Revision: 1801065

URL: http://svn.apache.org/viewvc?rev=1801065&view=rev
Log:
Store the GeoTIFF check points in metadata (under some conditions, we need to avoid that if
too numerous).
Avoid a warning if the GeoTIFF file said that it does not define the prime meridian but nevertheless
contains a tag for the prime meridian longitude.

Modified:
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometry.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java

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=1801065&r1=1801064&r2=1801065&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] Thu Jul  6 14:40:34 2017
@@ -914,13 +914,13 @@ final class CRSBuilder {
     private PrimeMeridian createPrimeMeridian(final String[] names, final Unit<Angle>
unit) throws FactoryException {
         final int epsg = getAsInteger(GeoKeys.PrimeMeridian);
         switch (epsg) {
-            case GeoCodes.undefined: {
-                break;                      // If not specified, default to Greenwich.
-            }
+            case GeoCodes.undefined:      // If not specified, should default to Greenwich
but we nevertheless verify.
             case GeoCodes.userDefined: {
                 final double longitude = getAsDouble(GeoKeys.PrimeMeridianLong);
                 if (Double.isNaN(longitude)) {
-                    missingValue(GeoKeys.PrimeMeridianLong);
+                    if (epsg != GeoCodes.undefined) {
+                        missingValue(GeoKeys.PrimeMeridianLong);
+                    }
                 } else if (longitude != 0) {
                     /*
                      * If the prime meridian is not Greenwich, create that meridian but do
not use the

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometry.java?rev=1801065&r1=1801064&r2=1801065&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometry.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometry.java
[UTF-8] Thu Jul  6 14:40:34 2017
@@ -28,6 +28,7 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.builder.LocalizationGridBuilder;
 import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
+import org.apache.sis.internal.storage.MetadataBuilder;
 import org.apache.sis.internal.util.DoubleDouble;
 import org.apache.sis.math.Vector;
 
@@ -119,6 +120,18 @@ final class GridGeometry extends Abstrac
     }
 
     /**
+     * Writes the check point or Ground Control Points (GCP) in the metadata.
+     *
+     * @param metadata        where to write the ground control points.
+     * @param modelTiePoints  the vector of model tie points.
+     */
+    static void addControlPoints(final CoordinateReferenceSystem crs, final MetadataBuilder
metadata, final Vector modelTiePoints)
+            throws FactoryException, TransformException
+    {
+        metadata.addControlPoints(crs, modelTiePoints, RECORD_LENGTH/2, RECORD_LENGTH);
+    }
+
+    /**
      * Provides an overall assessment of quality of geolocation information.
      */
     @Override

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java?rev=1801065&r1=1801064&r2=1801065&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
[UTF-8] Thu Jul  6 14:40:34 2017
@@ -1158,8 +1158,12 @@ final class ImageFileDirectory {
                 }
             }
         }
-        if (!isGeorectified) try {
-            metadata.addGeolocation(new GridGeometry(input().filename, crs, modelTiePoints));
+        try {
+            if (isGeorectified) {
+                GridGeometry.addControlPoints(crs, metadata, modelTiePoints);
+            } else {
+                metadata.addGeolocation(new GridGeometry(input().filename, crs, modelTiePoints));
+            }
         } catch (TransformException e) {
             reader.owner.warning(null, e);
         }

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=1801065&r1=1801064&r2=1801065&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] Thu Jul  6 14:40:34 2017
@@ -29,11 +29,13 @@ import javax.measure.Unit;
 import org.opengis.util.MemberName;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
+import org.opengis.util.FactoryException;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Role;
 import org.opengis.metadata.citation.DateType;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.CitationDate;
+import org.opengis.metadata.spatial.GCP;
 import org.opengis.metadata.spatial.Dimension;
 import org.opengis.metadata.spatial.DimensionNameType;
 import org.opengis.metadata.spatial.CellGeometry;
@@ -49,10 +51,16 @@ import org.opengis.metadata.identificati
 import org.opengis.metadata.identification.KeywordType;
 import org.opengis.metadata.identification.TopicCategory;
 import org.opengis.metadata.distribution.Format;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.crs.VerticalCRS;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.referencing.CRS;
 import org.apache.sis.geometry.AbstractEnvelope;
+import org.apache.sis.geometry.GeneralDirectPosition;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.metadata.iso.DefaultIdentifier;
 import org.apache.sis.metadata.iso.DefaultMetadataScope;
@@ -65,6 +73,8 @@ import org.apache.sis.metadata.iso.spati
 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.spatial.DefaultGCPCollection;
+import org.apache.sis.metadata.iso.spatial.DefaultGCP;
 import org.apache.sis.metadata.iso.content.DefaultAttributeGroup;
 import org.apache.sis.metadata.iso.content.DefaultSampleDimension;
 import org.apache.sis.metadata.iso.content.DefaultCoverageDescription;
@@ -99,6 +109,7 @@ import org.apache.sis.metadata.sql.Metad
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.iso.Types;
+import org.apache.sis.math.Vector;
 
 import static java.util.Collections.singleton;
 import static org.apache.sis.internal.util.StandardDateFormat.MILLISECONDS_PER_DAY;
@@ -436,6 +447,23 @@ public class MetadataBuilder {
     }
 
     /**
+     * Collection of ground control points.
+     */
+    private DefaultGCPCollection groundControlPoints;
+
+    /**
+     * Creates the collection of ground control points if it does not already exists, then
returns it.
+     *
+     * @return the ground control points (never {@code null}).
+     */
+    private DefaultGCPCollection groundControlPoints() {
+        if (groundControlPoints == null) {
+            groundControlPoints = new DefaultGCPCollection();
+        }
+        return groundControlPoints;
+    }
+
+    /**
      * Information about the distributor of and options for obtaining the resource.
      */
     private DefaultDistribution distribution;
@@ -750,6 +778,10 @@ public class MetadataBuilder {
             if (n != 0) {
                 gridRepresentation.setNumberOfDimensions(shared(n));
             }
+            if (groundControlPoints != null && gridRepresentation instanceof DefaultGeoreferenceable)
{
+                addIfNotPresent(((DefaultGeoreferenceable) gridRepresentation).getGeolocationInformation(),
groundControlPoints);
+                groundControlPoints = null;
+            }
             addIfNotPresent(metadata.getSpatialRepresentationInfo(), gridRepresentation);
             gridRepresentation = null;
         }
@@ -1833,40 +1865,96 @@ parse:      for (int i = 0; i < length;)
     }
 
     /**
-     * Sets a general description of the transformation form grid coordinates to "real world"
coordinates.
+     * Adds information about the geolocation of an image.
      * Storage location is:
      *
      * <ul>
-     *   <li>{@code metadata/spatialRepresentationInfo/transformationDimensionDescription}</li>
+     *   <li>{@code metadata/spatialRepresentationInfo/geolocationInformation}</li>
      * </ul>
      *
-     * @param  value  a general description of the "grid to CRS" transformation, or {@code
null} for no-operation.
+     * @param  info  the geolocation information to add, or {@code null} if none.
      */
-    public final void setGridToCRS(final CharSequence value) {
-        final InternationalString i18n = trim(value);
-        if (i18n != null) {
+    public final void addGeolocation(final GeolocationInformation info) {
+        if (info != null) {
+            final DefaultGridSpatialRepresentation gridRepresentation = gridRepresentation();
+            if (gridRepresentation instanceof DefaultGeoreferenceable) {
+                addIfNotPresent(((DefaultGeoreferenceable) gridRepresentation).getGeolocationInformation(),
info);
+            }
+        }
+    }
+
+    /**
+     * Adds <cite>check points</cite> (if georectified) or <cite>ground
control points</cite> (if georeferenceable).
+     * Storage location is:
+     *
+     * <ul>
+     *   <li>{@code metadata/spatialRepresentationInfo/checkPoint/geographicCoordinates}
if georectified</li>
+     *   <li>{@code metadata/spatialRepresentationInfo/geolocationInformation/gcp/geographicCoordinates}
if georeferenceable</li>
+     * </ul>
+     *
+     * @param  crs        the coordinate reference system of given ordinate values.
+     * @param  ordinates  the ordinate values of control points.
+     * @param  offset     index of the first ordinate value.
+     * @param  stride     increment between two coordinates in the given vector.
+     * @throws FactoryException if an error occurred while preparing the conversion to geographic
coordinates
+     * @throws TransformException if an error occurred while converting the given coordinates
to geographic coordinates.
+     *
+     * @todo Factor most of this code outside MetadataBuilder. May opportunistically define
a class that extend
+     *       AbstractDirectPosition and implement GCP for saving space.
+     */
+    public final void addControlPoints(final CoordinateReferenceSystem crs, final Vector
ordinates,
+            int offset, final int stride) throws FactoryException, TransformException
+    {
+        final int size;
+        if (ordinates != null && (size = ordinates.size()) != 0) {
+            final GeographicCRS geoCRS = ReferencingUtilities.toNormalizedGeographicCRS(crs);
+            if (geoCRS == null) {
+                return;
+            }
+            final MathTransform mt = CRS.findOperation(crs, geoCRS, null).getMathTransform();
             final DefaultGridSpatialRepresentation gridRepresentation = gridRepresentation();
+            final Collection<GCP> points;
             if (gridRepresentation instanceof DefaultGeorectified) {
-                ((DefaultGeorectified) gridRepresentation).setTransformationDimensionDescription(i18n);
+                points = ((DefaultGeorectified) gridRepresentation).getCheckPoints();
+            } else if (gridRepresentation instanceof DefaultGeoreferenceable) {
+                points = groundControlPoints().getGCPs();
+            } else {
+                return;
+            }
+            final int dimension = crs.getCoordinateSystem().getDimension();
+            while (offset < size) {
+                DirectPosition pos = new GeneralDirectPosition(crs);
+                for (int i=0; i<dimension; i++) {
+                    pos.setOrdinate(i, ordinates.doubleValue(offset + i));
+                }
+                pos = mt.transform(pos, pos);
+                final double t = pos.getOrdinate(0);        // Swap ordinate for (latitude,
longitude) order.
+                pos.setOrdinate(0, pos.getOrdinate(1));
+                pos.setOrdinate(1, t);
+                final DefaultGCP gcp = new DefaultGCP();
+                gcp.setGeographicCoordinates(pos);
+                points.add(gcp);
+                offset += stride;
             }
         }
     }
 
     /**
-     * Adds information about the geolocation of an image.
+     * Sets a general description of the transformation form grid coordinates to "real world"
coordinates.
      * Storage location is:
      *
      * <ul>
-     *   <li>{@code metadata/spatialRepresentationInfo/geolocationInformation}</li>
+     *   <li>{@code metadata/spatialRepresentationInfo/transformationDimensionDescription}</li>
      * </ul>
      *
-     * @param  info  the geolocation information to add, or {@code null} if none.
+     * @param  value  a general description of the "grid to CRS" transformation, or {@code
null} for no-operation.
      */
-    public final void addGeolocation(final GeolocationInformation info) {
-        if (info != null) {
+    public final void setGridToCRS(final CharSequence value) {
+        final InternationalString i18n = trim(value);
+        if (i18n != null) {
             final DefaultGridSpatialRepresentation gridRepresentation = gridRepresentation();
-            if (gridRepresentation instanceof DefaultGeoreferenceable) {
-                addIfNotPresent(((DefaultGeoreferenceable) gridRepresentation).getGeolocationInformation(),
info);
+            if (gridRepresentation instanceof DefaultGeorectified) {
+                ((DefaultGeorectified) gridRepresentation).setTransformationDimensionDescription(i18n);
             }
         }
     }



Mime
View raw message