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 ad371b45bb Fix a few holes in the implementation of `createGridCRS`
and expand the test.
ad371b45bb is described below
commit ad371b45bb7968a6d26ec9ad4cc1df9f2cd74c22
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Apr 29 18:50:21 2026 +0200
Fix a few holes in the implementation of `createGridCRS` and expand the
test.
---
.../apache/sis/coverage/grid/GridCRSBuilder.java | 24 +++++----
.../apache/sis/coverage/grid/GridGeometryTest.java | 57 ++++++++++++++++------
2 files changed, 57 insertions(+), 24 deletions(-)
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 e9e95626bf..8244d295a7 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
@@ -56,6 +56,7 @@ import
org.apache.sis.referencing.operation.DefaultOperationMethod;
import org.apache.sis.referencing.operation.transform.TransformSeparator;
import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
import org.apache.sis.referencing.internal.shared.AxisDirections;
+import org.apache.sis.referencing.internal.shared.DirectPositionView;
import org.apache.sis.referencing.internal.shared.ReferencingFactoryContainer;
import org.apache.sis.feature.internal.Resources;
import org.apache.sis.util.ArraysExt;
@@ -184,6 +185,9 @@ final class GridCRSBuilder extends
ReferencingFactoryContainer {
grid.getGeographicExtent().ifPresent((domain) -> {
properties.put(ObjectDomain.DOMAIN_OF_VALIDITY_KEY, new
DefaultExtent(null, domain, null, null));
});
+ if (grid.isDefined(GridGeometry.EXTENT)) {
+ extent = grid.getExtent();
+ }
if (derived || grid.isDefined(GridGeometry.CRS |
GridGeometry.GRID_TO_CRS)) try {
separator = new
TransformSeparator(grid.getGridToCRS(anchor).inverse());
return forComponent(name, grid.getCoordinateReferenceSystem(), 0,
0);
@@ -197,12 +201,12 @@ final class GridCRSBuilder extends
ReferencingFactoryContainer {
*/
final int dimension = grid.getDimension();
final DimensionNameType[] dimensionNames;
- if (grid.extent != null) {
- dimensionNames = Arrays.copyOf(grid.extent.getAxisTypes(),
dimension);
+ if (extent != null) {
+ dimensionNames = Arrays.copyOf(extent.getAxisTypes(), dimension);
} else {
dimensionNames = new DimensionNameType[dimension];
}
- final CoordinateSystem cs = createCS(dimension, dimensionNames,
directions(dimensionNames), 0, true);
+ final CoordinateSystem cs = createCS(dimension, dimensionNames,
directions(dimensionNames), 1, true);
return getCRSFactory().createEngineeringCRS(properties(name),
CommonCRS.Engineering.GRID.datum(), cs);
}
@@ -281,7 +285,7 @@ final class GridCRSBuilder extends
ReferencingFactoryContainer {
toGrid: try {
final Matrix derivative;
if (extent != null) {
- derivative = extent.derivativeAtPOI(crsToGrid, anchor);
+ derivative = crsToGrid.derivative(new
DirectPositionView.Double(extent.getPointOfInterest(anchor), srcDim,
dimension));
} else try {
derivative = crsToGrid.derivative(null);
} catch (NullPointerException e) {
@@ -308,7 +312,7 @@ toGrid: try {
/*
* Creates the coordinate system, then the conversion, and finally the
derived CRS.
*/
- final CoordinateSystem cs = createCS(dispatch.length, dimensionNames,
directions, tgtDim, true);
+ final CoordinateSystem cs = createCS(dispatch.length, dimensionNames,
directions, tgtDim + 1, true);
final ParameterValueGroup params =
METHOD.getParameters().createValue();
params.parameter(ANCHOR_PARAM).setValue(anchor);
final var conversion = new
DefiningConversion(properties(METHOD.getName()), METHOD, crsToGrid, params);
@@ -343,12 +347,12 @@ toGrid: try {
* @param dimension number of dimensions of the coordinate system
to create.
* @param dimensionNames names of grid dimension. Shall not be null but
may contain null elements.
* @param directions directions of the axes of the coordinate system
to create. May contain null elements.
- * @param offset index of the first dimension in the final
{@link CompoundCRS}. Used for default axis names.
+ * @param labelOffset offset to add to the dimension for producing a
default axis name or abbreviation.
* @return coordinate system for the grid extent, or {@code null} if it
cannot be inferred.
* @throws FactoryException if an error occurred during the use of {@link
CSFactory}.
*/
private CoordinateSystem createCS(final int dimension, final
DimensionNameType[] dimensionNames,
- final AxisDirection[] directions, final int offset, final boolean
cartesian)
+ final AxisDirection[] directions, final int labelOffset, final
boolean cartesian)
throws FactoryException
{
final CSFactory csFactory = getCSFactory();
@@ -382,7 +386,7 @@ toGrid: try {
}
}
if (abbreviation == null) {
- final var b = new StringBuilder(4).append('x').append(offset +
j);
+ final var b = new
StringBuilder(4).append('x').append(labelOffset + j);
for (int i = b.length(); --i >= 1;) {
b.setCharAt(i, Characters.toSubScript(b.charAt(i)));
}
@@ -394,7 +398,7 @@ toGrid: try {
*/
String name = Types.toString(Types.getCodeTitle(type), LOCALE);
if (name == null) {
- name =
Vocabulary.forLocale(LOCALE).getString(Vocabulary.Keys.Dimension_1, offset + j);
+ name =
Vocabulary.forLocale(LOCALE).getString(Vocabulary.Keys.Dimension_1, labelOffset
+ j);
}
AxisDirection direction = directions[j];
if (direction == null) {
@@ -525,7 +529,7 @@ toGrid: try {
final var dimensionNames = new DimensionNameType[dimension];
AxisDirection[] directions = directions(ArraysExt.resize(types,
dimension));
directions = reorder(directions, derivative, types, dimensionNames);
- final CoordinateSystem cs = createCS(dimension, dimensionNames,
directions, 0, false);
+ final CoordinateSystem cs = createCS(dimension, dimensionNames,
directions, 1, false);
if (cs == null) {
return Optional.empty();
}
diff --git
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java
index 7bb3a95c42..4c03cc09fe 100644
---
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java
+++
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -22,7 +22,10 @@ import org.opengis.util.FactoryException;
import org.opengis.geometry.Envelope;
import org.opengis.metadata.Identifier;
import org.opengis.metadata.spatial.DimensionNameType;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.referencing.ObjectDomain;
import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.crs.DerivedCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -46,9 +49,11 @@ import org.apache.sis.util.ComparisonMode;
// Test dependencies
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
+import static org.opengis.test.Assertions.assertAxisDirectionsEqual;
import org.apache.sis.test.TestCase;
import org.apache.sis.referencing.crs.HardCodedCRS;
import org.apache.sis.referencing.operation.HardCodedConversions;
+import static org.apache.sis.test.Assertions.assertSingleton;
import static org.apache.sis.test.Assertions.assertSetEquals;
import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.referencing.Assertions.assertMatrixEquals;
@@ -822,36 +827,60 @@ public final class GridGeometryTest extends TestCase {
public void testCreateGridCRS() throws FactoryException {
final var gg = new GridGeometry(
new GridExtent(null, null, new long[] {17, 10, 4}, true),
- PixelInCell.CELL_CENTER,
+ PixelInCell.CELL_CORNER,
MathTransforms.linear(new Matrix4(
- 1, 0, 0, -7,
- 0, -1, 0, 50,
- 0, 0, 8, 20,
+ 0, -1, 0, 50, // Longitude
+ 1, 0, 0, -7, // Latitude
+ 0, 0, 8, 20, // Time
0, 0, 0, 1)),
HardCodedCRS.WGS84_WITH_TIME);
-
+ /*
+ * Metadata about the CRS as a whole (a CompoundCRS).
+ * Axes are like "Dimension 1 (x₁)" because we did not
+ * specified some `DimentionNameType` parameter values.
+ */
final Identifier name = new ImmutableIdentifier(null, null, "Tested
grid CRS");
- final CoordinateReferenceSystem crs = gg.createGridCRS(name,
PixelInCell.CELL_CENTER);
+ final CoordinateReferenceSystem crs = gg.createGridCRS(name,
PixelInCell.CELL_CORNER);
+ final ObjectDomain domain = assertSingleton(crs.getDomains());
+ final GeographicBoundingBox bbox =
assertInstanceOf(GeographicBoundingBox.class,
+
assertSingleton(domain.getDomainOfValidity().getGeographicElements()));
+ assertEquals(39, bbox.getWestBoundLongitude());
+ assertEquals(50, bbox.getEastBoundLongitude());
+ assertEquals(-7, bbox.getSouthBoundLatitude());
+ assertEquals(11, bbox.getNorthBoundLatitude());
+ assertNotNull(domain.getScope()); // Text depends on the locale.
assertSame(name, crs.getName());
-
+ /*
+ * Check the horizontal and temporal components.
+ */
final List<SingleCRS> components = CRS.getSingleComponents(crs);
assertEquals(2, components.size());
-
final var horizontal = assertInstanceOf(DerivedCRS.class,
components.get(0));
+ final var temporal = assertInstanceOf(DerivedCRS.class,
components.get(1));
assertSame(HardCodedCRS.WGS84, horizontal.getBaseCRS());
+ assertSame(HardCodedCRS.TIME, temporal .getBaseCRS());
+ assertAxisDirectionsEqual(horizontal.getCoordinateSystem(),
AxisDirection.NORTH, AxisDirection.WEST);
+ assertAxisDirectionsEqual(temporal .getCoordinateSystem(),
AxisDirection.FUTURE);
assertMatrixEquals(
- new Matrix3(1, 0, 7, // Opposite sign because this is
the inverse transform.
- 0, -1, 50, // Opposite sign cancelled by -1
scale factor.
- 0, 0, 1),
+ new Matrix3(0, 1, 7, // Opposite sign of translation term
because this is the inverse transform.
+ -1, 0, 50, // Reminder: sign of translation term
is inversed by the scale factor -1.
+ 0, 0, 1),
horizontal.getConversionFromBase().getMathTransform(),
"CRS to grid");
-
- final var temporal = assertInstanceOf(DerivedCRS.class,
components.get(1));
- assertSame(HardCodedCRS.TIME, temporal.getBaseCRS());
assertMatrixEquals(
new Matrix2(0.125, -2.5, 0, 1),
temporal.getConversionFromBase().getMathTransform(),
"CRS to grid");
+ /*
+ * Check axis names. The grid dimension which is mapped to longitudes
has its direction
+ * reversed because of the -1 sign in the scale factor.
+ */
+ final CoordinateSystem cs = crs.getCoordinateSystem();
+ assertEquals(3, cs.getDimension());
+ assertEquals("x₁", cs.getAxis(0).getAbbreviation());
+ assertEquals("x₂", cs.getAxis(1).getAbbreviation());
+ assertEquals("t", cs.getAxis(2).getAbbreviation());
+ assertAxisDirectionsEqual(cs, AxisDirection.NORTH, AxisDirection.WEST,
AxisDirection.FUTURE);
}
/**