You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2019/06/21 15:48:16 UTC

[sis] 03/10: First round of simplication allowed by SIS-463: delete ReferencingServices methods which were used for GeodeticObjectParser implementation. Instead, GeodeticObjectParser can now access directly the sis-referencing classes that it needs.

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 7c21a98bdc468791895411fa277feb387acdd3a5
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Fri Jun 21 12:10:28 2019 +0200

    First round of simplication allowed by SIS-463: delete ReferencingServices methods which were used for GeodeticObjectParser implementation. Instead, GeodeticObjectParser can now access directly the sis-referencing classes that it needs.
---
 .../sis/internal/metadata/ReferencingServices.java | 161 --------------
 .../internal/referencing/ServicesForMetadata.java  | 233 +--------------------
 .../sis/internal/referencing/WKTUtilities.java     |  37 ++++
 .../main/java/org/apache/sis/io/wkt/Formatter.java |   8 +-
 .../apache/sis/io/wkt/GeodeticObjectParser.java    |  49 +++--
 5 files changed, 78 insertions(+), 410 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
index 2653d77..ef7a0ed 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
@@ -21,29 +21,17 @@ import java.util.Collections;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.text.Format;
-import javax.measure.Unit;
-import javax.measure.quantity.Length;
 import org.opengis.geometry.Envelope;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.CRSFactory;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.crs.SingleCRS;
-import org.opengis.referencing.crs.DerivedCRS;
-import org.opengis.referencing.crs.VerticalCRS;
-import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CSFactory;
-import org.opengis.referencing.cs.CartesianCS;
-import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.datum.DatumFactory;
-import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.CoordinateOperationFactory;
 import org.opengis.referencing.operation.OperationMethod;
-import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.util.FactoryException;
 import org.apache.sis.metadata.iso.extent.DefaultExtent;
@@ -331,101 +319,6 @@ public class ReferencingServices extends OptionalDependency {
         throw moduleNotFound();
     }
 
-
-
-
-    ///////////////////////////////////////////////////////////////////////////////////////
-    ////                                                                               ////
-    ////                           SERVICES FOR WKT PARSING                            ////
-    ////                                                                               ////
-    ///////////////////////////////////////////////////////////////////////////////////////
-
-    /**
-     * Returns a coordinate reference system for heights above the mean seal level.
-     *
-     * @return the "Mean Seal Level (MSL) height" coordinate reference system, or {@code null}.
-     *
-     * @since 0.6
-     */
-    public VerticalCRS getMSLH() {
-        throw moduleNotFound();
-    }
-
-    /**
-     * Returns the Greenwich prime meridian.
-     *
-     * @return the Greenwich prime meridian.
-     *
-     * @since 0.6
-     */
-    public PrimeMeridian getGreenwich() {
-        throw moduleNotFound();
-    }
-
-    /**
-     * Returns the coordinate system of a geocentric CRS using axes in the given unit of measurement.
-     *
-     * @param  unit  the unit of measurement for the geocentric CRS axes.
-     * @return the coordinate system for a geocentric CRS with axes using the given unit of measurement.
-     *
-     * @since 0.6
-     */
-    public CartesianCS getGeocentricCS(final Unit<Length> unit) {
-        throw moduleNotFound();
-    }
-
-    /**
-     * Converts a geocentric coordinate system from the legacy WKT 1 to the current ISO 19111 standard.
-     * This method replaces the (Other, East, North) directions by (Geocentric X, Geocentric Y, Geocentric Z).
-     *
-     * @param  cs  the geocentric coordinate system to upgrade.
-     * @return the upgraded coordinate system, or {@code cs} if this method can not upgrade the given CS.
-     *
-     * @since 0.6
-     */
-    public CartesianCS upgradeGeocentricCS(final CartesianCS cs) {
-        return cs;
-    }
-
-    /**
-     * Creates a coordinate system of unknown type. This method is used during parsing of WKT version 1,
-     * since that legacy format did not specified any information about the coordinate system in use.
-     * This method should not need to be invoked for parsing WKT version 2.
-     *
-     * @param  properties  the coordinate system name, and optionally other properties.
-     * @param  axes        the axes of the unknown coordinate system.
-     * @return an "abstract" coordinate system using the given axes.
-     *
-     * @since 0.6
-     */
-    public CoordinateSystem createAbstractCS(final Map<String,?> properties, final CoordinateSystemAxis[] axes) {
-        throw moduleNotFound();
-    }
-
-    /**
-     * Creates a derived CRS from the information found in a WKT 1 {@code FITTED_CS} element.
-     * This coordinate system can not be easily constructed from the information provided by the WKT 1 format.
-     * Note that this method is needed only for WKT 1 parsing, since WKT provides enough information for using
-     * the standard factories.
-     *
-     * @param  properties     the properties to be given to the {@code DerivedCRS} and {@code Conversion} objects.
-     * @param  baseCRS        coordinate reference system to base the derived CRS on.
-     * @param  method         the coordinate operation method (mandatory in all cases).
-     * @param  baseToDerived  transform from positions in the base CRS to positions in this target CRS.
-     * @param  derivedCS      the coordinate system for the derived CRS.
-     * @return the newly created derived CRS, potentially implementing an additional CRS interface.
-     *
-     * @since 0.6
-     */
-    public DerivedCRS createDerivedCRS(final Map<String,?>    properties,
-                                       final SingleCRS        baseCRS,
-                                       final OperationMethod  method,
-                                       final MathTransform    baseToDerived,
-                                       final CoordinateSystem derivedCS)
-    {
-        throw moduleNotFound();
-    }
-
     /**
      * Creates a format for {@link DirectPosition} instances.
      *
@@ -440,60 +333,6 @@ public class ReferencingServices extends OptionalDependency {
     }
 
     /**
-     * Returns an axis direction from a pole along a meridian.
-     * The given meridian is usually, but not necessarily, relative to the Greenwich meridian.
-     *
-     * @param  baseDirection  the base direction, which must be {@link AxisDirection#NORTH} or {@link AxisDirection#SOUTH}.
-     * @param  meridian       the meridian in degrees, relative to a unspecified (usually Greenwich) prime meridian.
-     *                        Meridians in the East hemisphere are positive and meridians in the West hemisphere are negative.
-     * @return the axis direction along the given meridian.
-     *
-     * @since 0.6
-     */
-    public AxisDirection directionAlongMeridian(final AxisDirection baseDirection, final double meridian) {
-        throw moduleNotFound();
-    }
-
-    /**
-     * Creates the {@code TOWGS84} element during parsing of a WKT version 1. This is an optional operation:
-     * this method is allowed to return {@code null} if the "sis-referencing" module is not in the classpath.
-     *
-     * @param  values  the 7 Bursa-Wolf parameter values.
-     * @return the {@link org.apache.sis.referencing.datum.BursaWolfParameters}, or {@code null}.
-     *
-     * @since 0.6
-     */
-    public Object createToWGS84(final double[] values) {
-        return null;
-    }
-
-    /**
-     * Creates a single operation from the given properties.
-     * This method is provided here because not yet available in GeoAPI interfaces.
-     *
-     * @param  properties        the properties to be given to the identified object.
-     * @param  sourceCRS         the source CRS.
-     * @param  targetCRS         the target CRS.
-     * @param  interpolationCRS  the CRS of additional coordinates needed for the operation, or {@code null} if none.
-     * @param  method            the coordinate operation method (mandatory in all cases).
-     * @param  factory           the factory to use.
-     * @return the coordinate operation created from the given arguments.
-     * @throws FactoryException if the object creation failed.
-     *
-     * @since 0.6
-     */
-    public SingleOperation createSingleOperation(
-            final Map<String,?>              properties,
-            final CoordinateReferenceSystem  sourceCRS,
-            final CoordinateReferenceSystem  targetCRS,
-            final CoordinateReferenceSystem  interpolationCRS,
-            final OperationMethod            method,
-            final CoordinateOperationFactory factory) throws FactoryException
-    {
-        throw moduleNotFound();
-    }
-
-    /**
      * Returns the coordinate operation factory to use for the given properties and math transform factory.
      * If the given properties are empty and the {@code mtFactory} is the system default, then this method
      * returns the system default {@code CoordinateOperationFactory} instead of creating a new one.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
index d44c5f1..8b6ea4c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
@@ -24,33 +24,21 @@ import java.util.Collections;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.text.Format;
-import javax.measure.Unit;
-import javax.measure.quantity.Length;
 
 import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
 import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.SingleCRS;
-import org.opengis.referencing.crs.DerivedCRS;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.CRSFactory;
 import org.opengis.referencing.cs.CSFactory;
-import org.opengis.referencing.cs.AxisDirection;
-import org.opengis.referencing.cs.CartesianCS;
 import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
-import org.opengis.referencing.datum.PrimeMeridian;
-import org.opengis.referencing.operation.Matrix;
-import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
-import org.opengis.referencing.operation.OperationMethod;
-import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.referencing.operation.CoordinateOperationFactory;
 import org.opengis.metadata.Identifier;
@@ -71,18 +59,9 @@ import org.apache.sis.referencing.CRS;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
-import org.apache.sis.referencing.cs.AbstractCS;
-import org.apache.sis.referencing.cs.CoordinateSystems;
-import org.apache.sis.referencing.crs.DefaultDerivedCRS;
 import org.apache.sis.referencing.crs.DefaultTemporalCRS;
-import org.apache.sis.referencing.datum.BursaWolfParameters;
-import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
 import org.apache.sis.parameter.DefaultParameterDescriptor;
-import org.apache.sis.parameter.Parameterized;
-import org.apache.sis.io.wkt.Formatter;
-import org.apache.sis.io.wkt.FormattableObject;
-import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.metadata.iso.extent.DefaultExtent;
 import org.apache.sis.metadata.iso.extent.DefaultVerticalExtent;
 import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
@@ -92,7 +71,6 @@ import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.internal.metadata.AxisDirections;
 import org.apache.sis.internal.metadata.ReferencingServices;
-import org.apache.sis.internal.referencing.provider.Affine;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.util.Constants;
@@ -510,7 +488,7 @@ public final class ServicesForMetadata extends ReferencingServices {
 
     ///////////////////////////////////////////////////////////////////////////////////////
     ////                                                                               ////
-    ////                          SERVICES FOR WKT FORMATTING                          ////
+    ////                    SERVICES FOR WKT PARSING AND FORMATTING                    ////
     ////                                                                               ////
     ///////////////////////////////////////////////////////////////////////////////////////
 
@@ -526,151 +504,6 @@ public final class ServicesForMetadata extends ReferencingServices {
     }
 
     /**
-     * Converts the given object in a {@code FormattableObject} instance.
-     *
-     * @param  object  the object to wrap.
-     * @return the given object converted to a {@code FormattableObject} instance.
-     */
-    public static FormattableObject toFormattableObject(final IdentifiedObject object) {
-        return AbstractIdentifiedObject.castOrCopy(object);
-    }
-
-    /**
-     * Converts the given object in a {@code FormattableObject} instance. Callers should verify that the given
-     * object is not already an instance of {@code FormattableObject} before to invoke this method. This method
-     * returns {@code null} if it can not convert the object.
-     *
-     * @param  object    the object to wrap.
-     * @param  internal  {@code true} if the formatting convention is {@code Convention.INTERNAL}.
-     * @return the given object converted to a {@code FormattableObject} instance, or {@code null}.
-     *
-     * @since 0.6
-     */
-    public static FormattableObject toFormattableObject(final MathTransform object, boolean internal) {
-        Matrix matrix;
-        final ParameterValueGroup parameters;
-        if (internal && (matrix = MathTransforms.getMatrix(object)) != null) {
-            parameters = Affine.parameters(matrix);
-        } else if (object instanceof Parameterized) {
-            parameters = ((Parameterized) object).getParameterValues();
-        } else {
-            matrix = MathTransforms.getMatrix(object);
-            if (matrix == null) {
-                return null;
-            }
-            parameters = Affine.parameters(matrix);
-        }
-        return new FormattableObject() {
-            @Override
-            protected String formatTo(final Formatter formatter) {
-                WKTUtilities.appendParamMT(parameters, formatter);
-                return WKTKeywords.Param_MT;
-            }
-        };
-    }
-
-
-
-
-    ///////////////////////////////////////////////////////////////////////////////////////
-    ////                                                                               ////
-    ////                           SERVICES FOR WKT PARSING                            ////
-    ////                                                                               ////
-    ///////////////////////////////////////////////////////////////////////////////////////
-
-    /**
-     * Returns a coordinate reference system for heights above the mean seal level.
-     *
-     * @return the "Mean Seal Level (MSL) height" coordinate reference system.
-     *
-     * @since 0.6
-     */
-    @Override
-    public VerticalCRS getMSLH() {
-        return CommonCRS.Vertical.MEAN_SEA_LEVEL.crs();
-    }
-
-    /**
-     * Returns the Greenwich prime meridian.
-     *
-     * @return the Greenwich prime meridian.
-     *
-     * @since 0.6
-     */
-    @Override
-    public PrimeMeridian getGreenwich() {
-        return CommonCRS.WGS84.primeMeridian();
-    }
-
-    /**
-     * Returns the coordinate system of a geocentric CRS using axes in the given unit of measurement.
-     *
-     * @param  linearUnit  the unit of measurement for the geocentric CRS axes.
-     * @return the coordinate system for a geocentric CRS with axes using the given unit of measurement.
-     *
-     * @since 0.6
-     */
-    @Override
-    public CartesianCS getGeocentricCS(final Unit<Length> linearUnit) {
-        return Legacy.standard(linearUnit);
-    }
-
-    /**
-     * Converts a geocentric coordinate system from the legacy WKT 1 to the current ISO 19111 standard.
-     * This method replaces the (Other, East, North) directions by (Geocentric X, Geocentric Y, Geocentric Z).
-     *
-     * @param  cs  the geocentric coordinate system to upgrade.
-     * @return the upgraded coordinate system, or {@code cs} if there is no change to apply.
-     *
-     * @since 0.6
-     */
-    @Override
-    public CartesianCS upgradeGeocentricCS(final CartesianCS cs) {
-        return Legacy.forGeocentricCRS(cs, false);
-    }
-
-    /**
-     * Creates a coordinate system of unknown type. This method is used during parsing of WKT version 1,
-     * since that legacy format did not specified any information about the coordinate system in use.
-     * This method should not need to be invoked for parsing WKT version 2.
-     *
-     * @param  properties  the coordinate system name, and optionally other properties.
-     * @param  axes        the axes of the unknown coordinate system.
-     * @return an "abstract" coordinate system using the given axes.
-     *
-     * @since 0.6
-     */
-    @Override
-    public CoordinateSystem createAbstractCS(final Map<String,?> properties, final CoordinateSystemAxis[] axes) {
-        return new AbstractCS(properties, axes);
-    }
-
-    /**
-     * Creates a derived CRS from the information found in a WKT 1 {@code FITTED_CS} element.
-     * This coordinate system can not be easily constructed from the information provided by the WKT 1 format.
-     * Note that this method is needed only for WKT 1 parsing, since WKT provides enough information for using
-     * the standard factories.
-     *
-     * @param  properties     the properties to be given to the {@code DerivedCRS} and {@code Conversion} objects.
-     * @param  baseCRS        coordinate reference system to base the derived CRS on.
-     * @param  method         the coordinate operation method (mandatory in all cases).
-     * @param  baseToDerived  transform from positions in the base CRS to positions in this target CRS.
-     * @param  derivedCS      the coordinate system for the derived CRS.
-     * @return the newly created derived CRS, potentially implementing an additional CRS interface.
-     *
-     * @since 0.6
-     */
-    @Override
-    public DerivedCRS createDerivedCRS(final Map<String,?>    properties,
-                                       final SingleCRS        baseCRS,
-                                       final OperationMethod  method,
-                                       final MathTransform    baseToDerived,
-                                       final CoordinateSystem derivedCS)
-    {
-        return DefaultDerivedCRS.create(properties, baseCRS, null, method, baseToDerived, derivedCS);
-    }
-
-    /**
      * Creates a format for {@link DirectPosition} instances.
      *
      * @param  locale    the locale for the new {@code Format}, or {@code null} for {@code Locale.ROOT}.
@@ -685,70 +518,6 @@ public final class ServicesForMetadata extends ReferencingServices {
     }
 
     /**
-     * Returns an axis direction from a pole along a meridian.
-     * The given meridian is usually, but not necessarily, relative to the Greenwich meridian.
-     *
-     * @param  baseDirection  the base direction, which must be {@link AxisDirection#NORTH} or {@link AxisDirection#SOUTH}.
-     * @param  meridian       the meridian in degrees, relative to a unspecified (usually Greenwich) prime meridian.
-     *         Meridians in the East hemisphere are positive and meridians in the West hemisphere are negative.
-     * @return the axis direction along the given meridian.
-     *
-     * @since 0.6
-     */
-    @Override
-    public AxisDirection directionAlongMeridian(final AxisDirection baseDirection, final double meridian) {
-        return CoordinateSystems.directionAlongMeridian(baseDirection, meridian);
-    }
-
-    /**
-     * Creates the {@code TOWGS84} element during parsing of a WKT version 1.
-     *
-     * @param  values  the 7 Bursa-Wolf parameter values.
-     * @return the {@link BursaWolfParameters}.
-     *
-     * @since 0.6
-     */
-    @Override
-    public Object createToWGS84(final double[] values) {
-        final BursaWolfParameters info = new BursaWolfParameters(CommonCRS.WGS84.datum(), null);
-        info.setValues(values);
-        return info;
-    }
-
-    /**
-     * Creates a single operation from the given properties.
-     * This method is provided here because not yet available in GeoAPI interfaces.
-     *
-     * @param  properties        the properties to be given to the identified object.
-     * @param  sourceCRS         the source CRS.
-     * @param  targetCRS         the target CRS.
-     * @param  interpolationCRS  the CRS of additional coordinates needed for the operation, or {@code null} if none.
-     * @param  method            the coordinate operation method (mandatory in all cases).
-     * @param  factory           the factory to use.
-     * @return the coordinate operation created from the given arguments.
-     * @throws FactoryException if the object creation failed.
-     *
-     * @since 0.6
-     */
-    @Override
-    public SingleOperation createSingleOperation(
-            final Map<String,?>              properties,
-            final CoordinateReferenceSystem  sourceCRS,
-            final CoordinateReferenceSystem  targetCRS,
-            final CoordinateReferenceSystem  interpolationCRS,
-            final OperationMethod            method,
-            final CoordinateOperationFactory factory) throws FactoryException
-    {
-        final DefaultCoordinateOperationFactory df;
-        if (factory instanceof DefaultCoordinateOperationFactory) {
-            df = (DefaultCoordinateOperationFactory) factory;
-        } else {
-            df = CoordinateOperations.factory();
-        }
-        return df.createSingleOperation(properties, sourceCRS, targetCRS, interpolationCRS, method, null);
-    }
-
-    /**
      * Returns the coordinate operation factory to use for the given properties and math transform factory.
      * If the given properties are empty and the {@code mtFactory} is the system default, then this method
      * returns the system default {@code CoordinateOperationFactory} instead of creating a new one.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
index 5b41ec8..2ff80be 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
@@ -34,6 +34,8 @@ import org.opengis.referencing.datum.Datum;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.referencing.operation.MathTransform;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.crs.AbstractCRS;
 import org.apache.sis.referencing.cs.AbstractCS;
@@ -42,7 +44,11 @@ import org.apache.sis.referencing.datum.AbstractDatum;
 import org.apache.sis.referencing.datum.DefaultGeodeticDatum;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
 import org.apache.sis.referencing.datum.DefaultEllipsoid;
+import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.internal.referencing.provider.Affine;
 import org.apache.sis.parameter.DefaultParameterValue;
+import org.apache.sis.parameter.Parameterized;
+import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.io.wkt.ElementKind;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.io.wkt.Formatter;
@@ -208,6 +214,37 @@ public final class WKTUtilities extends Static {
     }
 
     /**
+     * Converts the given object in a {@code FormattableObject} instance. Callers should verify that the
+     * given object is not already an instance of {@code FormattableObject} before to invoke this method.
+     * This method returns {@code null} if it can not convert the object.
+     *
+     * @param  object    the object to wrap.
+     * @param  internal  {@code true} if the formatting convention is {@code Convention.INTERNAL}.
+     * @return the given object converted to a {@code FormattableObject} instance, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final MathTransform object, boolean internal) {
+        Matrix matrix;
+        final ParameterValueGroup parameters;
+        if (internal && (matrix = MathTransforms.getMatrix(object)) != null) {
+            parameters = Affine.parameters(matrix);
+        } else if (object instanceof Parameterized) {
+            parameters = ((Parameterized) object).getParameterValues();
+        } else {
+            matrix = MathTransforms.getMatrix(object);
+            if (matrix == null) {
+                return null;
+            }
+            parameters = Affine.parameters(matrix);
+        }
+        return new FormattableObject() {
+            @Override protected String formatTo(final Formatter formatter) {
+                WKTUtilities.appendParamMT(parameters, formatter);
+                return WKTKeywords.Param_MT;
+            }
+        };
+    }
+
+    /**
      * If the given unit is one of the unit that can not be formatted without ambiguity in WKT format,
      * return a proposed replacement. Otherwise returns {@code unit} unchanged.
      *
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
index b924553..f93d23e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
@@ -75,8 +75,9 @@ import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.internal.simple.SimpleExtent;
 import org.apache.sis.internal.metadata.WKTKeywords;
-import org.apache.sis.internal.referencing.ServicesForMetadata;
 import org.apache.sis.internal.metadata.Resources;
+import org.apache.sis.internal.referencing.WKTUtilities;
+import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.measure.UnitFormat;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.MeasurementRange;
@@ -984,8 +985,7 @@ public class Formatter implements Localized {
             if (transform instanceof FormattableObject) {
                 append((FormattableObject) transform);
             } else {
-                final FormattableObject object = ServicesForMetadata
-                        .toFormattableObject(transform, convention == Convention.INTERNAL);
+                final FormattableObject object = WKTUtilities.toFormattable(transform, convention == Convention.INTERNAL);
                 if (object != null) {
                     append(object);
                 } else {
@@ -1549,7 +1549,7 @@ public class Formatter implements Localized {
         if (value instanceof FormattableObject) {
             append((FormattableObject) value);
         } else if (value instanceof IdentifiedObject) {
-            append(ServicesForMetadata.toFormattableObject((IdentifiedObject) value));
+            append(AbstractIdentifiedObject.castOrCopy((IdentifiedObject) value));
         } else if (value instanceof MathTransform) {
             append((MathTransform) value);
         } else if (value instanceof Unit<?>) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
index ebf45df..eb20f81 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
@@ -57,6 +57,14 @@ import org.opengis.referencing.operation.*;
 
 import org.apache.sis.measure.Units;
 import org.apache.sis.measure.UnitFormat;
+import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.referencing.cs.AbstractCS;
+import org.apache.sis.referencing.cs.CoordinateSystems;
+import org.apache.sis.referencing.crs.DefaultDerivedCRS;
+import org.apache.sis.referencing.datum.BursaWolfParameters;
+import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
+import org.apache.sis.internal.referencing.CoordinateOperations;
+import org.apache.sis.internal.referencing.Legacy;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.extent.DefaultExtent;
@@ -293,7 +301,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             if (verticalElements != null) {
                 Exception ex = null;
                 try {
-                    verticalElements = verticalElements.resolve(referencing.getMSLH());     // Optional operation.
+                    verticalElements = verticalElements.resolve(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs());     // Optional operation.
                 } catch (UnsupportedOperationException e) {
                     ex = e;
                 }
@@ -811,7 +819,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
                         throw parent.missingComponent(WKTKeywords.LengthUnit);
                     }
                     if (is3D) {  // If dimension can not be 2, then CRS can not be Projected.
-                        return referencing.getGeocentricCS(defaultUnit.asType(Length.class));
+                        return Legacy.standard(defaultUnit.asType(Length.class));
                     }
                     nx = AxisNames.EASTING;  x = "E";
                     ny = AxisNames.NORTHING; y = "N";
@@ -934,7 +942,12 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             csProperties.put(CoordinateSystem.NAME_KEY, name);
         }
         if (type == null) {
-            return referencing.createAbstractCS(csProperties, axes);
+            /*
+             * Creates a coordinate system of unknown type. This block is executed during parsing of WKT version 1,
+             * since that legacy format did not specified any information about the coordinate system in use.
+             * This block should not be executed during parsing of WKT version 2.
+             */
+            return new AbstractCS(csProperties, axes);
         }
         /*
          * Finally, delegate to the factory method corresponding to the CS type and the number of axes.
@@ -994,7 +1007,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             }
             default: {
                 warning(parent, WKTKeywords.CS, Errors.formatInternational(Errors.Keys.UnknownType_1, type), null);
-                return referencing.createAbstractCS(csProperties, axes);
+                return new AbstractCS(csProperties, axes);
             }
         }
         throw new UnparsableObjectException(errorLocale, (axes.length > dimension)
@@ -1056,7 +1069,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             if (m != null) {
                 angle = m.getConverterTo(Units.DEGREE).convert(angle);
             }
-            direction = referencing.directionAlongMeridian(direction, angle);
+            direction = CoordinateSystems.directionAlongMeridian(direction, angle);
         }
         /*
          * According ISO 19162, the abbreviation should be inserted between parenthesis in the name.
@@ -1214,7 +1227,9 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             }
         }
         element.close(ignoredElements);
-        return referencing.createToWGS84(values);
+        final BursaWolfParameters info = new BursaWolfParameters(CommonCRS.WGS84.datum(), null);
+        info.setValues(values);
+        return info;
     }
 
     /**
@@ -1410,7 +1425,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
         final Object             toWGS84    = parseToWGS84(OPTIONAL, element);
         final Map<String,Object> properties = parseAnchorAndClose(element, name);
         if (meridian == null) {
-            meridian = referencing.getGreenwich();
+            meridian = CommonCRS.WGS84.primeMeridian();
         }
         if (toWGS84 != null) {
             properties.put(ReferencingServices.BURSA_WOLF_KEY, toWGS84);
@@ -1848,7 +1863,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             }
             if (cs instanceof CartesianCS) {                                    // The second most frequent case.
                 return crsFactory.createGeocentricCRS(properties, datum,
-                        referencing.upgradeGeocentricCS((CartesianCS) cs));
+                        Legacy.forGeocentricCRS((CartesianCS) cs, false));
             }
             if (cs instanceof SphericalCS) {                                    // Not very common case.
                 return crsFactory.createGeocentricCRS(properties, datum, (SphericalCS) cs);
@@ -2235,14 +2250,16 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
                         number, AxisDirection.OTHER, Units.UNITY);
             }
             final Map<String,Object> properties = parseMetadataAndClose(element, name, baseCRS);
-            final CoordinateSystem derivedCS = referencing.createAbstractCS(
+            final CoordinateSystem derivedCS = new AbstractCS(
                     singletonMap(CoordinateSystem.NAME_KEY, AxisDirections.appendTo(new StringBuilder("CS"), axes)), axes);
             /*
-             * We do not know which name to give to the conversion method.
-             * For now, use the CRS name.
+             * Creates a derived CRS from the information found in a WKT 1 {@code FITTED_CS} element.
+             * This coordinate system can not be easily constructed from the information provided by
+             * the WKT 1 format, which block us from using the standard Coordinate System factory.
+             * Note that we do not know which name to give to the conversion method; for now we use the CRS name.
              */
             properties.put("conversion.name", name);
-            return referencing.createDerivedCRS(properties, (SingleCRS) baseCRS, method, toBase.inverse(), derivedCS);
+            return DefaultDerivedCRS.create(properties, (SingleCRS) baseCRS, null, method, toBase.inverse(), derivedCS);
         } catch (FactoryException | NoninvertibleTransformException exception) {
             throw element.parseFailed(exception);
         }
@@ -2278,7 +2295,13 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
             accuracy.close(ignoredElements);
         }
         try {
-            return referencing.createSingleOperation(properties, sourceCRS, targetCRS, interpolationCRS, method, opFactory);
+            final DefaultCoordinateOperationFactory df;
+            if (opFactory instanceof DefaultCoordinateOperationFactory) {
+                df = (DefaultCoordinateOperationFactory) opFactory;
+            } else {
+                df = CoordinateOperations.factory();
+            }
+            return df.createSingleOperation(properties, sourceCRS, targetCRS, interpolationCRS, method, null);
         } catch (FactoryException e) {
             throw element.parseFailed(e);
         }