You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2018/12/13 18:02:08 UTC
[sis] 02/02: First draft of handling of GridGeometry argument in
the 'read' method.
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 fa22bec4782dee135be84cec597f4e5f5ef37484
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Dec 13 19:01:35 2018 +0100
First draft of handling of GridGeometry argument in the 'read' method.
---
.../apache/sis/storage/netcdf/GridResource.java | 11 +-------
.../sis/internal/storage/AbstractGridResource.java | 30 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
index 925a1f9..35d9345 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
@@ -207,13 +207,7 @@ final class GridResource extends AbstractGridResource implements ResourceOnFileS
*/
@Override
public GridCoverage read(GridGeometry domain, final int... range) throws DataStoreException {
- if (range != null && range.length != 0) {
- throw new DataStoreException("Unsupported range subsetting."); // TODO
- }
- if (domain != null) {
- throw new DataStoreException("Unsupported domain subsetting."); // TODO
- }
- domain = getGridGeometry();
+ domain = validateReadArgument(domain);
final GridExtent extent = domain.getExtent();
final int dimension = domain.getDimension();
final int[] areaLower = new int[dimension];
@@ -223,9 +217,6 @@ final class GridResource extends AbstractGridResource implements ResourceOnFileS
final int j = (dimension - 1) - i;
areaLower[j] = unsigned(extent.getLow (i)); // Inclusive.
areaUpper[j] = unsigned(extent.getHigh(i) + 1); // Exclusive.
- if (i >= 2) {
- areaUpper[j] = areaLower[j] + 1; // TODO
- }
subsampling[j] = 1;
}
final Vector samples;
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java
index bd06abb..8971b9e 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java
@@ -17,12 +17,15 @@
package org.apache.sis.internal.storage;
import org.opengis.geometry.Envelope;
+import org.opengis.geometry.MismatchedDimensionException;
+import org.opengis.referencing.datum.PixelInCell;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.GridCoverageResource;
import org.apache.sis.coverage.grid.GridGeometry;
import org.apache.sis.coverage.SampleDimension;
import org.apache.sis.storage.Resource;
+import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.logging.WarningListeners;
@@ -86,4 +89,31 @@ public abstract class AbstractGridResource extends AbstractResource implements G
metadata.addNewBand(band);
}
}
+
+ /**
+ * Verifies the validity of the grid geometry specified by the user
+ * for a {@link #read(GridGeometry, int...)} operation.
+ *
+ * @param domain the user-specified grid geometry, or {@code null}.
+ * @return the grid geometry to use for reading.
+ * @throws DataStoreException if an error occurred while validating the grid geometry.
+ */
+ protected final GridGeometry validateReadArgument(GridGeometry domain) throws DataStoreException {
+ final GridGeometry gridGeometry = getGridGeometry();
+ final int dimension = gridGeometry.getDimension();
+ if (domain == null) {
+ domain = gridGeometry;
+ } else {
+ final int ad = domain.getDimension();
+ if (ad != gridGeometry.getDimension()) {
+ throw new MismatchedDimensionException(Errors.format(Errors.Keys.MismatchedDimension_3, "domain", dimension, ad));
+ }
+ if (domain.isDefined(GridGeometry.GRID_TO_CRS) &&
+ !gridGeometry.getGridToCRS(PixelInCell.CELL_CENTER).equals(domain.getGridToCRS(PixelInCell.CELL_CENTER)))
+ {
+ throw new IllegalArgumentException("Mismatched grid to CRS transform.");
+ }
+ }
+ return domain;
+ }
}