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 2023/04/17 09:59:50 UTC

[sis] branch geoapi-4.0 updated: Keep a reference to the `GridCoverageProcessor` to use for selecting bands in a `MemoryGridResource`. The coverage processor determines the color model to use when a band subset is requested.

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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new f444cac9c0 Keep a reference to the `GridCoverageProcessor` to use for selecting bands in a `MemoryGridResource`. The coverage processor determines the color model to use when a band subset is requested.
f444cac9c0 is described below

commit f444cac9c00abd06b60c51b8149bab864a23f3df
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Mon Apr 17 11:38:58 2023 +0200

    Keep a reference to the `GridCoverageProcessor` to use for selecting bands in a `MemoryGridResource`.
    The coverage processor determines the color model to use when a band subset is requested.
---
 .../sis/internal/storage/MemoryGridResource.java   | 16 +++++++++++----
 .../storage/image/WritableSingleImageStore.java    |  2 +-
 .../aggregate/BandAggregateGridResource.java       |  2 +-
 .../sis/storage/aggregate/CoverageAggregator.java  | 23 +++++++++++++---------
 .../apache/sis/storage/aggregate/GridSlice.java    | 15 --------------
 .../internal/storage/MemoryGridResourceTest.java   |  2 +-
 .../org/apache/sis/storage/CoverageSubsetTest.java |  2 +-
 .../aggregate/BandAggregateGridResourceTest.java   |  2 +-
 8 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java
index f96563a553..f01991fc5d 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java
@@ -48,16 +48,24 @@ public final class MemoryGridResource extends AbstractGridCoverageResource {
      */
     public final GridCoverage coverage;
 
+    /**
+     * The grid coverage processor to use for selecting bands.
+     * It may be configured with a colorizer for determining the color models.
+     */
+    private final GridCoverageProcessor processor;
+
     /**
      * Creates a new coverage stored in memory.
      *
-     * @param  parent    listeners of the parent resource, or {@code null} if none.
-     * @param  coverage  stored coverage retained as-is (not copied). Cannot be null.
+     * @param  parent     listeners of the parent resource, or {@code null} if none.
+     * @param  coverage   stored coverage retained as-is (not copied). Cannot be null.
+     * @param  processor  the grid coverage processor for selecting bands, or {@code null} for default.
      */
-    public MemoryGridResource(final StoreListeners parent, final GridCoverage coverage) {
+    public MemoryGridResource(final StoreListeners parent, final GridCoverage coverage, final GridCoverageProcessor processor) {
         super(parent, false);
         ArgumentChecks.ensureNonNull("coverage", coverage);
         this.coverage = coverage;
+        this.processor = (processor != null) ? processor : new GridCoverageProcessor();
     }
 
     /**
@@ -100,7 +108,7 @@ public final class MemoryGridResource extends AbstractGridCoverageResource {
          */
         GridCoverage subset = coverage;
         if (ranges != null && ranges.length != 0) {
-            subset = new GridCoverageProcessor().selectSampleDimensions(subset, ranges);
+            subset = processor.selectSampleDimensions(subset, ranges);
         }
         /*
          * The given `domain` may use arbitrary `gridToCRS` and `CRS` properties.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableSingleImageStore.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableSingleImageStore.java
index 28cc1fe185..ef0809470c 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableSingleImageStore.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableSingleImageStore.java
@@ -170,7 +170,7 @@ final class WritableSingleImageStore extends WritableStore implements WritableGr
     public void write(final GridCoverage coverage, final Option... options) throws DataStoreException {
         try {
             if (isMultiImages() == 0) {
-                add(new MemoryGridResource(listeners, coverage));
+                add(new MemoryGridResource(listeners, coverage, null));
             } else {
                 delegate().write(coverage, options);
             }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/BandAggregateGridResource.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/BandAggregateGridResource.java
index 5487b2cea2..8f2de820d9 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/BandAggregateGridResource.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/BandAggregateGridResource.java
@@ -203,7 +203,7 @@ final class BandAggregateGridResource extends AbstractGridCoverageResource imple
         if (count != 0) {
             coverages     = ArraysExt.resize(coverages,     count);
             coverageBands = ArraysExt.resize(coverageBands, count);
-            var aggregate = new MemoryGridResource(parentListeners, processor.aggregateRanges(coverages, coverageBands));
+            var aggregate = new MemoryGridResource(parentListeners, processor.aggregateRanges(coverages, coverageBands), processor);
             for (int i=0; i<sources.length; i++) {
                 if (sources[i] == null) {
                     sources[i] = aggregate;
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/CoverageAggregator.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/CoverageAggregator.java
index 828c045584..01dee863cb 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/CoverageAggregator.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/CoverageAggregator.java
@@ -41,6 +41,7 @@ import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.coverage.grid.GridCoverageProcessor;
 import org.apache.sis.coverage.grid.IllegalGridGeometryException;
 import org.apache.sis.coverage.SubspaceNotSpecifiedException;
+import org.apache.sis.internal.storage.MemoryGridResource;
 import org.apache.sis.util.collection.BackingStoreException;
 
 
@@ -184,16 +185,20 @@ public final class CoverageAggregator extends Group<GroupBySample> {
      * @since 1.4
      */
     public void add(final GridCoverage coverage) {
-        final GroupBySample bySample = GroupBySample.getOrAdd(members, coverage.getSampleDimensions());
-        final GridSlice slice = new GridSlice(listeners, coverage);
-        final List<GridSlice> slices;
         try {
-            slices = slice.getList(bySample.members, strategy).members;
-        } catch (NoninvertibleTransformException e) {
-            throw new IllegalGridGeometryException(e);
-        }
-        synchronized (slices) {
-            slices.add(slice);
+            add(new MemoryGridResource(listeners, coverage, processor()));
+        } catch (DataStoreException e) {
+            /*
+             * `DataStoreException` are never thrown by `MemoryGridResource`.
+             * The only case where we could get that exception with default
+             * `add(GridCoverageResource)` is with non-invertible transform.
+             */
+            final Throwable cause = e.getCause();
+            if (cause instanceof NoninvertibleTransformException) {
+                throw new IllegalGridGeometryException(cause);
+            } else {
+                throw new BackingStoreException(e);
+            }
         }
     }
 
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/GridSlice.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/GridSlice.java
index 09fb3c54e8..738b20770a 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/GridSlice.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/aggregate/GridSlice.java
@@ -24,14 +24,11 @@ import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
-import org.apache.sis.storage.event.StoreListeners;
 import org.apache.sis.storage.GridCoverageResource;
 import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.coverage.grid.GridExtent;
 import org.apache.sis.internal.coverage.CommonDomainFinder;
-import org.apache.sis.internal.storage.MemoryGridResource;
 import org.apache.sis.internal.util.Strings;
 
 
@@ -70,18 +67,6 @@ final class GridSlice {
      */
     private final long[] offset;
 
-    /**
-     * Creates a new slice for the specified coverage.
-     *
-     * @param  parent  listeners of the parent resource, or {@code null} if none.
-     * @param  slice   coverage associated to this slice.
-     */
-    GridSlice(final StoreListeners parent, final GridCoverage slice) {
-        resource = new MemoryGridResource(parent, slice);
-        geometry = slice.getGridGeometry();
-        offset   = new long[geometry.getDimension()];
-    }
-
     /**
      * Creates a new slice for the specified resource.
      *
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
index ef8a7fedaa..e51b7d8e09 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
@@ -67,7 +67,7 @@ public final class MemoryGridResourceTest extends TestCase {
         gridToCRS = new AffineTransform2D(2, 0, 0, 3, 0, 0);
         final GridGeometry grid = new GridGeometry(new GridExtent(WIDTH, HEIGHT), PixelInCell.CELL_CENTER, gridToCRS, crs);
         final BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_BYTE_BINARY);
-        resource = new MemoryGridResource(null, new GridCoverage2D(grid, null, image));
+        resource = new MemoryGridResource(null, new GridCoverage2D(grid, null, image), null);
     }
 
     /**
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/storage/CoverageSubsetTest.java b/storage/sis-storage/src/test/java/org/apache/sis/storage/CoverageSubsetTest.java
index 53c0abac97..ec20872938 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/storage/CoverageSubsetTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/storage/CoverageSubsetTest.java
@@ -70,7 +70,7 @@ public final class CoverageSubsetTest extends TestCase {
         final var domain = new GridGeometry(extent, region, GridOrientation.HOMOTHETY);
         final var band   = new SampleDimension.Builder().addQuantitative("101-based row-major order pixel number", 101, 105, 1, 0, Units.UNITY).build();
         final var buffer = new DataBufferInt(values(), WIDTH * HEIGHT);
-        return new MemoryGridResource(null, new BufferedGridCoverage(domain, List.of(band), buffer));
+        return new MemoryGridResource(null, new BufferedGridCoverage(domain, List.of(band), buffer), null);
     }
 
     /**
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/storage/aggregate/BandAggregateGridResourceTest.java b/storage/sis-storage/src/test/java/org/apache/sis/storage/aggregate/BandAggregateGridResourceTest.java
index 95ef5dc7bb..16a7a1baaf 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/storage/aggregate/BandAggregateGridResourceTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/storage/aggregate/BandAggregateGridResourceTest.java
@@ -201,7 +201,7 @@ public final class BandAggregateGridResourceTest extends TestCase {
             System.arraycopy(bandValues, 0, data, i, numBands);
         }
         final var values = new DataBufferInt(data, data.length);
-        final var r = new MemoryGridResource(null, new BufferedGridCoverage(domain, samples, values));
+        final var r = new MemoryGridResource(null, new BufferedGridCoverage(domain, samples, values), null);
         return opaque ? new OpaqueGridResource(r) : r;
     }