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 1112c88a0c53830c298ae8845b55dd8d6fa0dee4 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Jul 6 13:05:32 2024 +0200 Remove `ReferencingUtilities.builder(…)`, replaced by direct uses of `ParameterizedTransformBuilder`. --- .../referencing/factory/sql/EPSGDataAccess.java | 12 +++--- .../internal/ParameterizedTransformBuilder.java | 50 +++++++++++++++++++--- .../operation/AbstractSingleOperation.java | 11 +++-- .../operation/CoordinateOperationFinder.java | 2 +- .../operation/CoordinateOperationRegistry.java | 31 ++++++++++++-- .../referencing/operation/DefaultConversion.java | 16 +++---- .../DefaultCoordinateOperationFactory.java | 9 ++-- .../transform/DefaultMathTransformFactory.java | 9 ++-- .../referencing/privy/ReferencingUtilities.java | 37 ---------------- 9 files changed, 105 insertions(+), 72 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java index f4694584cd..de31e5a7e4 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java @@ -73,7 +73,6 @@ import org.apache.sis.referencing.AbstractIdentifiedObject; import org.apache.sis.referencing.privy.WKTKeywords; import org.apache.sis.referencing.privy.CoordinateOperations; import org.apache.sis.referencing.privy.ReferencingFactoryContainer; -import org.apache.sis.referencing.privy.ReferencingUtilities; import org.apache.sis.referencing.privy.Formulas; import org.apache.sis.metadata.sql.privy.SQLUtilities; import org.apache.sis.referencing.internal.DeferredCoordinateOperation; @@ -109,6 +108,7 @@ import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory; import org.apache.sis.referencing.factory.FactoryDataException; import org.apache.sis.referencing.factory.GeodeticAuthorityFactory; import org.apache.sis.referencing.factory.IdentifiedObjectFinder; +import org.apache.sis.referencing.internal.ParameterizedTransformBuilder; import org.apache.sis.util.collection.BackingStoreException; import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.util.resources.Errors; @@ -2949,9 +2949,11 @@ next: while (r.next()) { * GeoAPI method cannot handle Molodensky transform because it does not give the target datum). */ opProperties = new HashMap<>(opProperties); // Because this class uses a shared map. - final MathTransformFactory mtFactory = owner.mtFactory; - final MathTransform mt = ReferencingUtilities.builder( - mtFactory, parameters, sourceCRS, targetCRS).create(); + final var builder = new ParameterizedTransformBuilder(owner.mtFactory, null); + builder.setParameters(parameters, true); + builder.setSourceAxes(sourceCRS); + builder.setTargetAxes(targetCRS); + final MathTransform mt = builder.create(); /* * Give a hint to the factory about the type of the coordinate operation. ISO 19111 defines * Conversion and Transformation, but SIS also have more specific sub-types. We begin with @@ -2966,7 +2968,7 @@ next: while (r.next()) { } else { opType = SingleOperation.class; } - final OperationMethod provider = mtFactory.getLastMethodUsed(); + final OperationMethod provider = builder.getMethod().orElse(null); if (provider instanceof DefaultOperationMethod) { // SIS-specific final Class<?> s = ((DefaultOperationMethod) provider).getOperationType(); if (s != null && opType.isAssignableFrom(s)) { diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java index f770546166..bab03dcdb0 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java @@ -38,6 +38,7 @@ import org.opengis.referencing.operation.Matrix; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.MathTransformFactory; import org.opengis.referencing.operation.OperationMethod; +import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.util.NoSuchIdentifierException; import org.opengis.util.FactoryException; import org.apache.sis.util.ArgumentChecks; @@ -59,8 +60,10 @@ import org.apache.sis.referencing.operation.transform.MathTransformProvider; import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory; import org.apache.sis.referencing.factory.InvalidGeodeticParameterException; import org.apache.sis.referencing.privy.CoordinateOperations; +import org.apache.sis.referencing.privy.ReferencingUtilities; import org.apache.sis.referencing.privy.Formulas; import org.apache.sis.parameter.Parameterized; +import org.apache.sis.parameter.Parameters; import org.apache.sis.measure.Units; // Specific to the geoapi-3.1 and geoapi-4.0 branches: @@ -126,7 +129,7 @@ public class ParameterizedTransformBuilder implements MathTransform.Builder, Mat * <p>This reference is {@code null} if this builder has been constructed without * specifying a method or parameters. In such case, calls to {@link #parameters()} * or {@link #getCompletedParameters()} will throw {@link IllegalStateException}, - * unless {@link #setParameters(ParameterValueGroup)} is invoked.</p> + * unless {@link #setParameters(ParameterValueGroup, boolean)} is invoked.</p> */ private ParameterValueGroup parameters; @@ -169,14 +172,29 @@ public class ParameterizedTransformBuilder implements MathTransform.Builder, Mat } /** - * Replaces the parameters by the given values; + * Replaces the parameters by the given values. If {@code copy} is {@code false}, the given parameters + * will be used directly and may be modified. If {@code true}, the parameters will be copied in a group + * created by the provider. The latter group may contain more parameters than the given {@code values}. + * In particular, the copy may contain parameters such as {@code "semi_major"} that may not be present + * in the given values. * * @param values the parameter values. + * @param copy whether to copy the given parameter values. * @throws NoSuchIdentifierException if no method has been found for the given parameters. + * @throws InvalidGeodeticParameterException if the parameters cannot be set to the given values. */ - public void setParameters(final ParameterValueGroup values) throws NoSuchIdentifierException { - parameters = values; - provider = CoordinateOperations.findMethod(factory, parameters.getDescriptor()); + public void setParameters(final ParameterValueGroup values, final boolean copy) + throws NoSuchIdentifierException, InvalidGeodeticParameterException + { + provider = CoordinateOperations.findMethod(factory, values.getDescriptor()); + if (copy) try { + parameters = provider.getParameters().createValue(); + Parameters.copy(values, parameters); + } catch (IllegalArgumentException e) { + throw new InvalidGeodeticParameterException(e.getMessage(), e); + } else { + parameters = values; + } } /** @@ -189,6 +207,28 @@ public class ParameterizedTransformBuilder implements MathTransform.Builder, Mat return factory; } + /** + * Gives input coordinates hints derived from the given <abbr>CRS</abbr>. The hints are used for axis order and + * units conversions, and for completing parameters with axis lengths. No change of <abbr>CRS</abbr> other than + * axis order and units are performed. This method is not public for that reason. + * + * @param crs the <abbr>CRS</abbr> from which to fetch the hints, or {@code null}. + */ + public final void setSourceAxes(final CoordinateReferenceSystem crs) { + setSourceAxes(crs != null ? crs.getCoordinateSystem() : null, ReferencingUtilities.getEllipsoid(crs)); + } + + /** + * Gives output coordinates hints derived from the given <abbr>CRS</abbr>. The hints are used for axis order and + * units conversions, and for completing parameters with axis lengths. No change of <abbr>CRS</abbr> other than + * axis order and units are performed. This method is not public for that reason. + * + * @param crs the <abbr>CRS</abbr> from which to fetch the hints, or {@code null}. + */ + public final void setTargetAxes(final CoordinateReferenceSystem crs) { + setTargetAxes(crs != null ? crs.getCoordinateSystem() : null, ReferencingUtilities.getEllipsoid(crs)); + } + /** * Gives hints about axis lengths and their orientations in input coordinates. * The {@code ellipsoid} argument is often provided together with an {@link EllipsoidalCS}, but not only. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/AbstractSingleOperation.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/AbstractSingleOperation.java index de3287b2e1..8c0c65cbad 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/AbstractSingleOperation.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/AbstractSingleOperation.java @@ -45,10 +45,10 @@ import org.apache.sis.xml.bind.referencing.CC_OperationParameterGroup; import org.apache.sis.xml.bind.referencing.CC_OperationMethod; import org.apache.sis.referencing.GeodeticException; import org.apache.sis.referencing.privy.CoordinateOperations; -import org.apache.sis.referencing.privy.ReferencingUtilities; +import org.apache.sis.referencing.internal.ParameterizedTransformBuilder; +import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory; import org.apache.sis.metadata.privy.ImplementationHelper; import org.apache.sis.metadata.privy.Identifiers; -import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.ComparisonMode; import org.apache.sis.util.collection.Containers; @@ -468,8 +468,11 @@ class AbstractSingleOperation extends AbstractCoordinateOperation implements Sin final CoordinateReferenceSystem sourceCRS = super.getSourceCRS(); final CoordinateReferenceSystem targetCRS = super.getTargetCRS(); if (transform == null && sourceCRS != null && targetCRS != null && parameters != null) try { - transform = ReferencingUtilities.builder(DefaultMathTransformFactory.provider(), - parameters, sourceCRS, targetCRS).create(); + final var builder = new ParameterizedTransformBuilder(DefaultMathTransformFactory.provider(), null); + builder.setParameters(parameters, true); + builder.setSourceAxes(sourceCRS); + builder.setTargetAxes(targetCRS); + transform = builder.create(); } catch (FactoryException e) { Context.warningOccured(Context.current(), AbstractSingleOperation.class, "afterUnmarshal", e, true); } 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 54139b2fa6..6200fb4977 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 @@ -674,7 +674,7 @@ public class CoordinateOperationFinder extends CoordinateOperationRegistry { * Context parameter. The operation name is inferred from the parameters, unless a method has been * specified in advance. */ - context.setParameters(parameters); + context.setParameters(parameters, false); MathTransform transform = context.create(); if (method == null) { method = context.getMethod().orElse(null); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java index 157387066c..7edfc6f93f 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java @@ -64,6 +64,7 @@ import org.apache.sis.referencing.privy.CoordinateOperations; import org.apache.sis.referencing.privy.EllipsoidalHeightCombiner; import org.apache.sis.referencing.privy.PositionalAccuracyConstant; import org.apache.sis.referencing.privy.ReferencingUtilities; +import org.apache.sis.referencing.internal.ParameterizedTransformBuilder; import org.apache.sis.referencing.internal.DeferredCoordinateOperation; import org.apache.sis.referencing.internal.Resources; import org.apache.sis.referencing.operation.provider.Affine; @@ -1022,8 +1023,7 @@ class CoordinateOperationRegistry { CoordinateReferenceSystem crs; if (Utilities.equalsApproximately(sourceCRS, crs = operation.getSourceCRS())) sourceCRS = crs; if (Utilities.equalsApproximately(targetCRS, crs = operation.getTargetCRS())) targetCRS = crs; - var builder = ReferencingUtilities.builder( - factorySIS.getMathTransformFactory(), parameters, sourceCRS, targetCRS); + final var builder = createTransformBuilder(parameters, sourceCRS, targetCRS); final MathTransform mt = builder.create(); // Must be before `operation.getMethod()`. return factorySIS.createSingleOperation(IdentifiedObjects.getProperties(operation), sourceCRS, targetCRS, null, operation.getMethod(), mt); @@ -1137,14 +1137,13 @@ class CoordinateOperationRegistry { Matrix matrix = MathTransforms.getMatrix(op.getMathTransform()); if (matrix == null) { if (op instanceof SingleOperation) { - final MathTransformFactory mtFactory = factorySIS.getMathTransformFactory(); if (forward) sourceCRS = toGeodetic3D(sourceCRS, source3D); else targetCRS = toGeodetic3D(targetCRS, target3D); final MathTransform.Builder builder; final MathTransform mt; try { final var parameters = ((SingleOperation) op).getParameterValues(); - builder = ReferencingUtilities.builder(mtFactory, parameters, sourceCRS, targetCRS); + builder = createTransformBuilder(parameters, sourceCRS, targetCRS); mt = builder.create(); } catch (InvalidGeodeticParameterException e) { log(null, e); @@ -1251,6 +1250,30 @@ class CoordinateOperationRegistry { return properties; } + /** + * Creates a transform builder which will use the given <abbr>CRS</abbr> as contextual information. + * The ellipsoids will be used for completing the axis-length parameters, and the coordinate systems will + * be used for axis order and units of measurement. This method does not perform <abbr>CRS</abbr> changes + * other than axis order and units. + * + * @param parameters the operation parameter value group. + * @param sourceCRS the CRS from which to get the source coordinate system and ellipsoid. + * @param targetCRS the CRS from which to get the target coordinate system and ellipsoid. + * @return the parameterized transform. + * @throws FactoryException if the transform cannot be created. + */ + private MathTransform.Builder createTransformBuilder( + final ParameterValueGroup parameters, + final CoordinateReferenceSystem sourceCRS, + final CoordinateReferenceSystem targetCRS) throws FactoryException + { + final var builder = new ParameterizedTransformBuilder(factorySIS.getMathTransformFactory(), null); + builder.setParameters(parameters, true); + builder.setSourceAxes(sourceCRS); + builder.setTargetAxes(targetCRS); + return builder; + } + /** * Creates a coordinate operation from a math transform. * The method performs the following steps: diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConversion.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConversion.java index d54d36d42c..cd485a045b 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConversion.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConversion.java @@ -247,10 +247,10 @@ public class DefaultConversion extends AbstractSingleOperation implements Conver * method in invoked, and attempts to use it can cause NullPointerException. */ final boolean isDerived = (target instanceof DerivedCRS); - var builder = ReferencingUtilities.builder(factory, parameters, source, isDerived ? null : target); - if (isDerived) { - builder.setTargetAxes(target.getCoordinateSystem(), null); - } + final var builder = new ParameterizedTransformBuilder(factory, null); + builder.setParameters(parameters, true); + builder.setSourceAxes(source); + builder.setTargetAxes(target.getCoordinateSystem(), isDerived ? null : ReferencingUtilities.getEllipsoid(target)); transform = builder.create(); if (builder instanceof MathTransformProvider.Context) { final var context = (MathTransformProvider.Context) builder; @@ -263,10 +263,10 @@ public class DefaultConversion extends AbstractSingleOperation implements Conver * ProjectedCRS), then there is a method for this job. */ if (sourceCRS == null && targetCRS == null) { - var context = new ParameterizedTransformBuilder(factory, null); - context.setSourceAxes(source.getCoordinateSystem(), null); - context.setTargetAxes(target.getCoordinateSystem(), null); // See comment on the other setTargetAxes(…) call. - transform = context.swapAndScaleAxes(transform); + var builder = new ParameterizedTransformBuilder(factory, null); + builder.setSourceAxes(source.getCoordinateSystem(), null); + builder.setTargetAxes(target.getCoordinateSystem(), null); // See comment on the other setTargetAxes(…) call. + transform = builder.swapAndScaleAxes(transform); } else { /* * If this conversion is not a defining conversion (i.e. if this is the conversion of an existing diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java index 5341d69389..4064e84ed3 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java @@ -38,7 +38,6 @@ import org.apache.sis.referencing.internal.Resources; import org.apache.sis.referencing.internal.MergedProperties; import org.apache.sis.referencing.privy.CoordinateOperations; import org.apache.sis.referencing.privy.ReferencingFactoryContainer; -import org.apache.sis.referencing.privy.ReferencingUtilities; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.Classes; import org.apache.sis.util.Utilities; @@ -46,6 +45,7 @@ import org.apache.sis.util.Debug; import org.apache.sis.util.privy.Constants; import org.apache.sis.referencing.factory.GeodeticObjectFactory; import org.apache.sis.referencing.factory.InvalidGeodeticParameterException; +import org.apache.sis.referencing.internal.ParameterizedTransformBuilder; import org.apache.sis.referencing.operation.transform.AbstractMathTransform; import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory; import org.apache.sis.util.collection.WeakHashSet; @@ -494,8 +494,11 @@ next: for (int i=components.size(); --i >= 0;) { if (parameters == null) { throw new NullPointerException(Errors.format(Errors.Keys.NullArgument_1, "transform")); } - transform = ReferencingUtilities.builder( - getMathTransformFactory(), parameters, sourceCRS, targetCRS).create(); + final var builder = new ParameterizedTransformBuilder(getMathTransformFactory(), null); + builder.setParameters(parameters, false); + builder.setSourceAxes(sourceCRS); + builder.setTargetAxes(targetCRS); + transform = builder.create(); } /* * The "operationType" property is currently undocumented. The intent is to help this factory method in 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 47efd04345..c44cc8c2b6 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 @@ -50,14 +50,12 @@ import org.apache.sis.util.iso.AbstractFactory; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.collection.WeakHashSet; import org.apache.sis.referencing.privy.CoordinateOperations; -import org.apache.sis.referencing.privy.ReferencingUtilities; import org.apache.sis.referencing.operation.DefaultOperationMethod; import org.apache.sis.referencing.operation.provider.AbstractProvider; import org.apache.sis.referencing.operation.matrix.Matrices; import org.apache.sis.referencing.internal.ParameterizedTransformBuilder; import org.apache.sis.referencing.factory.InvalidGeodeticParameterException; import org.apache.sis.parameter.DefaultParameterValueGroup; -import org.apache.sis.parameter.Parameters; import org.apache.sis.system.Reflect; // Specific to the geoapi-3.1 and geoapi-4.0 branches: @@ -712,9 +710,8 @@ public class DefaultMathTransformFactory extends AbstractFactory implements Math } builder = new ContextBuilder(factory, null); if (parameters != null) { - builder.setParameters(parameters); + builder.setParameters(parameters, false); } - Parameters.copy(parameters, builder.parameters()); } return builder; } @@ -1011,7 +1008,9 @@ public class DefaultMathTransformFactory extends AbstractFactory implements Math ArgumentChecks.ensureNonNull("baseCRS", baseCRS); ArgumentChecks.ensureNonNull("parameters", parameters); ArgumentChecks.ensureNonNull("derivedCS", derivedCS); - var builder = ReferencingUtilities.builder(this, parameters, baseCRS, null); + final var builder = new ContextBuilder(this, null); + builder.setParameters(parameters, true); + builder.setSourceAxes(baseCRS); builder.setTargetAxes(derivedCS, null); return builder.create(); } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java index d7dc4b2150..af6ba953a8 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java @@ -24,10 +24,8 @@ import org.opengis.annotation.UML; import org.opengis.annotation.Specification; import org.opengis.metadata.Identifier; import org.opengis.metadata.citation.Citation; -import org.opengis.parameter.ParameterValueGroup; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.parameter.GeneralParameterDescriptor; -import org.opengis.util.FactoryException; import org.opengis.referencing.IdentifiedObject; import org.opengis.referencing.cs.*; import org.opengis.referencing.crs.*; @@ -36,7 +34,6 @@ import org.opengis.referencing.datum.Ellipsoid; import org.opengis.referencing.datum.PrimeMeridian; import org.opengis.referencing.datum.GeodeticDatum; import org.opengis.referencing.datum.VerticalDatum; -import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.MathTransformFactory; import org.apache.sis.util.Static; import org.apache.sis.util.Classes; @@ -54,8 +51,6 @@ import org.apache.sis.referencing.cs.AxesConvention; import org.apache.sis.referencing.cs.DefaultEllipsoidalCS; import org.apache.sis.referencing.internal.VerticalDatumTypes; import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory; -import org.apache.sis.referencing.factory.InvalidGeodeticParameterException; -import org.apache.sis.parameter.Parameters; /** @@ -511,38 +506,6 @@ public final class ReferencingUtilities extends Static { return factory; } - /** - * Creates a builder with source and target ellipsoids and coordinate systems inferred from the given CRSs. - * The ellipsoids will be non-null only if the given CRS is geodetic (geographic or geocentric). - * - * @param factory the factory on which to create the builder. - * @param parameters the operation parameter value group. - * @param sourceCRS the CRS from which to get the source coordinate system and ellipsoid, or {@code null}. - * @param targetCRS the CRS from which to get the target coordinate system and ellipsoid, or {@code null}. - * @return the context to provides to math transform factory. - * @throws FactoryException if the builder cannot be created. - */ - public static MathTransform.Builder builder( - final MathTransformFactory factory, - final ParameterValueGroup parameters, - final CoordinateReferenceSystem sourceCRS, - final CoordinateReferenceSystem targetCRS) throws FactoryException - { - final var builder = factory.builder(parameters.getDescriptor().getName().getCode()); - try { - Parameters.copy(parameters, builder.parameters()); - } catch (IllegalArgumentException e) { - throw new InvalidGeodeticParameterException(e.getMessage(), e); - } - if (sourceCRS != null) { - builder.setSourceAxes(sourceCRS.getCoordinateSystem(), getEllipsoid(sourceCRS)); - } - if (targetCRS != null) { - builder.setTargetAxes(targetCRS.getCoordinateSystem(), getEllipsoid(targetCRS)); - } - return builder; - } - /** * Returns the mapping between parameter identifiers and parameter names as defined by the given authority. * This method assumes that the identifiers of all parameters defined by that authority are numeric.