Package org.apache.sis.referencing.operation

# Class DefaultConversion

Object
FormattableObject
AbstractIdentifiedObject
AbstractCoordinateOperation
DefaultConversion

All Implemented Interfaces:
  `Serializable`, `Formattable`, `Parameterized`, `Deprecable`, `LenientComparable`, `IdentifiedObject`, `Conversion`, `CoordinateOperation`, `SingleOperation`

public class DefaultConversion extends AbstractCoordinateOperation implements Conversion
A parameterized mathematical operation that converts coordinates to another CRS without any change of datum. The best-known example of a coordinate conversion is a map projection. The parameters describing coordinate conversions are defined rather than empirically derived.

This coordinate operation contains an operation method, usually with associated parameter values. In the SIS implementation, the parameter values can be either inferred from the math transform or explicitly provided at construction time in a defining conversion (see below).

## Defining conversions

`OperationMethod` instances are generally created for a pair of existing source and target CRS. But `Conversion` instances without those information may exist temporarily while creating a derived or projected CRS. Those defining conversions have no source and target CRS since those elements are provided by the derived or projected CRS themselves. This class provides a constructor for such defining conversions.

After the source and target CRS become known, we can invoke the `specialize(…)` method for creating a math transform from the parameters, instantiate a new `Conversion` of a more specific type (`ConicProjection`, `CylindricalProjection` or `PlanarProjection`) if possible, and assign the source and target CRS to it.

## Immutability and thread safety

This class is immutable and thus thread-safe if the property values (not necessarily the map itself) given to the constructor are also immutable. This means that unless otherwise noted in the javadoc, `Conversion` instances created using only SIS factories and static constants can be shared by many objects and passed between threads without synchronization.

Since:
  0.6
See Also:
  - `DefaultTransformation`
  - Serialized Form

Defined in the `sis-referencing` module

- ## Field Summary

  ### Fields inherited from class AbstractIdentifiedObject

  `DEPRECATED_KEY, LOCALE_KEY`

  ### Fields inherited from interface CoordinateOperation

  `COORDINATE_OPERATION_ACCURACY_KEY, DOMAIN_OF_VALIDITY_KEY, OPERATION_VERSION_KEY, SCOPE_KEY`

  ### Fields inherited from interface IdentifiedObject

  `ALIAS_KEY, IDENTIFIERS_KEY, NAME_KEY, REMARKS_KEY`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  ``
  `DefaultConversion(Map<String,?> properties, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, CoordinateReferenceSystem interpolationCRS, OperationMethod method, MathTransform transform)`
  Creates a coordinate conversion from the given properties.
  ``
  `DefaultConversion(Map<String,?> properties, OperationMethod method, MathTransform transform, ParameterValueGroup parameters)`
  Creates a defining conversion from the given transform and/or parameters.
  `protected`
  `DefaultConversion(Conversion operation)`
  Creates a new coordinate operation with the same values than the specified one.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static DefaultConversion`
  `castOrCopy(Conversion object)`
  Returns a SIS coordinate operation implementation with the values of the given arbitrary implementation.
  `boolean`
  `equals(Object object, ComparisonMode mode)`
  Compares this coordinate operation with the specified object for equality.
  `Class<? extends Conversion>`
  `getInterface()`
  Returns the GeoAPI interface implemented by this class.
  `OperationMethod`
  `getMethod()`
  Returns a description of the operation method, including a list of expected parameter names.
  `ParameterDescriptorGroup`
  `getParameterDescriptors()`
  Returns a description of the parameters.
  `ParameterValueGroup`
  `getParameterValues()`
  Returns the parameter values.
  `<T extends Conversion>
  T`
  `specialize(Class<T> baseType, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, MathTransformFactory factory)`
  Returns a specialization of this conversion with a more specific type, source and target CRS.

  ### Methods inherited from class AbstractCoordinateOperation

  `castOrCopy, computeHashCode, formatTo, getCoordinateOperationAccuracy, getDomainOfValidity, getInterpolationCRS, getLinearAccuracy, getMathTransform, getOperationVersion, getScope, getSourceCRS, getTargetCRS, getWrapAroundChanges, isDefiningConversion`

  ### Methods inherited from class AbstractIdentifiedObject

  `castOrCopy, equals, formatTo, getAlias, getDescription, getIdentifiers, getName, getRemarks, hashCode, isDeprecated, isHeuristicMatchForName`

  ### Methods inherited from class FormattableObject

  `print, toString, toString, toWKT`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Conversion

  `getOperationVersion, getSourceCRS, getTargetCRS`

  ### Methods inherited from interface CoordinateOperation

  `getCoordinateOperationAccuracy, getDomainOfValidity, getMathTransform, getScope`

  ### Methods inherited from interface IdentifiedObject

  `getAlias, getIdentifiers, getName, getRemarks, toWKT`

  ### Methods inherited from interface SingleOperation

  `getMethod, getParameterValues`

- ## Constructor Details

  - ### DefaultConversion

    public DefaultConversion(Map<String,?> properties, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, CoordinateReferenceSystem interpolationCRS, OperationMethod method, MathTransform transform)
    Creates a coordinate conversion from the given properties. The properties given in argument follow the same rules than for the super-class constructor. The following table is a reminder of main (not all) properties:

    Recognized properties (non exhaustive list)
    Property name | Value type | Returned by
    --- | --- | ---
    "name" | `Identifier` or `String` | `AbstractIdentifiedObject.getName()`
    "identifiers" | `Identifier` (optionally as array) | `AbstractIdentifiedObject.getIdentifiers()`
    "domainOfValidity" | `Extent` | `AbstractCoordinateOperation.getDomainOfValidity()`

    #### Relationship between datum

    By definition, coordinate conversions do not change the datum. Consequently the given `sourceCRS` and `targetCRS` should use the same datum. If the datum is not the same, then the coordinate operation should probably be a transformation instead. However Apache SIS does not enforce that condition, but we encourage users to follow it. The reason why SIS is tolerant is because some gray areas may exist about whether an operation should be considered as a conversion or a transformation.
    Example: converting time instants from a temporal CRS using the January 1st, 1950 epoch to another temporal CRS using the January 1st, 1970 epoch is a datum change, since the epoch is part of temporal datum definition. However such operation does not have all the accuracy issues of transformations between geodetic datum (empirically determined, over-determined systems, stochastic nature of the parameters). Consequently some users may consider sufficient to represent temporal epoch changes as conversions instead than transformations.
    Note that while Apache SIS accepts to construct `DefaultConversion` instances with different source and target datum, it does not accept to use such instances for derived CRS construction.
    Parameters:
      `properties` - the properties to be given to the identified object.
      `sourceCRS` - the source CRS.
      `targetCRS` - the target CRS, which shall use a datum equals (ignoring metadata) to the source CRS datum.
      `interpolationCRS` - the CRS of additional coordinates needed for the operation, or `null` if none.
      `method` - the coordinate operation method (mandatory in all cases).
      `transform` - transform from positions in the source CRS to positions in the target CRS.

  - ### DefaultConversion

    public DefaultConversion(Map<String,?> properties, OperationMethod method, MathTransform transform, ParameterValueGroup parameters)
    Creates a defining conversion from the given transform and/or parameters. This conversion has no source and target CRS since those elements are usually unknown at defining conversion construction time. The source and target CRS will become known later, at the Derived CRS or Projected CRS construction time.

    The `properties` map given in argument follows the same rules than for the above constructor.

    #### Transform and parameters arguments

    At least one of the `transform` or `parameters` argument must be non-null. If the caller supplies a `transform` argument, then it shall be a transform expecting normalized input coordinates and producing normalized output coordinates. See `AxesConvention` for more information about what Apache SIS means by "normalized".

    If the caller can not yet supply a `MathTransform`, then (s)he shall supply the parameter values needed for creating that transform, with the possible omission of `"semi_major"` and `"semi_minor"` values. The semi-major and semi-minor parameter values will be set automatically when the `specialize(…)` method will be invoked.

    If both the `transform` and `parameters` arguments are non-null, then the later should describe the parameters used for creating the transform. Those parameters will be stored for information purpose and can be given back by the `SingleOperation​.getParameterValues()` method.

    Parameters:
      `properties` - the properties to be given to the identified object.
      `method` - the operation method.
      `transform` - transform from positions in the source CRS to positions in the target CRS, or `null`.
      `parameters` - the `transform` parameter values, or `null`.
    See Also:
      - `DefaultMathTransformFactory​.swapAndScaleAxes(MathTransform, DefaultMathTransformFactory​.Context)`

  - ### DefaultConversion

    protected DefaultConversion(Conversion operation)
    Creates a new coordinate operation with the same values than the specified one. This copy constructor provides a way to convert an arbitrary implementation into a SIS one or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API.

    This constructor performs a shallow copy, i.e. the properties are not cloned.

    Parameters:
      `operation` - the coordinate operation to copy.
    See Also:
      - `castOrCopy(Conversion)`

- ## Method Details

  - ### castOrCopy

    public static DefaultConversion castOrCopy(Conversion object)
    Returns a SIS coordinate operation implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:
    - If the given object is `null`, then this method returns `null`.
    - Otherwise if the given object is an instance of `Conversion`, `Projection`, `CylindricalProjection`, `ConicProjection` or `PlanarProjection`, then this method delegates to the `castOrCopy(…)` method of the corresponding SIS subclass. Note that if the given object implements more than one of the above-cited interfaces, then the `castOrCopy(…)` method to be used is unspecified.
    - Otherwise if the given object is already an instance of `DefaultConversion`, then it is returned unchanged.
    - Otherwise a new `DefaultConversion` instance is created using the copy constructor and returned. Note that this is a shallow copy operation, since the other properties contained in the given object are not recursively copied.
    Parameters:
      `object` - the object to get as a SIS implementation, or `null` if none.
    Returns:
      a SIS implementation containing the values of the given object (may be the given object itself), or `null` if the argument was null.

  - ### getInterface

    public Class<? extends Conversion> getInterface()
    Returns the GeoAPI interface implemented by this class. The default implementation returns `Conversion​.class`. Subclasses implementing a more specific GeoAPI interface shall override this method.
    Overrides:
      `getInterface` in class `AbstractCoordinateOperation`
    Returns:
      the conversion interface implemented by this class.

  - ### specialize

    public <T extends Conversion> T specialize(Class<T> baseType, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, MathTransformFactory factory) throws FactoryException
    Returns a specialization of this conversion with a more specific type, source and target CRS. This `specialize(…)` method is typically invoked on defining conversion instances, when more information become available about the conversion to create.

    The given `baseType` argument can be one of the following values:

    - `Conversion.class`
    - `Projection.class`
    - `CylindricalProjection.class`
    - `ConicProjection.class`
    - `PlanarProjection.class`
    This `specialize(…)` method returns a conversion which implement at least the given `baseType` interface, but may also implement a more specific GeoAPI interface if `specialize(…)` has been able to infer the type from this operation method.
    Type Parameters:
      `T` - compile-time type of the `baseType` argument.
    Parameters:
      `baseType` - the base GeoAPI interface to be implemented by the conversion to return.
      `sourceCRS` - the source CRS.
      `targetCRS` - the target CRS.
      `factory` - the factory to use for creating a transform from the parameters or for performing axis changes.
    Returns:
      the conversion of the given type between the given CRS.
    Throws:
      `ClassCastException` - if a contradiction is found between the given `baseType`, the defining conversion type and the method operation type.
      `MismatchedDatumException` - if the given CRS do not use the same datum than the source and target CRS of this conversion.
      `FactoryException` - if the creation of a `MathTransform` from the parameter values, or a change of axis order or units failed.
    See Also:
      - `DefaultMathTransformFactory​.createParameterizedTransform(ParameterValueGroup, DefaultMathTransformFactory​.Context)`

  - ### getMethod

    public OperationMethod getMethod()
    Returns a description of the operation method, including a list of expected parameter names. The returned object does not contains any parameter value.
    Specified by:
      `getMethod` in interface `SingleOperation`
    Returns:
      a description of the operation method.

  - ### getParameterDescriptors

    public ParameterDescriptorGroup getParameterDescriptors()
    Returns a description of the parameters. The default implementation performs the following choice:
    - If parameter values were specified explicitly at construction time, then the descriptor of those parameters is returned.
    - Otherwise if this method can infer the parameter descriptor from the math transform, then that descriptor is returned.
    - Otherwise fallback on the method parameters.
    Note: the two parameter descriptions (from the `MathTransform` or from the `OperationMethod`) should be very similar. If they differ, it should be only in minor details like remarks, default values or units of measurement.
    Specified by:
      `getParameterDescriptors` in interface `Parameterized`
    Returns:
      a description of the parameters.
    See Also:
      - `DefaultOperationMethod​.getParameters()`
      - `AbstractMathTransform​.getParameterDescriptors()`

  - ### getParameterValues

    public ParameterValueGroup getParameterValues()
    Returns the parameter values. The default implementation performs the following choice:
    - If parameter values were specified explicitly at construction time, then they are returned as an unmodifiable parameter group.
    - Otherwise if this method can infer the parameter values from the math transform, then those parameters are returned.
    - Otherwise throw `UnsupportedImplementationException`.
    Specified by:
      `getParameterValues` in interface `Parameterized`
    Specified by:
      `getParameterValues` in interface `SingleOperation`
    Returns:
      the parameter values.
    Throws:
      `UnsupportedOperationException` - if the parameter values can not be determined for the current math transform implementation.
    See Also:
      - `AbstractMathTransform​.getParameterValues()`

  - ### equals

    public boolean equals(Object object, ComparisonMode mode)
    Compares this coordinate operation with the specified object for equality. If the `mode` argument is `ComparisonMode​.STRICT` or `BY_CONTRACT`, then all available properties are compared including the domain of validity and the scope.
    Specified by:
      `equals` in interface `LenientComparable`
    Overrides:
      `equals` in class `AbstractCoordinateOperation`
    Parameters:
      `object` - the object to compare to `this`.
      `mode` - `STRICT` for performing a strict comparison, or `IGNORE_METADATA` for ignoring properties that do not make a difference in the numerical results of coordinate operations.
    Returns:
      `true` if both objects are equal for the given comparison mode.
    See Also:
      - `AbstractIdentifiedObject​.computeHashCode()`
      - `Utilities​.deepEquals(Object, Object, ComparisonMode)`