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 5c8868faa7e008fd746bbab60be949d2e67bc706 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Nov 3 12:48:17 2021 +0100 Fix an exception when rendering an image without "grid to CRS" conversion. --- .../org/apache/sis/gui/coverage/CoverageCanvas.java | 16 +++++++++++++--- .../java/org/apache/sis/gui/coverage/ImageRequest.java | 17 ++++++++++------- .../java/org/apache/sis/gui/coverage/RenderingData.java | 10 +++++++++- .../java/org/apache/sis/gui/coverage/package-info.java | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java index 8979673..fd667d1 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java @@ -59,6 +59,8 @@ import org.apache.sis.coverage.grid.ImageRenderer; import org.apache.sis.referencing.operation.matrix.AffineTransforms2D; import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.CommonCRS; +import org.apache.sis.geometry.GeneralEnvelope; import org.apache.sis.geometry.Envelope2D; import org.apache.sis.geometry.Shapes2D; import org.apache.sis.image.PlanarImage; @@ -86,7 +88,7 @@ import org.apache.sis.util.Debug; * A canvas for {@link RenderedImage} provided by a {@link GridCoverage}. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * * @see CoverageExplorer * @@ -484,8 +486,16 @@ public class CoverageCanvas extends MapCanvasAWT { derivedImages.clear(); data.setImage(image, domain, ranges); Envelope bounds = null; - if (domain != null && domain.isDefined(GridGeometry.ENVELOPE)) { - bounds = domain.getEnvelope(); + if (domain != null) { + if (domain.isDefined(GridGeometry.ENVELOPE)) { + bounds = domain.getEnvelope(); + } else if (domain.isDefined(GridGeometry.EXTENT)) try { + final GeneralEnvelope ge = domain.getExtent().toEnvelope(MathTransforms.identity(BIDIMENSIONAL)); + ge.setCoordinateReferenceSystem(CommonCRS.Engineering.DISPLAY.crs()); + bounds = ge; + } catch (TransformException e) { + unexpectedException(e); // Should never happen. + } } setObjectiveBounds(bounds); requestRepaint(); // Cause `Worker` class to be executed. diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImageRequest.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImageRequest.java index 18a3383..dd3b5ba 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImageRequest.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImageRequest.java @@ -55,7 +55,7 @@ public class ImageRequest { /** * The source for rendering the image, specified at construction time. - * After class initialization, only one of {@link #resource} and {@link #coverage} is non-null. + * After construction, only one of {@link #resource} and {@link #coverage} is non-null. * But after task execution, this field will be set to the coverage which has been read. */ private GridCoverage coverage; @@ -147,7 +147,7 @@ public class ImageRequest { } /** - * Returns the coverage, or an empty value is not yet known. This is either the value specified explicitly + * Returns the coverage, or an empty value if not yet known. This is either the value specified explicitly * to the constructor, or otherwise the coverage obtained after a read operation. * * @return the coverage. @@ -162,7 +162,7 @@ public class ImageRequest { * * <blockquote>{@link #ImageRequest(GridCoverageResource, GridGeometry, int[])}</blockquote> * - * and this argument will be transferred verbatim to the following method + * This argument will be forwarded verbatim to the following method * (see its javadoc for more explanation): * * <blockquote>{@link GridCoverageResource#read(GridGeometry, int...)}</blockquote> @@ -183,7 +183,7 @@ public class ImageRequest { * * <blockquote>{@link #ImageRequest(GridCoverageResource, GridGeometry, int[])}</blockquote> * - * and this argument will be transferred verbatim to the following method + * This argument will be forwarded verbatim to the following method * (see its javadoc for more explanation): * * <blockquote>{@link GridCoverageResource#read(GridGeometry, int...)}</blockquote> @@ -209,7 +209,7 @@ public class ImageRequest { * * <blockquote>{@link #ImageRequest(GridCoverage, GridExtent)}</blockquote> * - * and this argument will be transferred verbatim to the following method + * This argument will be forwarded verbatim to the following method * (see its javadoc for more explanation): * * <blockquote>{@link GridCoverage#render(GridExtent)}</blockquote> @@ -223,11 +223,14 @@ public class ImageRequest { } /** - * Sets a new subspace of the grid coverage extent to render. This {@code sliceExtent} argument is not specified + * Sets a new subspace of the grid coverage extent to render. + * + * <div class="note"><b>API design note:</b> + * this {@code sliceExtent} argument is not specified * to the {@link #ImageRequest(GridCoverageResource, GridGeometry, int[])} constructor because when reading data * from a {@link GridCoverageResource}, a slicing can already be done by the {@link GridGeometry} {@code domain} * argument. This method is provided for the rare cases where it may be useful to specify both the {@code domain} - * and the {@code sliceExtent}. + * and the {@code sliceExtent}.</div> * * @param sliceExtent subspace of the grid coverage extent to render. */ diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java index 1cb1ef9..8fcb117 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java @@ -92,7 +92,7 @@ import org.apache.sis.util.logging.Logging; * works well in the general case before doing special cases. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ @@ -253,6 +253,14 @@ final class RenderingData implements Cloneable { this.data = data; this.dataGeometry = domain; this.dataRanges = ranges; // Not cloned because already an unmodifiable list. + if (!domain.isDefined(GridGeometry.GRID_TO_CRS)) { + CoordinateReferenceSystem crs = null; + if (domain.isDefined(GridGeometry.CRS)) { + crs = domain.getCoordinateReferenceSystem(); + } + dataGeometry = new GridGeometry(domain.getExtent(), PixelInCell.CELL_CENTER, + MathTransforms.identity(domain.getDimension()), crs); + } } /** diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/package-info.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/package-info.java index 7492013..cb2d730 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/package-info.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/package-info.java @@ -19,7 +19,7 @@ * Widgets showing {@link org.apache.sis.coverage.grid.GridCoverage} images or sample values. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */