sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 25/31: Fix error messages for illegal grid geometries.
Date Mon, 18 Jun 2018 09:44:36 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 5963796c896f47ecd8d4c4733299203dda83ed9c
Author: Martin Desruisseaux <desruisseaux@apache.org>
AuthorDate: Wed Jun 6 17:27:02 2018 +0000

    Fix error messages for illegal grid geometries.
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sis/branches/JDK8@1833061 13f79535-47bb-0310-9956-ffa450edef68
---
 .../main/java/org/apache/sis/coverage/grid/GridGeometry.java | 12 ++++++------
 .../org/apache/sis/storage/geotiff/GridGeometryBuilder.java  | 11 +++++++++--
 .../org/apache/sis/storage/geotiff/ImageFileDirectory.java   |  2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 30dc210..de064a0 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -234,10 +234,10 @@ public class GridGeometry implements Serializable {
     {
         if (gridToCRS != null) {
             if (extent != null) {
-                ensureDimensionMatches("extent", extent.getDimension(), gridToCRS.getSourceDimensions());
+                ensureDimensionMatches("extent", gridToCRS.getSourceDimensions(), extent.getDimension());
             }
             if (crs != null) {
-                ensureDimensionMatches("crs", crs.getCoordinateSystem().getDimension(), gridToCRS.getTargetDimensions());
+                ensureDimensionMatches("crs", gridToCRS.getTargetDimensions(), crs.getCoordinateSystem().getDimension());
             }
         } else if (crs == null) {
             ArgumentChecks.ensureNonNull("extent", extent);
@@ -275,15 +275,15 @@ public class GridGeometry implements Serializable {
      * Ensures that the given dimension is equals to the expected value. If not, throws an
exception.
      *
      * @param argument  the name of the argument being tested.
-     * @param dimension the dimension of the argument value.
-     * @param expected  the expected dimension.
+     * @param expected  the expected number of dimension.
+     * @param dimension the actual dimension of the argument value.
      */
-    private static void ensureDimensionMatches(final String argument, final int dimension,
final int expected)
+    private static void ensureDimensionMatches(final String argument, final int expected,
final int dimension)
             throws MismatchedDimensionException
     {
         if (dimension != expected) {
             throw new MismatchedDimensionException(Errors.format(
-                    Errors.Keys.MismatchedDimension_3, argument, dimension, expected));
+                    Errors.Keys.MismatchedDimension_3, argument, expected, dimension));
         }
     }
 
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
index 5badf79..498424d 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
@@ -292,7 +292,7 @@ final class GridGeometryBuilder {
                 reader.owner.warning(reader.resources().getString(key, reader.owner.getDisplayName()),
e);
             } catch (IllegalArgumentException | NoSuchElementException | ClassCastException
e) {
                 if (!helper.alreadyReported) {
-                    reader.owner.warning(null, e);
+                    canNotCreate(e);
                 }
             }
         }
@@ -308,7 +308,7 @@ final class GridGeometryBuilder {
             gridGeometry = new GridGeometry(extent, pixelIsPoint ? PixelInCell.CELL_CENTER
: PixelInCell.CELL_CORNER, gridToCRS, crs);
         } catch (TransformException e) {
             gridGeometry = new GridGeometry(extent, crs);
-            reader.owner.warning(null, e);
+            canNotCreate(e);
             /*
              * Note: we catch TransformExceptions because they may be caused by erroneous
data in the GeoTIFF file,
              * but let FactoryExceptions propagate because they are more likely to be a SIS
configuration problem.
@@ -365,4 +365,11 @@ final class GridGeometryBuilder {
         }
         metadata.setPointInPixel(po);
     }
+
+    /**
+     * Logs a warning telling that we can not create a grid geometry for the given reason.
+     */
+    private void canNotCreate(final Exception e) {
+        reader.owner.warning(reader.resources().getString(Resources.Keys.CanNotComputeGridGeometry_1,
reader.input.filename), e);
+    }
 }
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index c3366b8..2fc880a 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -1221,7 +1221,7 @@ final class ImageFileDirectory extends AbstractResource implements GridCoverageR
             if (gridGeometry == null) try {
                 gridGeometry = referencing.build(extent());
             } catch (FactoryException e) {
-                throw new DataStoreContentException(reader.resources().getString(Resources.Keys.CanNotComputeGridGeometry_1,
filename(), e));
+                throw new DataStoreContentException(reader.resources().getString(Resources.Keys.CanNotComputeGridGeometry_1,
filename()), e);
             }
             return gridGeometry;
         } else {

-- 
To stop receiving notification emails like this one, please contact
desruisseaux@apache.org.

Mime
View raw message