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 7ed0df72f30a51c0d4aa2a17957eb9761364d5b4 Author: Martin Desruisseaux <[email protected]> AuthorDate: Fri Apr 12 17:36:17 2024 +0200 As a consequence of the change in previous commit, remove the SIS-specific "dim" parameter in Geographic/Geocentric conversions. That parameter was not part of OGC standard neither in EPSG database. It was a hack needed by SIS as a way to specify the desired number of dimensions, but this hack is no longer needed now. --- .../operation/CoordinateOperationFinder.java | 8 +---- .../provider/FranceGeocentricInterpolation.java | 16 ++------- .../GeocentricAffineBetweenGeographic.java | 16 ++++----- .../operation/provider/GeocentricToGeographic.java | 4 +-- .../operation/provider/GeographicToGeocentric.java | 42 ++++------------------ .../referencing/operation/provider/Molodensky.java | 15 ++------ .../referencing/operation/provider/Wraparound.java | 5 ++- .../transform/DefaultMathTransformFactory.java | 3 -- .../transform/EllipsoidToCentricTransform.java | 8 ++--- .../operation/transform/MolodenskyTransform.java | 1 + 10 files changed, 30 insertions(+), 88 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java index b6635b8178..985ad9e777 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java @@ -626,21 +626,15 @@ public class CoordinateOperationFinder extends CoordinateOperationRegistry { } } else if (identifier == GEOCENTRIC_CONVERSION) { /* - * Geographic ↔︎ Geocentric conversion. The "dim" parameter is Apache SIS specific but is guaranteed - * to be present since we use SIS parameter descriptors directly. The default number of dimension is 3, - * but we specify the value unconditionally anyway as a safety. + * Geographic ↔︎ Geocentric conversion. */ final ParameterDescriptorGroup descriptor; - final GeodeticCRS geographic; if (isGeographicToGeocentric) { - geographic = sourceCRS; descriptor = GeographicToGeocentric.PARAMETERS; } else { - geographic = targetCRS; descriptor = GeocentricToGeographic.PARAMETERS; } parameters = descriptor.createValue(); - parameters.parameter(Constants.DIM).setValue(geographic.getCoordinateSystem().getDimension()); } else { /* * Coordinate system change (including change in the number of dimensions) without datum shift. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/FranceGeocentricInterpolation.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/FranceGeocentricInterpolation.java index b17cd63b6d..9c4e08516d 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/FranceGeocentricInterpolation.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/FranceGeocentricInterpolation.java @@ -34,7 +34,6 @@ import javax.measure.quantity.Length; import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.parameter.ParameterNotFoundException; -import org.opengis.parameter.InvalidParameterValueException; import org.opengis.referencing.datum.Ellipsoid; import org.opengis.referencing.cs.EllipsoidalCS; import org.opengis.referencing.operation.Transformation; @@ -56,7 +55,6 @@ import org.apache.sis.measure.Units; import org.apache.sis.util.CharSequences; import org.apache.sis.util.logging.Logging; import org.apache.sis.util.resources.Errors; -import static org.apache.sis.util.privy.Constants.DIM; /** @@ -281,16 +279,8 @@ public final class FranceGeocentricInterpolation extends AbstractProvider { */ @Override public MathTransform createMathTransform(final Context context) throws FactoryException { - int n = 2; // Default number of dimensions. final Parameters pg = Parameters.castOrWrap(context.getCompletedParameters()); - final Integer dim = pg.getValue(Molodensky.DIMENSION); - if (dim != null) { - n = dim; // Unboxing. - if (n < 2 || n > 3) { - throw new InvalidParameterValueException(Errors.format( - Errors.Keys.IllegalArgumentValue_2, DIM, dim), DIM, dim); - } - } + final int dim = pg.getValue(Molodensky.DIMENSION); final GridFile file = new GridFile(pg, FILE); final LoadedGrid<Angle,Length> grid; try { @@ -304,11 +294,11 @@ public final class FranceGeocentricInterpolation extends AbstractProvider { createEllipsoid(pg, Molodensky.TGT_SEMI_MAJOR, Molodensky.TGT_SEMI_MINOR, CommonCRS.ETRS89.ellipsoid()), // GRS 1980 ellipsoid - context.getTargetDimensions().orElse(n) >= 3, + context.getTargetDimensions().orElse(dim) >= 3, createEllipsoid(pg, Molodensky.SRC_SEMI_MAJOR, Molodensky.SRC_SEMI_MINOR, null), // Clarke 1880 (IGN) ellipsoid - context.getSourceDimensions().orElse(n) >= 3, + context.getSourceDimensions().orElse(dim) >= 3, grid); try { tr = tr.inverse(); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricAffineBetweenGeographic.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricAffineBetweenGeographic.java index 1f5b29e874..fd561617da 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricAffineBetweenGeographic.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricAffineBetweenGeographic.java @@ -58,15 +58,11 @@ public abstract class GeocentricAffineBetweenGeographic extends GeocentricAffine /** * The operation parameter descriptor for the number of source and target geographic dimensions (2 or 3). - * This is an OGC-specific parameter for the {@link Molodensky} and {@link AbridgedMolodensky} operations, - * but Apache SIS uses it also for internal parameters of Geographic/Geocentric. + * This is an OGC-specific parameter for the {@link Molodensky} and {@link AbridgedMolodensky} operations. * - * <p>We do not provide default value for this parameter (neither we do for other OGC-specific parameters - * in this class) because this parameter is used with both two- and three-dimensional operation methods. - * If we want to provide a default value, we could but it would complicate a little bit the code because - * we could no longer reuse the same {@code PARAMETERS} constant for all operation methods.</p> - * - * @see GeographicToGeocentric#DIMENSION + * <p>A default value is needed for avoiding the need to check for null values. This is set to 2 dimensions. + * Note that the value of this parameter is ignored if the math transform is built with a {@link Context} + * that specifies the number of source and/or target dimensions.</p> * * <!-- Generated by ParameterNameTableGenerator --> * <table class="sis"> @@ -76,7 +72,7 @@ public abstract class GeocentricAffineBetweenGeographic extends GeocentricAffine * <b>Notes:</b> * <ul> * <li>Value domain: [2…3]</li> - * <li>No default value</li> + * <li>Default value: 2</li> * <li>Optional</li> * </ul> */ @@ -159,7 +155,7 @@ public abstract class GeocentricAffineBetweenGeographic extends GeocentricAffine SRC_SEMI_MINOR = builder.addName("src_semi_minor").createStrictlyPositive(Double.NaN, Units.METRE); TGT_SEMI_MAJOR = builder.addName("tgt_semi_major").createStrictlyPositive(Double.NaN, Units.METRE); TGT_SEMI_MINOR = builder.addName("tgt_semi_minor").createStrictlyPositive(Double.NaN, Units.METRE); - DIMENSION = builder.addName(Constants.DIM).setRequired(false).createBounded(Integer.class, 2, 3, null); + DIMENSION = builder.addName(Constants.DIM).setRequired(false).createBounded(Integer.class, 2, 3, 2); } /** diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricToGeographic.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricToGeographic.java index ef87a028de..e546342c0a 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricToGeographic.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeocentricToGeographic.java @@ -52,7 +52,7 @@ public final class GeocentricToGeographic extends AbstractProvider { static { PARAMETERS = builder() .addName(Citations.OGC, NAME) - .createGroupForMapProjection(GeographicToGeocentric.DIMENSION); + .createGroupForMapProjection(); // Not really a map projection, but we leverage the same axis parameters. } @@ -75,7 +75,7 @@ public final class GeocentricToGeographic extends AbstractProvider { */ @Override public MathTransform createMathTransform(final Context context) throws FactoryException { - MathTransform tr = GeographicToGeocentric.create(context, context.getTargetDimensions().orElse(-1)); + MathTransform tr = GeographicToGeocentric.create(context, context.getTargetDimensions()); try { tr = tr.inverse(); } catch (NoninvertibleTransformException e) { diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeographicToGeocentric.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeographicToGeocentric.java index a58116674f..dc06f87144 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeographicToGeocentric.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/GeographicToGeocentric.java @@ -16,11 +16,11 @@ */ package org.apache.sis.referencing.operation.provider; +import java.util.OptionalInt; import javax.measure.Unit; import javax.measure.quantity.Length; import org.opengis.util.FactoryException; import org.opengis.parameter.ParameterValue; -import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.referencing.cs.CartesianCS; import org.opengis.referencing.cs.EllipsoidalCS; @@ -29,7 +29,6 @@ import org.opengis.referencing.operation.MathTransform; import org.apache.sis.referencing.operation.transform.EllipsoidToCentricTransform; import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory; import org.apache.sis.metadata.iso.citation.Citations; -import org.apache.sis.parameter.ParameterBuilder; import org.apache.sis.parameter.Parameters; import org.apache.sis.util.privy.Constants; @@ -54,44 +53,16 @@ public final class GeographicToGeocentric extends AbstractProvider { */ public static final String NAME = "Ellipsoid_To_Geocentric"; - /** - * An Apache SIS specific parameter for the number of dimensions (2 or 3). - * This parameter is practically the same as {@link GeocentricAffineBetweenGeographic#DIMENSION} except: - * - * <ul> - * <li>The code space is {@code "SIS"} instead of {@code "OGC"} - * because this parameter is not defined in OGC 01-009.</li> - * <li>The default number of dimensions is 3 instead of unspecified.</li> - * </ul> - * - * @see GeocentricAffineBetweenGeographic#DIMENSION - * - * <!-- Generated by ParameterNameTableGenerator --> - * <table class="sis"> - * <caption>Parameter names</caption> - * <tr><td> SIS: </td><td> dim </td></tr> - * </table> - * <b>Notes:</b> - * <ul> - * <li>Value domain: [2…3]</li> - * <li>Default value: 3</li> - * <li>Optional</li> - * </ul> - */ - public static final ParameterDescriptor<Integer> DIMENSION; - /** * The group of all parameters expected by this coordinate operation. */ public static final ParameterDescriptorGroup PARAMETERS; static { - final ParameterBuilder builder = builder(); - DIMENSION = builder.addName(Citations.SIS, Constants.DIM).setRequired(false).createBounded(Integer.class, 2, 3, 3); - PARAMETERS = builder + PARAMETERS = builder() .addIdentifier("9602") .addName("Geographic/geocentric conversions") .addName(Citations.OGC, NAME) - .createGroupForMapProjection(DIMENSION); + .createGroupForMapProjection(); // Not really a map projection, but we leverage the same axis parameters. } @@ -136,19 +107,18 @@ public final class GeographicToGeocentric extends AbstractProvider { */ @Override public MathTransform createMathTransform(final Context context) throws FactoryException { - return create(context, context.getSourceDimensions().orElse(-1)); + return create(context, context.getSourceDimensions()); } /** * Implementation of {@link #createMathTransform(Context)} shared with {@link GeocentricToGeographic}. */ - static MathTransform create(final Context context, int dimensions) throws FactoryException { + static MathTransform create(final Context context, final OptionalInt dimension) throws FactoryException { final Parameters values = Parameters.castOrWrap(context.getCompletedParameters()); - if (dimensions < 0) dimensions = values.intValue(DIMENSION); final ParameterValue<?> semiMajor = values.parameter(Constants.SEMI_MAJOR); final Unit<Length> unit = semiMajor.getUnit().asType(Length.class); return EllipsoidToCentricTransform.createGeodeticConversion(context.getFactory(), semiMajor.doubleValue(), - values.parameter(Constants.SEMI_MINOR).doubleValue(unit), unit, dimensions >= 3, + values.parameter(Constants.SEMI_MINOR).doubleValue(unit), unit, dimension.orElse(3) >= 3, EllipsoidToCentricTransform.TargetType.CARTESIAN); } } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Molodensky.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Molodensky.java index 5eae6c5d3c..c366fe45f2 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Molodensky.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Molodensky.java @@ -35,7 +35,6 @@ import org.apache.sis.referencing.privy.Formulas; import org.apache.sis.util.Debug; import org.apache.sis.util.privy.Constants; import org.apache.sis.measure.Units; -import org.apache.sis.util.resources.Errors; /** @@ -174,16 +173,8 @@ public final class Molodensky extends GeocentricAffineBetweenGeographic { * @throws FactoryException if a transform cannot be created. */ static MathTransform createMathTransform(final Context context, final boolean isAbridged) throws FactoryException { - int n = 2; // Default number of dimensions. final Parameters values = Parameters.castOrWrap(context.getCompletedParameters()); - final Integer dim = values.getValue(DIMENSION); - if (dim != null) { - n = dim; // Unboxing. - if (n != 2 && n != 3) { - throw new InvalidParameterValueException(Errors.format( - Errors.Keys.IllegalArgumentValue_2, Constants.DIM, dim), Constants.DIM, dim); - } - } + final int dim = values.getValue(DIMENSION); /* * Following method calls implicitly convert parameter values to metres. * We do not try to match ellipsoid axis units because: @@ -213,8 +204,8 @@ public final class Molodensky extends GeocentricAffineBetweenGeographic { source.computeDifferences(values); return MolodenskyTransform.createGeodeticTransformation( context.getFactory(), - source, context.getSourceDimensions().orElse(n) >= 3, - target, context.getTargetDimensions().orElse(n) >= 3, + source, context.getSourceDimensions().orElse(dim) >= 3, + target, context.getTargetDimensions().orElse(dim) >= 3, values.doubleValue(TX), values.doubleValue(TY), values.doubleValue(TZ), diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Wraparound.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Wraparound.java index 3ee6445971..0dbf6bba12 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Wraparound.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/Wraparound.java @@ -27,6 +27,7 @@ import org.apache.sis.parameter.Parameters; import org.apache.sis.parameter.ParameterBuilder; import org.apache.sis.metadata.iso.citation.Citations; import org.apache.sis.referencing.operation.transform.WraparoundTransform; +import org.apache.sis.util.privy.Constants; /** @@ -43,6 +44,8 @@ public final class Wraparound extends AbstractProvider { /** * The operation parameter descriptor for the number of source and target dimensions. + * Contrarily to {@link GeocentricAffineBetweenGeographic#DIMENSION}, this parameter + * has no constraint on the number of dimensions and no default value. * * <!-- Generated by ParameterNameTableGenerator --> * <table class="sis"> @@ -95,7 +98,7 @@ public final class Wraparound extends AbstractProvider { public static final ParameterDescriptorGroup PARAMETERS; static { final ParameterBuilder builder = builder().setCodeSpace(Citations.SIS, "SIS"); - DIMENSION = builder.addName(Molodensky.DIMENSION.getName()).createBounded(Integer.class, 1, null, null); + DIMENSION = builder.addName(Constants.DIM).createBounded(Integer.class, 1, null, null); WRAPAROUND_DIMENSION = builder.addName("wraparound_dim").createBounded(Integer.class, 0, null, null); PERIOD = builder.addName("period").createStrictlyPositive(Double.NaN, null); PARAMETERS = builder.addName("Wraparound") diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java index 4302330e07..83750adbdd 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java @@ -1571,9 +1571,6 @@ public class DefaultMathTransformFactory extends AbstractFactory implements Math context.targetEllipsoid = ellipsoid; } final ParameterValueGroup pg = getDefaultParameters(operation); - if (cs.getDimension() < 3) { - pg.parameter(Constants.DIM).setValue(2); // Apache SIS specific parameter. - } return createParameterizedTransform(pg, context); } } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java index 4247297bcb..2a7a0280f3 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java @@ -60,7 +60,7 @@ import org.apache.sis.metadata.iso.citation.Citations; import static org.apache.sis.referencing.operation.provider.MapProjection.SEMI_MAJOR; import static org.apache.sis.referencing.operation.provider.MapProjection.SEMI_MINOR; import static org.apache.sis.referencing.operation.provider.MapProjection.ECCENTRICITY; -import static org.apache.sis.referencing.operation.provider.GeographicToGeocentric.DIMENSION; +import static org.apache.sis.referencing.operation.provider.GeocentricAffineBetweenGeographic.DIMENSION; /** @@ -276,9 +276,9 @@ public class EllipsoidToCentricTransform extends AbstractMathTransform implement * Copy parameters to the ContextualParameter. Those parameters are not used directly by * EllipsoidToCentricTransform, but we need to store them in case the user asks for them. * - * Note: we do not store the `DIMENSION` parameter because that parameter is not defined by OGC 01-009. - * Instead, this transform should be thought as always operating in 3 dimensions with a "2D to 3D" step - * prefixed if needed. The WKT is handled in a special way for inserting that step if needed. + * Note: There is no `DIMENSION` parameter here because no such parameter is defined by OGC 01-009. + * Instead, this transform should be thought as always operating in 3 dimensions with a "2D to 3D" + * step prefixed if needed. The WKT is handled in a special way for inserting that step if needed. */ context = new ContextualParameters(GeographicToGeocentric.PARAMETERS, withHeight ? 3 : 2, 3); context.getOrCreate(SEMI_MAJOR).setValue(semiMajor, unit); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java index f4e0a98cf6..972efc0872 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java @@ -231,6 +231,7 @@ public class MolodenskyTransform extends DatumShiftTransform { * * @see #createGeodeticTransformation(MathTransformFactory, Ellipsoid, boolean, Ellipsoid, boolean, double, double, double, boolean) */ + @SuppressWarnings("this-escape") public MolodenskyTransform(final Ellipsoid source, final boolean isSource3D, final Ellipsoid target, final boolean isTarget3D, final double tX, final double tY, final double tZ,
