This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits 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 10619683eb Add a `SOURCE_NAME_KEY` property to `PlanarImage` for 
making debugging easier.
10619683eb is described below

commit 10619683ebef4a818fdd95aea326f0bbc9f2b427
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Jun 8 14:58:00 2026 +0200

    Add a `SOURCE_NAME_KEY` property to `PlanarImage` for making debugging 
easier.
---
 .../sis/coverage/grid/BufferedGridCoverage.java    |  2 +-
 .../apache/sis/coverage/grid/ImageRenderer.java    |  2 +-
 .../main/org/apache/sis/image/MaskImage.java       |  7 +++---
 .../main/org/apache/sis/image/PlanarImage.java     | 29 ++++++++++++++++++----
 .../sis/image/PositionalConsistencyImage.java      |  2 ++
 .../main/org/apache/sis/image/ResampledImage.java  |  3 +++
 .../main/org/apache/sis/image/UserProperties.java  |  2 +-
 .../image/internal/shared/DeferredProperty.java    |  5 ++--
 .../sis/map/coverage/RenderingWorkaround.java      |  2 ++
 .../org/apache/sis/storage/netcdf/base/Raster.java |  4 +--
 .../sis/storage/tiling/TiledGridCoverage.java      | 17 ++++++++++---
 11 files changed, 55 insertions(+), 20 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BufferedGridCoverage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BufferedGridCoverage.java
index b20d2da52d..24177c6f92 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BufferedGridCoverage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BufferedGridCoverage.java
@@ -123,7 +123,7 @@ public class BufferedGridCoverage extends GridCoverage {
      *     }
      * }
      */
-    private final Cache<GridExtent,RenderedImage> cachedRenderings;
+    private final Cache<GridExtent, RenderedImage> cachedRenderings;
 
     /**
      * Constructs a grid coverage using the specified grid geometry, sample 
dimensions and data buffer.
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
index 401c404991..d78dd3b258 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
@@ -284,7 +284,7 @@ public class ImageRenderer {
      * @see #addProperty(String, Object)
      */
     @SuppressWarnings("UseOfObsoleteCollectionType")
-    private Hashtable<String,Object> properties;
+    private Hashtable<String, Object> properties;
 
     /**
      * The factory to use for {@link 
org.opengis.referencing.operation.MathTransform} creations,
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskImage.java 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskImage.java
index a0a87168f9..afec37b16e 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskImage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskImage.java
@@ -51,6 +51,7 @@ final class MaskImage extends SourceAlignedImage {
         super(image, ColorModelFactory.createIndexColorModel(null, 0,
                 1, Math.max(0, ImageUtilities.getVisibleBand(image)), new 
int[] {0, -1}, true, 0));
 
+        @SuppressWarnings("LocalVariableHidesMemberVariable")
         MathTransform converter = null;
         if (image.interpolation instanceof Visualization.InterpConvert) try {
             converter = ((Visualization.InterpConvert) 
image.interpolation).converter.inverse();
@@ -103,12 +104,12 @@ final class MaskImage extends SourceAlignedImage {
         final int tileMaxY  = Math.addExact(tileMinY, tile.getHeight());
         final int tileWidth = tile.getWidth();
         final float[] row   = new float[Math.multiplyExact(tileWidth, 
numBands)];
-        for (int y=tileMinY; y<tileMaxY; y++) {
+        for (int y = tileMinY; y < tileMaxY; y++) {
             source.getPixels(tileMinX, y, tileWidth, 1, row);
             if (converter != null) {
                 converter.transform(row, 0, row, 0, tileWidth);
             }
-            for (int i=0; i<row.length; i++) {
+            for (int i = 0; i < row.length; i++) {
                 if (Float.isNaN(row[i])) {
                     final int x = i / numBands + tileMinX;
                     tile.setSample(x, y, 0, 1);
@@ -133,7 +134,7 @@ final class MaskImage extends SourceAlignedImage {
     @Override
     public boolean equals(final Object object) {
         if (super.equals(object)) {
-            final MaskImage other = (MaskImage) object;
+            final var other = (MaskImage) object;
             return Objects.equals(converter, other.converter);
         }
         return false;
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java
index a84309840b..0e17b00ab4 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java
@@ -107,10 +107,25 @@ import org.apache.sis.pending.jdk.JDK18;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.5
+ * @version 1.7
  * @since   1.1
  */
 public abstract class PlanarImage implements RenderedImage {
+    /**
+     * Key for a property storing the name of the source of the data rendered 
by this image.
+     * The name can be used as a label in a graphical user interface or for 
debugging purposes,
+     * but should not be used as identifier since the name is not guaranteed 
to be unique.
+     * For example, if the image is a subset of a large source, many subsets 
may exist with the same source name.
+     *
+     * <p>The property value can be any object for which the {@link 
Object#toString()} method returns the name.</p>
+     *
+     * @see org.apache.sis.storage.DataStore#getDisplayName()
+     * @see org.apache.sis.storage.Resource#getIdentifier()
+     *
+     * @since 1.7
+     */
+    public static final String SOURCE_NAME_KEY = "org.apache.sis.SourceName";
+
     /**
      * Key for a property identifying the grid dimensions that are represented 
as a two-dimensional image.
      * For an image which is the result of {@linkplain 
org.apache.sis.coverage.grid.GridCoverage#render
@@ -692,15 +707,19 @@ public abstract class PlanarImage implements 
RenderedImage {
 
     /**
      * Returns a string representation of this image for debugging purpose.
-     * This string representation may change in any future SIS version.
+     * This string representation may change in any future <abbr>SIS</abbr> 
version.
      *
      * @return a string representation of this image for debugging purpose 
only.
      */
     @Override
     public String toString() {
-        final var buffer = new 
StringBuilder(100).append(Classes.getShortClassName(this))
-                .append("[(").append(getWidth()).append(" × 
").append(getHeight()).append(") pixels starting at ")
-                .append('(').append(getMinX()).append(", 
").append(getMinY()).append(')');
+        final var buffer = new 
StringBuilder(100).append(Classes.getShortClassName(this)).append('[');
+        final Object name = getProperty(SOURCE_NAME_KEY);
+        if (name != null && name != Image.UndefinedProperty) {
+            buffer.append('“').append(name).append("”: ");
+        }
+        buffer.append('(').append(getWidth()).append(" × 
").append(getHeight()).append(") pixels starting at ")
+              .append('(').append(getMinX()) .append(", ") 
.append(getMinY()).append(')');
         final SampleModel sm = getSampleModel();
         if (sm != null) {
             buffer.append(" in ").append(sm.getNumBands()).append(" bands");
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PositionalConsistencyImage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PositionalConsistencyImage.java
index a43a6ed02c..465bc3dd62 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PositionalConsistencyImage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PositionalConsistencyImage.java
@@ -39,6 +39,7 @@ final class PositionalConsistencyImage extends 
SourceAlignedImage {
      * @see #getPropertyNames()
      */
     private static final Set<String> INHERITED_PROPERTIES = Set.of(
+            SOURCE_NAME_KEY,
             XY_DIMENSIONS_KEY,
             GRID_GEOMETRY_KEY,
             POSITIONAL_ACCURACY_KEY,
@@ -87,6 +88,7 @@ final class PositionalConsistencyImage extends 
SourceAlignedImage {
             case POSITIONAL_ACCURACY_KEY:
             case GRID_GEOMETRY_KEY:
             case XY_DIMENSIONS_KEY:
+            case SOURCE_NAME_KEY:
             case MASK_KEY: {
                 return getSource().getProperty(key);
             }
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ResampledImage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ResampledImage.java
index 043df29625..1d8182b7e3 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ResampledImage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ResampledImage.java
@@ -495,6 +495,7 @@ public class ResampledImage extends ComputedImage {
      * (more properties may be added to this list in any future Apache SIS 
versions):
      *
      * <ul>
+     *   <li>{@value #SOURCE_NAME_KEY}</li>
      *   <li>{@value #POSITIONAL_ACCURACY_KEY}</li>
      *   <li>{@value #POSITIONAL_CONSISTENCY_KEY}</li>
      *   <li>{@value #SAMPLE_DIMENSIONS_KEY}  (forwarded to the source 
image)</li>
@@ -510,6 +511,7 @@ public class ResampledImage extends ComputedImage {
     @Override
     public Object getProperty(final String key) {
         switch (key) {
+            case SOURCE_NAME_KEY:
             case SAMPLE_DIMENSIONS_KEY:
             case SAMPLE_RESOLUTIONS_KEY: {
                 return getSource().getProperty(key);
@@ -542,6 +544,7 @@ public class ResampledImage extends ComputedImage {
     public String[] getPropertyNames() {
         final String[] inherited = getSource().getPropertyNames();
         final String[] names = {
+            SOURCE_NAME_KEY,
             SAMPLE_DIMENSIONS_KEY,
             SAMPLE_RESOLUTIONS_KEY,
             POSITIONAL_ACCURACY_KEY,
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/UserProperties.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/UserProperties.java
index 24a53783b6..8032f062b1 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/UserProperties.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/UserProperties.java
@@ -41,7 +41,7 @@ final class UserProperties extends ImageAdapter {
      *
      * <p>This {@code UserProperties} class shall not modify the content of 
this map.</p>
      */
-    private final Map<String,Object> properties;
+    private final Map<String, Object> properties;
 
     /**
      * Creates a new wrapper for the given image.
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/DeferredProperty.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/DeferredProperty.java
index c14c9f4ed6..cc26b5a19c 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/DeferredProperty.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/DeferredProperty.java
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.image.internal.shared;
 
-import java.util.Map;
 import java.util.function.Function;
 import java.awt.image.RenderedImage;
 import org.apache.sis.image.PlanarImage;
@@ -79,8 +78,8 @@ public final class DeferredProperty {
      * @param  dimensions  the dimensions to keep from the coverage grid 
geometry.
      * @return a deferred property for computing the grid geometry of an image.
      */
-    public static Map<String,Object> forGridGeometry(final GridGeometry grid, 
final int[] dimensions) {
-        return Map.of(PlanarImage.GRID_GEOMETRY_KEY, new DeferredProperty(new 
ImageGeometry(grid, dimensions)));
+    public static DeferredProperty forGridGeometry(final GridGeometry grid, 
final int[] dimensions) {
+        return new DeferredProperty(new ImageGeometry(grid, dimensions));
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingWorkaround.java
 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingWorkaround.java
index a75d82da42..eaddb4e690 100644
--- 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingWorkaround.java
+++ 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingWorkaround.java
@@ -25,6 +25,7 @@ import java.awt.image.RenderedImage;
 import java.awt.image.SampleModel;
 import java.awt.image.WritableRaster;
 import java.util.Vector;
+import org.apache.sis.util.Workaround;
 import org.apache.sis.image.internal.shared.TilePlaceholder;
 
 
@@ -36,6 +37,7 @@ import org.apache.sis.image.internal.shared.TilePlaceholder;
  *
  * @see <a 
href="https://bugs.openjdk.java.net/browse/JDK-8275345";>JDK-8275345</a>
  */
+@Workaround(library = "jdk", version = "11", fixed = "19")
 public final class RenderingWorkaround implements RenderedImage {
     /**
      * Applies workaround for JDK-8275345 if needed.
diff --git 
a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Raster.java
 
b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Raster.java
index 722f907da0..209e1a813f 100644
--- 
a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Raster.java
+++ 
b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Raster.java
@@ -65,7 +65,7 @@ final class Raster extends BufferedGridCoverage {
      * The colors to use for each category, or {@code null} for default.
      * The function may return {@code null}, which means transparent.
      */
-    private final Function<Category,Color[]> colors;
+    private final Function<Category, Color[]> colors;
 
     /**
      * Creates a new raster from the given resource.
@@ -84,7 +84,7 @@ final class Raster extends BufferedGridCoverage {
            final int pixelStride,
            final int[] bandOffsets,
            final int visibleBand,
-           final Function<Category,Color[]> colors)
+           final Function<Category, Color[]> colors)
     {
         super(domain, range, data);
         this.colors      = colors;
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TiledGridCoverage.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TiledGridCoverage.java
index e820ce116b..3421c2a561 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TiledGridCoverage.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TiledGridCoverage.java
@@ -16,7 +16,7 @@
  */
 package org.apache.sis.storage.tiling;
 
-import java.util.Map;
+import java.util.HashMap;
 import java.util.Optional;
 import java.nio.file.Path;
 import java.awt.Point;
@@ -40,6 +40,7 @@ import org.opengis.util.GenericName;
 import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.coverage.grid.GridExtent;
 import org.apache.sis.coverage.grid.DisjointExtentException;
+import org.apache.sis.image.PlanarImage;
 import org.apache.sis.image.internal.shared.DeferredProperty;
 import org.apache.sis.image.internal.shared.TiledImage;
 import org.apache.sis.storage.event.StoreListeners;
@@ -575,6 +576,10 @@ public abstract class TiledGridCoverage extends 
GridCoverage {
             // TODO
             throw new UnsupportedOperationException("Slices in arbitrary 
dimensions not yet implemented.");
         }
+        GenericName name = getIdentifier();
+        if (name != null) {
+            name = name.toFullyQualifiedName();
+        }
         final RenderedImage image;
         try {
             final int[] tileLower = new int[dimension];         // Indices of 
first tile to read, inclusive.
@@ -617,7 +622,11 @@ public abstract class TiledGridCoverage extends 
GridCoverage {
                 // Leave `eventContext` to null: no event will be fired.
             }
             final var iterator = new TileIterator(tileLower, tileUpper, 
offsetAOI, dimension, xDimension, yDimension, eventContext);
-            final Map<String, Object> properties = 
DeferredProperty.forGridGeometry(gridGeometry, selectedDimensions);
+            final var properties = new HashMap<String, Object>(4);
+            properties.put(PlanarImage.GRID_GEOMETRY_KEY, 
DeferredProperty.forGridGeometry(gridGeometry, selectedDimensions));
+            if (name != null) {
+                properties.put(PlanarImage.SOURCE_NAME_KEY, 
name.toFullyQualifiedName());
+            }
             if (deferredTileReading) {
                 image = new TiledDeferredImage(imageSize, tileLower, 
properties, iterator);
             } else {
@@ -633,8 +642,8 @@ public abstract class TiledGridCoverage extends 
GridCoverage {
         } catch (DisjointExtentException | CannotEvaluateException e) {
             throw e;
         } catch (Exception e) {     // Too many exception types for listing 
them all.
-            throw new 
CannotEvaluateException(Resources.forLocale(listeners.getLocale()).getString(
-                    Resources.Keys.CanNotRenderImage_1, 
getIdentifier().toFullyQualifiedName()), e);
+            throw new 
CannotEvaluateException(Resources.forLocale(listeners.getLocale())
+                        .getString(Resources.Keys.CanNotRenderImage_1, name), 
e);
         }
         return image;
     }

Reply via email to