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

alexismanin pushed a commit to branch fix/image-tile-matrix-get-tile
in repository https://gitbox.apache.org/repos/asf/sis.git

commit c773e2ca4d3fc293c113a8e78816910ffb013a6b
Author: Alexis Manin <[email protected]>
AuthorDate: Mon May 18 08:45:12 2026 +0200

    fix(Storage): Fix ImageTileMatrix tile indices to work with slices in N 
dimensions.
    
    Previously, tiles from the ImageTileMatrix were assuming that its tiles 
were set in a 2D space.
    However, an ImageTileMatrix can be a 2D slice in higher dimension space 
(for example, CRS:84 + single elevation coordinate). In such cases, the code 
that was relying on tile coordinates broke.
---
 .../apache/sis/storage/tiling/ImageTileMatrix.java | 41 ++++++++++++++++++----
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/ImageTileMatrix.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/ImageTileMatrix.java
index 38d09e96e8..84087f6e29 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/ImageTileMatrix.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/ImageTileMatrix.java
@@ -383,7 +383,8 @@ final class ImageTileMatrix implements TileMatrix {
                         return new Iterator(Math.toIntExact(xmin),
                                             Math.toIntExact(ymin),
                                             Math.toIntExact(xmax),
-                                            Math.toIntExact(ymax));
+                                            Math.toIntExact(ymax),
+                                            
indiceRanges.getLow().getCoordinateValues());
                     }
                 }
             }
@@ -448,19 +449,42 @@ final class ImageTileMatrix implements TileMatrix {
          */
         private final long offsetX, offsetY;
 
+        /**
+         * Dimension indices for the X and Y axes in the tile matrix 
coordinate system.
+         */
+        private final int xDim, yDim;
+
+        /**
+         * Base template of tile indices.
+         * Used when returning {@link Tile#getIndices() tile indices}.
+         * Tiles will use these coordinates, replacing {link #xDim X} and 
{link #yDim Y} dimensions.
+         */
+        private final long[] baseIndices;
+
         /**
          * Creates a new request for tile iterators.
          *
-         * @param xmin  first column index of tiles, inclusive.
-         * @param xmin  first row index of tiles, inclusive.
-         * @param xmax  last column index of tiles, inclusive.
-         * @param ymax  last row index of tiles, inclusive.
+         * @param xmin        first column index of tiles, inclusive.
+         * @param ymin        first row index of tiles, inclusive.
+         * @param xmax        last column index of tiles, inclusive.
+         * @param ymax        last row index of tiles, inclusive.
+         * @param baseIndices tile coordinate template.
+         *                    It can be any valid coordinate of the tiles 
managed by this iterator.
+         *                    It serves as base to build correct tile 
coordinate for each returned tile.
+         *                    Each tile will clone this array and replace its 
X and Y indices with its own.
+         *                    Therefore, it is important that it represent 
properly the "slice" of extra-dimensions
+         *                    this iterator operates on.
          */
-        Iterator(final int xmin, final int ymin, final int xmax, final int 
ymax) {
+        Iterator(final int xmin, final int ymin, final int xmax, final int 
ymax,
+                 final long[] baseIndices)
+        {
             super(xmin, ymin, xmax, ymax);
             tiles   = image;
             offsetX = imageToTileX;
             offsetY = imageToTileY;
+            xDim    = coverage.xDimension;
+            yDim    = coverage.yDimension;
+            this.baseIndices = baseIndices;
         }
 
         /**
@@ -481,7 +505,10 @@ final class ImageTileMatrix implements TileMatrix {
 
                 /** Returns the indices of this tile in the {@code 
TileMatrix}. */
                 @Override public long[] getIndices() {
-                    return new long[] {offsetX + tileX, offsetY + tileY};
+                    final long[] indices = baseIndices.clone();
+                    indices[xDim] = offsetX + tileX;
+                    indices[yDim] = offsetY + tileY;
+                    return indices;
                 }
 
                 /** Returns information about whether the tile failed to load. 
*/

Reply via email to