sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1800701 - 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 Mon, 03 Jul 2017 17:09:36 GMT
Author: desruisseaux
Date: Mon Jul  3 17:09:36 2017
New Revision: 1800701

URL: http://svn.apache.org/viewvc?rev=1800701&view=rev
Log:
Complete the calculation of "grid to CRS" translation terms from the model tie point.
Use a tolerance factor when determining if the "grid to CRS" transform is linear.
Declare in the metadata whether model tie points are present.

Modified:
    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/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=1800701&r1=1800700&r2=1800701&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] Mon Jul  3 17:09:36 2017
@@ -24,9 +24,11 @@ import org.opengis.metadata.spatial.Geol
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 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.util.DoubleDouble;
 import org.apache.sis.math.Vector;
 
 
@@ -51,6 +53,12 @@ final class GridGeometry extends Abstrac
     private static final int RECORD_LENGTH = 6;
 
     /**
+     * The desired precision of coordinate transformations in units of pixels.
+     * This is an arbitrary value that may be adjusted in any future SIS version.
+     */
+    private static final double PRECISION = 1E-6;
+
+    /**
      * Creates a new transformation from the information found by {@link ImageFileDirectory}.
      */
     GridGeometry(final String name, final CoordinateReferenceSystem crs, final Vector modelTiePoints)
@@ -82,10 +90,35 @@ final class GridGeometry extends Abstrac
                                  modelTiePoints.doubleValue(i+3),
                                  modelTiePoints.doubleValue(i+4));
         }
+        grid.setDesiredPrecision(PRECISION);
         return grid.create(null);
     }
 
     /**
+     * Computes translation terms in the given matrix from the (usually singleton) tie point.
+     *
+     * @param  gridToCRS       the matrix to update. That matrix shall contain the scale
factors before to invoke this method.
+     * @param  modelTiePoints  the vector of model tie points. Only the first point will
be used.
+     * @return {@code true} if the given vector is non-null and contains at least one complete
record.
+     */
+    static boolean setTranslationTerms(final MatrixSIS gridToCRS, final Vector modelTiePoints)
{
+        if (modelTiePoints == null || modelTiePoints.size() < RECORD_LENGTH) {
+            return false;
+        }
+        final DoubleDouble t = new DoubleDouble();
+        final int numDim = gridToCRS.getNumRow() - 1;
+        final int trCol  = gridToCRS.getNumCol() - 1;
+        for (int j=0; j<numDim; j++) {
+            t.value = -modelTiePoints.doubleValue(j);
+            t.error = DoubleDouble.errorForWellKnownValue(t.value);
+            t.divide(gridToCRS.getNumber(j, j));
+            t.add(modelTiePoints.doubleValue(j + RECORD_LENGTH/2));
+            gridToCRS.setNumber(j, trCol, t);
+        }
+        return true;
+    }
+
+    /**
      * 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=1800701&r1=1800700&r2=1800701&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] Mon Jul  3 17:09:36 2017
@@ -341,6 +341,12 @@ final class ImageFileDirectory {
     private MatrixSIS gridToCRS;
 
     /**
+     * {@code true} if {@link #gridToCRS} has been specified by a complete matrix ({@link
Tags#ModelTransformation}),
+     * or {@code false} if it has been specified by the scale factors only ({@link Tags#ModelPixelScaleTag}).
+     */
+    private boolean completeMatrixSpecified;
+
+    /**
      * Creates a new image file directory.
      *
      * @param reader  information about the input stream to read, the metadata and the character
encoding.
@@ -694,6 +700,7 @@ final class ImageFileDirectory {
                     case 16: n = 4; break;      // 3D model with full 4×4 matrix, as required
by GeoTIFF spec.
                     default: return m;
                 }
+                completeMatrixSpecified = true;
                 gridToCRS = Matrices.createZero(n, n);
                 gridToCRS.setElement(n-1, n-1, 1);
                 for (int i=0; i<size; i++) {
@@ -711,6 +718,7 @@ final class ImageFileDirectory {
                 if (size < 2 || size > 3) {     // Length should be exactly 3, but
we make this reader tolerant.
                     return m;
                 }
+                completeMatrixSpecified = false;
                 gridToCRS = Matrices.createZero(size+1, size+1);
                 gridToCRS.setElement(size, size, 1);
                 for (int i=0; i<size; i++) {
@@ -1042,9 +1050,9 @@ final class ImageFileDirectory {
             }
         }
         /*
-         * Log a warning if the tile offset and tile byte count vectors do not have the same
length. Then
-         * ensure that the number of tiles is equal to the expected number.  The formula
below is the one
-         * documented in the TIFF specification and reproduced in tileWidth & tileHeight
fields javadoc.
+         * Report an error if the tile offset and tile byte count vectors do not have the
same length.
+         * Then ensure that the number of tiles is equal to the expected number. The formula
below is the
+         * one documented in the TIFF specification and reproduced in tileWidth & tileHeight
fields javadoc.
          */
         ensureSameLength(offsetsTag, byteCountsTag, tileOffsets.size(), tileByteCounts.size());
         long expectedCount = Math.multiplyExact(
@@ -1058,6 +1066,15 @@ final class ImageFileDirectory {
             throw new DataStoreContentException(reader.resources().getString(Resources.Keys.UnexpectedTileCount_3,
                     input().filename, expectedCount, actualCount));
         }
+        /*
+         * If a "grid to CRS" conversion has been specified with only the scale factor, we
need to compute
+         * the translation terms now.
+         */
+        if (gridToCRS != null && !completeMatrixSpecified) {
+            if (!GridGeometry.setTranslationTerms(gridToCRS, modelTiePoints)) {
+                throw missingTag(Tags.ModelTiePoints);
+            }
+        }
     }
 
     /**
@@ -1121,6 +1138,7 @@ final class ImageFileDirectory {
         final boolean isGeorectified = (modelTiePoints == null) || (gridToCRS != null);
         metadata.newGridRepresentation(isGeorectified ? MetadataBuilder.GridType.GEORECTIFIED
                                                       : MetadataBuilder.GridType.GEOREFERENCEABLE);
+        metadata.setGeoreferencingAvailability(gridToCRS != null, modelTiePoints != null,
completeMatrixSpecified);
         CoordinateReferenceSystem crs = null;
         if (geoKeyDirectory != null) {
             final CRSBuilder helper = new CRSBuilder(reader);

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=1800701&r1=1800700&r2=1800701&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] Mon Jul  3 17:09:36 2017
@@ -1799,6 +1799,40 @@ parse:      for (int i = 0; i < length;)
     }
 
     /**
+     * Sets whether parameters for transformation, control/check point(s) or orientation
parameters are available.
+     * Storage location are:
+     *
+     * <ul>
+     *   <li>If georeferenceable:<ul>
+     *     <li>{@code metadata/spatialRepresentationInfo/transformationParameterAvailability}</li>
+     *     <li>{@code metadata/spatialRepresentationInfo/controlPointAvailability}</li>
+     *     <li>{@code metadata/spatialRepresentationInfo/orientationParameterAvailability}</li>
+     *   </ul></li>
+     *   <li>If georeferenced:<ul>
+     *     <li>{@code metadata/spatialRepresentationInfo/transformationParameterAvailability}</li>
+     *     <li>{@code metadata/spatialRepresentationInfo/checkPointAvailability}</li>
+     *   </ul></li>
+     * </ul>
+     *
+     * @param  transformationParameterAvailability  indication of whether or not parameters
for transformation exists.
+     * @param  controlPointAvailability             indication of whether or not control
or check point(s) exists.
+     * @param  orientationParameterAvailability     indication of whether or not orientation
parameters are available.
+     */
+    public final void setGeoreferencingAvailability(final boolean transformationParameterAvailability,
+                                                    final boolean controlPointAvailability,
+                                                    final boolean orientationParameterAvailability)
+    {
+        final DefaultGridSpatialRepresentation gridRepresentation = gridRepresentation();
+        gridRepresentation.setTransformationParameterAvailable(transformationParameterAvailability);
+        if (gridRepresentation instanceof DefaultGeorectified) {
+            ((DefaultGeorectified) gridRepresentation).setCheckPointAvailable(controlPointAvailability);
+        } else if (gridRepresentation instanceof DefaultGeoreferenceable) {
+            ((DefaultGeoreferenceable) gridRepresentation).setControlPointAvailable(controlPointAvailability);
+            ((DefaultGeoreferenceable) gridRepresentation).setOrientationParameterAvailable(orientationParameterAvailability);
+        }
+    }
+
+    /**
      * Sets a general description of the transformation form grid coordinates to "real world"
coordinates.
      * Storage location is:
      *



Mime
View raw message