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
commit 5df73a7e8fd9da0c59e58b3c96e2d1ccc5bf94d5 Author: Martin Desruisseaux <[email protected]> AuthorDate: Wed Jul 8 15:20:19 2026 +0200 If the `gridToCRS` transform is not available, fallback on resolution. This commit uses the information provided by the previous commit. --- .../apache/sis/coverage/grid/DefaultEvaluator.java | 20 ++++++++++++++++++-- .../org/apache/sis/map/coverage/RenderingData.java | 14 ++++++++------ .../apache/sis/storage/tiling/TileReadEvent.java | 21 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java index eac722be0e..19a7f10f1b 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java @@ -288,7 +288,7 @@ abstract class DefaultEvaluator implements GridCoverage.Evaluator { } while (axes != 0); assert wraparoundExtent.length == j : j; } - } catch (TransformException e) { + } catch (IncompleteGridGeometryException | TransformException e) { recoverableException("setWraparoundEnabled", e); } } @@ -617,6 +617,22 @@ next: while (--numPoints >= 0) { } } + /** + * Returns the grid to <abbr>CRS</abbr> transform or infers a transform from the resolution. + * + * @param grid the grid geometry. + * @return the transform from grid coordinates to <abbr>CRS</abbr> coordinates. + * @throws IncompleteGridGeometryException if there is neither transform or resolution. + */ + private static MathTransform getOfInferGridToCRS(final GridGeometry grid) { + if (!grid.isDefined(GridGeometry.GRID_TO_CRS) && grid.isDefined(GridGeometry.RESOLUTION)) { + return MathTransforms.concatenate( + MathTransforms.uniformTranslation(grid.getDimension(), 0.5), + MathTransforms.scale(grid.getResolution(false))); + } + return grid.getGridToCRS(PixelInCell.CELL_CENTER); + } + /** * Recomputes the {@link #inputToGrid} field if the <abbr>CRS</abbr> changed. * This method should be invoked when the transform has not yet been computed @@ -638,7 +654,7 @@ next: while (--numPoints >= 0) { } final GridCoverage coverage = getCoverage(); final GridGeometry gridGeometry = coverage.getGridGeometry(); - MathTransform gridToCRS = gridGeometry.getGridToCRS(PixelInCell.CELL_CENTER); + MathTransform gridToCRS = getOfInferGridToCRS(gridGeometry); MathTransform crsToGrid = TranslatedTransform.resolveNaN(gridToCRS.inverse(), gridGeometry); if (crs != null) { final CoordinateReferenceSystem stepCRS = coverage.getCoordinateReferenceSystem(); diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingData.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingData.java index 82e4a97b94..abeb7a695d 100644 --- a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingData.java +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/map/coverage/RenderingData.java @@ -330,13 +330,15 @@ public class RenderingData implements CloneAccess { if (domain != null && !domain.isDefined(GridGeometry.GRID_TO_CRS) && domain.isDefined(GridGeometry.EXTENT)) { - CoordinateReferenceSystem crs = null; - if (domain.isDefined(GridGeometry.CRS)) { - crs = domain.getCoordinateReferenceSystem(); - } final GridExtent extent = domain.getExtent(); - domain = new GridGeometry(extent, PixelInCell.CELL_CENTER, - MathTransforms.identity(extent.getDimension()), crs); + final LinearTransform gridToCRS; + if (domain.isDefined(GridGeometry.RESOLUTION)) { + gridToCRS = MathTransforms.scale(domain.getResolution(false)); + } else { + gridToCRS = MathTransforms.identity(extent.getDimension()); + } + // Do not reuse the CRS because the transform will map to something not really known. + domain = new GridGeometry(extent, PixelInCell.CELL_CORNER, gridToCRS, null); } dataGeometry = domain; dataRanges = ranges; diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java index bc28951b95..2c4970d6ce 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java @@ -32,6 +32,7 @@ import org.apache.sis.storage.Resource; import org.apache.sis.storage.event.StoreEvent; import org.apache.sis.coverage.grid.GridExtent; import org.apache.sis.coverage.grid.GridGeometry; +import org.apache.sis.coverage.grid.IncompleteGridGeometryException; import org.apache.sis.coverage.grid.PixelInCell; import org.apache.sis.geometry.Shapes2D; import org.apache.sis.util.internal.shared.Strings; @@ -116,11 +117,26 @@ public final class TileReadEvent extends StoreEvent { offsetY = aoi.getLow(yDimension); } + /** + * Returns the grid to <abbr>CRS</abbr> transform or infers a transform from the resolution. + * + * @param grid the grid geometry. + * @return the transform from grid coordinates to <abbr>CRS</abbr> coordinates. + * @throws IncompleteGridGeometryException if there is neither transform or resolution. + */ + private static MathTransform getOfInferGridToCRS(final GridGeometry grid) { + if (!grid.isDefined(GridGeometry.GRID_TO_CRS) && grid.isDefined(GridGeometry.RESOLUTION)) { + return MathTransforms.scale(grid.getResolution(false)); + } + return grid.getGridToCRS(PixelInCell.CELL_CORNER); + } + /** * Returns the transform from pixel coordinates to real world coordinates in the given <abbr>CRS</abbr>. * * @param crs the two-dimensional <abbr>CRS</abbr> of the desired bounding box. * @return transform from pixel coordinates to real world coordinates in the given <abbr>CRS</abbr>. + * @throws IncompleteGridGeometryException if the "grid to <abbr>CRS</abbr>" transform is missing. * @throws TransformException if the transform cannot be computed. */ final synchronized MathTransform2D imageToObjective(final CoordinateReferenceSystem crs) throws TransformException { @@ -129,7 +145,7 @@ public final class TileReadEvent extends StoreEvent { if (crsToObjective == null || !CRS.equivalent(crsToObjective.getTargetCRS(), crs)) try { crsToObjective = sliceGeometry.createChangeOfCRS(crs); MathTransform tr = MathTransforms.translation(offsetX, offsetY); - tr = MathTransforms.concatenate(tr, sliceGeometry.getGridToCRS(PixelInCell.CELL_CORNER)); + tr = MathTransforms.concatenate(tr, getOfInferGridToCRS(sliceGeometry)); tr = MathTransforms.concatenate(tr, crsToObjective.getMathTransform()); imageToObjective = MathTransforms.bidimensional(tr); this.crsToObjective = crsToObjective; // Store only after the rest was successful. @@ -188,6 +204,7 @@ public final class TileReadEvent extends StoreEvent { * The length of the returned array should be 2. * * @return the resolution in units of the coverage <abbr>CRS</abbr>. + * @throws IncompleteGridGeometryException if the resolution information is missing. */ public double[] getResolution() { return context.sliceGeometry.getResolution(true); @@ -201,6 +218,7 @@ public final class TileReadEvent extends StoreEvent { * * @param crs the two-dimensional <abbr>CRS</abbr> of the desired bounding box. * @return real world coordinates of the tile expressed in the given <abbr>CRS</abbr>. + * @throws IncompleteGridGeometryException if the "grid to <abbr>CRS</abbr>" transform is missing. * @throws TransformException if the tile bounds cannot be transformed to the given <abbr>CRS</abbr>. */ public Rectangle2D bounds(final CoordinateReferenceSystem crs) throws TransformException { @@ -214,6 +232,7 @@ public final class TileReadEvent extends StoreEvent { * * @param crs the two-dimensional <abbr>CRS</abbr> of the desired outline. * @return real world coordinates of the tile expressed in the given <abbr>CRS</abbr>. + * @throws IncompleteGridGeometryException if the "grid to <abbr>CRS</abbr>" transform is missing. * @throws TransformException if the tile bounds cannot be transformed to the given <abbr>CRS</abbr>. */ public Shape outline(final CoordinateReferenceSystem crs) throws TransformException {
