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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new e5e9520bce Rename `GridDerivation.selectDimensions(Predicate)` as
`selectAxes(int...)`.
e5e9520bce is described below
commit e5e9520bce64a0df8247c7d0cfabd12d0cfde829
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Jan 21 12:18:44 2026 +0100
Rename `GridDerivation.selectDimensions(Predicate)` as `selectAxes(int...)`.
---
.../apache/sis/coverage/grid/DimensionReducer.java | 7 +--
.../apache/sis/coverage/grid/GridDerivation.java | 66 ++++++++++------------
.../org/apache/sis/coverage/grid/GridExtent.java | 6 +-
.../org/apache/sis/coverage/grid/GridGeometry.java | 3 +-
.../sis/coverage/grid/GridDerivationTest.java | 7 +--
5 files changed, 42 insertions(+), 47 deletions(-)
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionReducer.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionReducer.java
index 2724153a6e..daa2eebcc5 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionReducer.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionReducer.java
@@ -17,7 +17,6 @@
package org.apache.sis.coverage.grid;
import java.util.Arrays;
-import java.util.BitSet;
import org.opengis.util.FactoryException;
import org.opengis.geometry.Envelope;
import org.opengis.geometry.DirectPosition;
@@ -56,10 +55,10 @@ final class DimensionReducer {
/**
* Requests to retain only the axes in the specified <abbr>CRS</abbr>
dimensions.
*
- * @param mask the <abbr>CRS</abbr> dimensions to keep.
+ * @param dimensions the <abbr>CRS</abbr> dimensions to keep, or {@code
null} for keeping them all.
*/
- DimensionReducer(final BitSet mask) {
- dimensions = mask.stream().toArray();
+ DimensionReducer(final int... dimensions) {
+ this.dimensions = dimensions;
}
/**
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridDerivation.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridDerivation.java
index 052b2cf796..982c68a090 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridDerivation.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridDerivation.java
@@ -17,12 +17,10 @@
package org.apache.sis.coverage.grid;
import java.util.Map;
-import java.util.Set;
-import java.util.BitSet;
+import java.util.Collection;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
-import java.util.function.Predicate;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.math.RoundingMode;
@@ -33,7 +31,6 @@ import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.AxisDirection;
import org.apache.sis.referencing.CRS;
@@ -235,9 +232,9 @@ public class GridDerivation {
* Indexes of <abbr>CRS</abbr> axes to keep, or {@code null} if no
filtering will be applied.
* A non-null value may cause a reduction in the number of dimensions of
the grid.
*
- * @see #selectDimensions(Set)
+ * @see #selectAxes(int[])
*/
- private BitSet dimensionsToKeepInCRS;
+ private int[] dimensionsToKeepInCRS;
/**
* Creates a new builder for deriving a grid geometry from the specified
base.
@@ -1204,44 +1201,31 @@ public class GridDerivation {
}
/**
- * Requests a grid where only a subset of the <abbr>CRS</abbr> dimensions
will be kept.
- * The real world dimensions to keep are specified by a filter applied on
the coordinate system axes.
+ * Requests a grid where only a subset of the <abbr>CRS</abbr> axes will
be kept.
+ * The given axis indices must be in strictly ascending order without
duplicated values.
* This method may reduce the number of dimensions of the grid if, as a
result of this filtering,
* some grid dimensions become unrelated to any <abbr>CRS</abbr> axis.
*
- * <h4>Example</h4>
- * The following code keeps only the axes having a linear unit of
measurement such as metres or kilometres:
- *
- * {@snippet lang="java" :
- * GridGeometry gg = ...;
- * gg = gg.derive().selectDimensions((axis) ->
Units.isLinear(axis.getUnit())).build();
- * }
- *
- * @param filter a predicate which returns {@code true} for coordinate
system axes to keep.
+ * @param indices indices of the axes of the <abbr>CRS</abbr> to keep in
the derived grid.
* @return {@code this} for method call chaining.
+ * @throws IllegalArgumentException if the indices are not in strictly
ascending order.
+ * @throws IndexOutOfBoundsException if an axis index is out of bounds.
* @throws IncompleteGridGeometryException if the base grid geometry has
no <abbr>CRS</abbr>.
*
+ * @see GridGeometry#selectDimensions(int...)
+ * @see CRS#selectDimensions(CoordinateReferenceSystem, int[])
+ *
* @since 1.6
*/
- public GridDerivation selectDimensions(final
Predicate<CoordinateSystemAxis> filter) {
- final var dimensions = new BitSet();
- final CoordinateSystem cs =
base.getCoordinateReferenceSystem().getCoordinateSystem();
- for (int i = cs.getDimension(); --i >= 0;) {
- if (filter.test(cs.getAxis(i))) {
- dimensions.set(i);
- }
- }
- if (dimensionsToKeepInCRS == null) {
- dimensionsToKeepInCRS = dimensions;
- } else {
- dimensionsToKeepInCRS.and(dimensions);
- }
+ public GridDerivation selectAxes(int... indices) {
+ CoordinateSystem cs =
base.getCoordinateReferenceSystem().getCoordinateSystem();
+ dimensionsToKeepInCRS = GridExtent.verifyDimensions(indices,
cs.getDimension());
return this;
}
/**
- * Requests a grid where some <abbr>CRS</abbr> dimensions are excluded.
- * The real world dimensions to exclude are specified by the axis
directions.
+ * Requests a grid where some <abbr>CRS</abbr> axes are excluded.
+ * The axes to exclude are specified by the axis directions.
* This method may reduce the number of dimensions of the grid if, as a
result of this filtering,
* some grid dimensions become unrelated to any <abbr>CRS</abbr> axis.
*
@@ -1254,12 +1238,12 @@ public class GridDerivation {
* try {
* doSomeStuff(gg);
* } catch (MissingSourceDimensionsException e) {
- * gg =
gg.gridDerivation().excludeDimensions(e.getMissingAxes()).build();
+ * gg =
gg.gridDerivation().excludeAxes(e.getMissingAxes()).build();
* doSomeStuff(gg); // Try again.
* }
* }
*
- * @param exclusion the dimensions to remove, identified by their axis
directions.
+ * @param exclusion the <abbr>CRS</abbr> axes to remove, identified by
their directions.
* @return {@code this} for method call chaining.
* @throws IncompleteGridGeometryException if the base grid geometry has
no <abbr>CRS</abbr>.
*
@@ -1267,8 +1251,18 @@ public class GridDerivation {
*
* @since 1.6
*/
- public GridDerivation excludeDimensions(final Set<AxisDirection>
exclusion) {
- return selectDimensions((axis) ->
!exclusion.contains(axis.getDirection()));
+ public GridDerivation excludeAxes(final Collection<AxisDirection>
exclusion) {
+ final CoordinateSystem cs =
base.getCoordinateReferenceSystem().getCoordinateSystem();
+ final int dimension = cs.getDimension();
+ final int[] indices = new int[dimension];
+ int count = 0;
+ for (int i=0; i<dimension; i++) {
+ if (!exclusion.contains(cs.getAxis(i).getDirection())) {
+ indices[count++] = i;
+ }
+ }
+ dimensionsToKeepInCRS = (count == dimension) ? null :
Arrays.copyOf(indices, count);
+ return this;
}
/**
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
index defb8b2b51..07d68fc690 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
@@ -115,7 +115,7 @@ public class GridExtent implements GridEnvelope,
LenientComparable, Serializable
*
* @see #typeFromAxes(CoordinateReferenceSystem, int)
*/
- private static final Map<AxisDirection,DimensionNameType> AXIS_DIRECTIONS
= Map.of(
+ private static final Map<AxisDirection, DimensionNameType> AXIS_DIRECTIONS
= Map.of(
AxisDirection.COLUMN_POSITIVE, DimensionNameType.COLUMN,
AxisDirection.ROW_POSITIVE, DimensionNameType.ROW,
AxisDirection.UP, DimensionNameType.VERTICAL,
@@ -133,7 +133,7 @@ public class GridExtent implements GridEnvelope,
LenientComparable, Serializable
* A pool of shared {@link DimensionNameType} arrays. We use a pool
* because a small number of arrays is shared by most grid extents.
*/
- private static final
WeakValueHashMap<DimensionNameType[],DimensionNameType[]> POOL = new
WeakValueHashMap<>(DimensionNameType[].class);
+ private static final WeakValueHashMap<DimensionNameType[],
DimensionNameType[]> POOL = new WeakValueHashMap<>(DimensionNameType[].class);
/**
* Type of each axis (vertical, temporal, …) or {@code null} if
unspecified.
@@ -2165,6 +2165,8 @@ public class GridExtent implements GridEnvelope,
LenientComparable, Serializable
/**
* Returns a string representation of this grid extent. The returned string
* is implementation dependent and is provided for debugging purposes only.
+ *
+ * @return a string representation of this grid extent for debugging
purposes.
*/
@Override
public String toString() {
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 3aca8de747..3155ad8a4e 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
@@ -1825,11 +1825,12 @@ public class GridGeometry implements LenientComparable,
Serializable {
*
* @param indices the grid (not <abbr>CRS</abbr>) dimensions to select,
in strictly increasing order.
* @return the sub-grid geometry, or {@code this} if the given array
contains all dimensions of this grid geometry.
+ * @throws IllegalArgumentException if the indices are not in strictly
ascending order.
* @throws IndexOutOfBoundsException if an index is out of bounds.
*
* @see GridExtent#selectDimensions(int[])
* @see GridExtent#getSubspaceDimensions(int)
- * @see
org.apache.sis.referencing.CRS#selectDimensions(CoordinateReferenceSystem,
int[])
+ * @see GridDerivation#selectAxes(int[])
*
* @since 1.3
*/
diff --git
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridDerivationTest.java
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridDerivationTest.java
index 98aef0e5c7..6abb65f224 100644
---
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridDerivationTest.java
+++
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridDerivationTest.java
@@ -18,7 +18,6 @@ package org.apache.sis.coverage.grid;
import java.util.Map;
import java.util.Set;
-import java.util.function.Predicate;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import org.opengis.geometry.DirectPosition;
@@ -740,10 +739,10 @@ public final class GridDerivationTest extends TestCase {
}
/**
- * Tests {@link GridDerivation#selectDimensions(Predicate)}.
+ * Tests exclusion of <abbr>CRS</abbr> axes.
*/
@Test
- public void testProject() {
+ public void testExcludeAxes() {
final var grid = new GridGeometry(
new GridExtent(null, new long[] {336, 20, 4}, new long[] {401,
419, 10}, true),
PixelInCell.CELL_CORNER, MathTransforms.linear(new Matrix4(
@@ -752,7 +751,7 @@ public final class GridDerivationTest extends TestCase {
0, 0, 2, 3,
0, 0, 0, 1)), HardCodedCRS.WGS84_3D);
- GridGeometry projected =
grid.derive().excludeDimensions(Set.of(AxisDirection.UP)).build();
+ GridGeometry projected =
grid.derive().excludeAxes(Set.of(AxisDirection.UP)).build();
assertNotSame(grid, projected);
assertEquals(2, projected.getDimension());
assertTrue(CRS.equivalent(HardCodedCRS.WGS84,
projected.getCoordinateReferenceSystem()));