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 11a7a3936f Fix an exception when showing pixel coordinates of a 3D 
image in the JavaFX application. Also fix misleading direction symbols and 
adjust some documentation. The pixel coordinates are needed at least for 
debugging.
11a7a3936f is described below

commit 11a7a3936f7aa198677dada863897b30761aaa24
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Jun 24 10:33:33 2026 +0200

    Fix an exception when showing pixel coordinates of a 3D image in the JavaFX 
application.
    Also fix misleading direction symbols and adjust some documentation.
    The pixel coordinates are needed at least for debugging.
---
 .../main/org/apache/sis/coverage/grid/DefaultEvaluator.java    |  7 ++++++-
 .../main/org/apache/sis/coverage/grid/GridCRSBuilder.java      |  7 ++++---
 .../main/org/apache/sis/coverage/grid/GridGeometry.java        |  8 +++++---
 .../main/org/apache/sis/coverage/grid/TranslatedTransform.java |  3 ++-
 .../main/org/apache/sis/geometry/CoordinateFormat.java         |  6 ++++--
 .../main/org/apache/sis/geometry/package-info.java             |  2 +-
 .../main/org/apache/sis/storage/geotiff/reader/Type.java       |  3 ++-
 .../org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java  |  1 +
 .../main/org/apache/sis/gui/map/OperationFinder.java           |  2 +-
 .../main/org/apache/sis/gui/referencing/MenuSync.java          |  7 +------
 .../org/apache/sis/gui/referencing/RecentReferenceSystems.java | 10 +++++++++-
 11 files changed, 36 insertions(+), 20 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 7cc19292fd..eac722be0e 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
@@ -37,6 +37,7 @@ import 
org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.referencing.CRS;
 import org.apache.sis.referencing.internal.shared.WraparoundAxesFinder;
+import org.apache.sis.referencing.operation.MissingSourceDimensionsException;
 import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
@@ -645,13 +646,17 @@ next:   while (--numPoints >= 0) {
             try {
                 CoordinateOperation op = CRS.findOperation(crs, stepCRS, 
areaOfInterest);
                 crsToGrid = MathTransforms.concatenate(op.getMathTransform(), 
crsToGrid);
-            } catch (FactoryException main) {
+            } catch (MissingSourceDimensionsException main) {
                 /*
                  * Above block tried to compute a "CRS to grid" transform in 
the most direct way.
                  * It covers the usual case where the point has the required 
number of dimensions,
                  * and fixes the case when the point has more dimensions 
(extra dimensions are ignored).
                  * The following block covers the opposite case, where the 
point does not have enough
                  * dimensions. We try to fill missing dimensions with the help 
of the `slice` map.
+                 *
+                 * Note: we could use 
`CoordinateOperationContext.setConstantCoordinates(…)` in above block instead.
+                 * But it would set a constant CRS coordinate, while we want 
to set a constant grid coordinate, and
+                 * computing the CRS coordinate is not easy because of NaN 
scale factors.
                  */
                 @SuppressWarnings("LocalVariableHidesMemberVariable")
                 final Map<Integer, Long> slice = getDefaultSlice();
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCRSBuilder.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCRSBuilder.java
index 5421b8639c..224c90b68a 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCRSBuilder.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCRSBuilder.java
@@ -442,11 +442,12 @@ toGrid: try {
         for (int j=0; j<dimension; j++) {
             String abbreviation = null;
             final DimensionNameType type = dimensionNames[j];
+            boolean pixel = false;
             if (type != null) {
                 if (type == DimensionNameType.COLUMN || type == 
DimensionNameType.SAMPLE) {
-                    abbreviation = "x";
+                    abbreviation = "x"; pixel = true;
                 } else if (type == DimensionNameType.ROW || type == 
DimensionNameType.LINE) {
-                    abbreviation = "y";
+                    abbreviation = "y"; pixel = true;
                 } else if (type == DimensionNameType.VERTICAL) {
                     abbreviation = "z"; hasVertical = true;
                 } else if (type == DimensionNameType.TIME) {
@@ -483,7 +484,7 @@ toGrid: try {
             if (direction == null) {
                 direction = AxisDirection.UNSPECIFIED;
             }
-            axes[j] = csFactory.createCoordinateSystemAxis(properties(name), 
abbreviation, direction, Units.UNITY);
+            axes[j] = csFactory.createCoordinateSystemAxis(properties(name), 
abbreviation, direction, pixel ? Units.PIXEL : Units.UNITY);
         }
         /*
          * Create a coordinate system of affine type if all axes seem spatial.
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java
index 4195bf8913..2dbea346be 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java
@@ -1306,13 +1306,15 @@ public class GridGeometry implements LenientComparable, 
Serializable {
         final double[] origin = new double[cornerToCRS.getTargetDimensions()];
         final Matrix matrix = MathTransforms.getMatrix(cornerToCRS);
         if (matrix != null) {
+            Matrix other = null;
             final int lastColumn = matrix.getNumCol() - 1;
             for (int j=0; j < origin.length; j++) {
                 if (Double.isNaN(origin[j] = matrix.getElement(j, 
lastColumn))) {
-                    final Matrix other = MathTransforms.getMatrix(gridToCRS);
-                    if (other != null) {
-                        origin[j] = other.getElement(j, lastColumn);
+                    if (other == null) {
+                        other = MathTransforms.getMatrix(gridToCRS);
+                        if (other == null) continue;
                     }
+                    origin[j] = other.getElement(j, lastColumn);
                 }
             }
         } else try {
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/TranslatedTransform.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/TranslatedTransform.java
index 9c4603b970..0bfcb138d1 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/TranslatedTransform.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/TranslatedTransform.java
@@ -37,7 +37,8 @@ import org.apache.sis.util.resources.Errors;
  * This class intentionally blocks the optimization which consists in 
optimizing two consecutive linear
  * transforms with a matrix multiplication. The purpose of this transform is 
to replace some coordinate
  * values by zero before the matrix multiplication is applied, because Apache 
<abbr>SIS</abbr> handles
- * 0 × NaN in a special resulting in 0 instead of NaN (okay if NaN is 
interpreted as "any finite number").
+ * 0 × NaN in a special way resulting in 0 instead of NaN, which is okay if 
NaN is interpreted as
+ * "any finite number".
  *
  * <p>The current implementation has no tolerance threshold,
  * but a future implementation could add such tolerance if it appears 
useful.</p>
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
index 1611183b07..4824f2829b 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
@@ -107,7 +107,7 @@ import org.apache.sis.pending.jdk.JDK23;
  * transform the position} before to format it.</p>
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
- * @version 1.4
+ * @version 1.7
  *
  * @see AngleFormat
  * @see org.apache.sis.measure.UnitFormat
@@ -620,7 +620,8 @@ public class CoordinateFormat extends 
CompoundFormat<DirectPosition> {
                     unitSymbols[i] = QuantityFormat.SEPARATOR + symbol;
                 }
             }
-            if (AxisDirections.isCompass(direction)) {
+            // Note: pixel units can come from `GridGeometry` derived CRS.
+            if (AxisDirections.isCompass(direction) && unit != Units.PIXEL) {
                 if (directionSymbols == null) {
                     directionSymbols = new String[dimension * 2];
                 }
@@ -1869,6 +1870,7 @@ checkDirection: if (direction != null) {
      * @throws ClassNotFoundException if the class serialized on the stream is 
not on the module path.
      */
     private void readObject(final ObjectInputStream in) throws IOException, 
ClassNotFoundException {
+        in.defaultReadObject();
         parseSeparator = separator.strip();
     }
 }
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/package-info.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/package-info.java
index fea401bb91..2679233150 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/package-info.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/package-info.java
@@ -87,7 +87,7 @@
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Alexis Manin (Geomatys)
- * @version 1.6
+ * @version 1.7
  * @since   0.3
  */
 package org.apache.sis.geometry;
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Type.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Type.java
index 22678b84c9..9f45f09b1e 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Type.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Type.java
@@ -31,7 +31,8 @@ import org.apache.sis.util.resources.Errors;
 
 
 /**
- * The types of values in a TIFF header. Provides also some support for 
reading a value of a given type.
+ * The types of values in a <abbr>TIFF</abbr> header.
+ * Provides also some support for reading a value of a given type.
  *
  * <p><b>Note on naming convention:</b>
  * the values in this enumeration are not necessarily named as the TIFF type 
names.
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java
index 1a47b5a68a..439e069286 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java
@@ -527,6 +527,7 @@ public final class CCITTRLETest extends TestCase {
      * @see CCITTRLE#WHITE_RUNLENGTH_TREE
      * @see CCITTRLE#BLACK_RUNLENGTH_TREE
      */
+    @SuppressWarnings({"UseOfSystemOutOrSystemErr", "unused"})
     private void printTree() {
         final StringBuilder sb = new StringBuilder(1050);
         int lastCut = 0;
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/OperationFinder.java
 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/OperationFinder.java
index 61de906f91..2e3b945892 100644
--- 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/OperationFinder.java
+++ 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/OperationFinder.java
@@ -168,7 +168,7 @@ abstract class OperationFinder extends Task<MathTransform> {
     }
 
     /**
-     * Returns {@code true} if the given coordinate reference system is the 
CRS of the grid.
+     * Returns {@code true} if the given coordinate reference system is the 
<abbr>CRS</abbr> of the grid.
      * We use the {@link 
org.apache.sis.referencing.CommonCRS.Engineering#GRID} datum as a signature.
      */
     private static boolean isGridCRS(final CoordinateReferenceSystem crs) {
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
index ca03c8a102..df9cd976f6 100644
--- 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
+++ 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
@@ -51,11 +51,6 @@ import org.apache.sis.util.Utilities;
  * @author  Martin Desruisseaux (Geomatys)
  */
 final class MenuSync extends SimpleObjectProperty<ReferenceSystem> implements 
EventHandler<ActionEvent> {
-    /**
-     * The {@value} value, for identifying code that assume two-dimensional 
objects.
-     */
-    private static final int BIDIMENSIONAL = 2;
-
     /**
      * Keys where to store the reference system in {@link MenuItem} properties.
      */
@@ -174,7 +169,7 @@ final class MenuSync extends 
SimpleObjectProperty<ReferenceSystem> implements Ev
     private void initialize() {
         for (final ReferenceSystem system : recentSystems) {
             if (system instanceof CoordinateReferenceSystem crs) {
-                if (CRS.getDimensionOrZero(crs) == BIDIMENSIONAL) {
+                if (CRS.getDimensionOrZero(crs) == 
RecentReferenceSystems.BIDIMENSIONAL) {
                     set(crs);
                     break;
                 }
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
index 23938a4c48..700a1ba091 100644
--- 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
+++ 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
@@ -50,6 +50,7 @@ import 
org.apache.sis.referencing.factory.IdentifiedObjectFinder;
 import org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem;
 import org.apache.sis.referencing.gazetteer.GazetteerException;
 import org.apache.sis.referencing.gazetteer.GazetteerFactory;
+import org.apache.sis.coverage.grid.GridExtent;
 import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.coverage.grid.PixelInCell;
 import org.apache.sis.util.ArgumentChecks;
@@ -86,6 +87,11 @@ import static org.apache.sis.gui.internal.LogHandler.LOGGER;
  * @since   1.1
  */
 public class RecentReferenceSystems {
+    /**
+     * The {@value} value, for identifying code that assume two-dimensional 
objects.
+     */
+    static final int BIDIMENSIONAL = 2;
+
     /**
      * Number of reference systems to always show before all other reference 
systems.
      * They are the native of preferred reference system for the visualized 
data.
@@ -335,13 +341,15 @@ public class RecentReferenceSystems {
         final var derived   = new CoordinateReferenceSystem[refsys.length];
         final var envelopes = new Envelope[refsys.length];
         for (final Map.Entry<Identifier, GridGeometry> entry : 
geometries.entrySet()) {
-            final GridGeometry gg = entry.getValue();
+            GridGeometry gg = entry.getValue();
             if (gg.isDefined(GridGeometry.CRS)) {
                 if (gg.isDefined(GridGeometry.ENVELOPE)) {
                     envelopes[countCRS] = gg.getEnvelope();
                 }
                 refsys[countCRS++] = gg.getCoordinateReferenceSystem();
             }
+            final GridExtent extent = gg.getExtent();
+            gg = 
gg.selectDimensions(extent.getSubspaceDimensions(Math.max(extent.getDegreesOfFreedom(),
 BIDIMENSIONAL)));
             try {
                 derived[countCIR] = gg.createGridCRS(entry.getKey(), 
PixelInCell.CELL_CENTER);
                 countCIR++;     // Increment only if above line was successful.

Reply via email to