Package org.apache.sis.referencing.crs

# Class DefaultCompoundCRS

Object
FormattableObject
AbstractIdentifiedObject
AbstractReferenceSystem
AbstractCRS
DefaultCompoundCRS

All Implemented Interfaces:
  `Serializable`, `Formattable`, `Deprecable`, `LenientComparable`, `CompoundCRS`, `CoordinateReferenceSystem`, `IdentifiedObject`, `ReferenceSystem`

public class DefaultCompoundCRS extends AbstractCRS implements CompoundCRS
A CRS describing the position of points through two or more independent coordinate reference systems. This class is often used for defining 4-dimensional (x,y,z,t) coordinate reference systems as an aggregation of simpler CRS. Below is two examples of such aggregations:

Flat list

> `CompoundCRS` — (x, y, z, t)
> `├─ProjectedCRS` — (x, y)
> `├─VerticalCRS` — (z)
> `└─TemporalCRS` — (t)

Hierarchical structure

> `CompoundCRS` — (x, y, z, t)
> `├─CompoundCRS` — (x, y, z)
> `│ ├─ProjectedCRS` — (x, y)
> `│ └─VerticalCRS` — (z)
> `└─TemporalCRS` — (t)

Strictly speaking, only the flat list on the left side is allowed by OGC/ISO specifications. However Apache SIS relaxes this rule by allowing hierarchies as shown on the right side. This flexibility allows SIS to preserve information about the (x,y,z) part (e.g. the EPSG identifier) that would otherwise been lost. Users can obtain the list of their choice by invoking `getSingleComponents()` or `getComponents()` respectively.

## Component order

ISO 19162 restricts compound CRS to the following components in that order:

- A mandatory horizontal CRS (only one of two-dimensional `GeographicCRS` or `ProjectedCRS` or `EngineeringCRS`).
- Optionally followed by a `VerticalCRS` or a `ParametricCRS` (but not both).
- Optionally followed by a `TemporalCRS`.

SIS currently does not enforce those restrictions. In particular:

- Components may appear in different order.
- `VerticalCRS` + `TemporalCRS` (without horizontal component) is accepted.
- `GeocentricCRS` or three-dimensional `GeographicCRS` can be combined with `TemporalCRS`.

However users are encouraged to follow ISO 19162 restriction for better portability.

## Immutability and thread safety

This class is immutable and thus thread-safe if the property values (not necessarily the map itself) and all `CoordinateReferenceSystem` instances given to the constructor are also immutable. Unless otherwise noted in the javadoc, this condition holds if all components were created using only SIS factories and static constants.

Since:
  0.4
See Also:
  - `GeodeticAuthorityFactory​.createCompoundCRS(String)`
  - Serialized Form

Defined in the `sis-referencing` module

- ## Field Summary

  ### Fields inherited from class AbstractIdentifiedObject

  `DEPRECATED_KEY, LOCALE_KEY`

  ### Fields inherited from interface IdentifiedObject

  `ALIAS_KEY, IDENTIFIERS_KEY, NAME_KEY, REMARKS_KEY`

  ### Fields inherited from interface ReferenceSystem

  `DOMAIN_OF_VALIDITY_KEY, SCOPE_KEY`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  ``
  `DefaultCompoundCRS(Map<String,?> properties, CoordinateReferenceSystem... components)`
  Constructs a compound CRS from the given properties and CRS.
  `protected`
  `DefaultCompoundCRS(CompoundCRS crs)`
  Constructs a new coordinate reference system with the same values than the specified one.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static DefaultCompoundCRS`
  `castOrCopy(CompoundCRS object)`
  Returns a SIS CRS implementation with the same values than the given arbitrary implementation.
  `protected long`
  `computeHashCode()`
  Invoked by `hashCode()` for computing the hash code when first needed.
  `boolean`
  `equals(Object object, ComparisonMode mode)`
  Compares this coordinate reference system with the specified object for equality.
  `DefaultCompoundCRS`
  `forConvention(AxesConvention convention)`
  Returns a coordinate reference system equivalent to this one but with axes rearranged according the given convention.
  `protected String`
  `formatTo(Formatter formatter)`
  Formats this CRS as a Well Known Text `CompoundCRS[…]` element.
  `List<CoordinateReferenceSystem>`
  `getComponents()`
  Returns the ordered list of coordinate reference systems.
  `Class<? extends CompoundCRS>`
  `getInterface()`
  Returns the GeoAPI interface implemented by this class.
  `List<SingleCRS>`
  `getSingleComponents()`
  Returns the ordered list of single coordinate reference systems.

  ### Methods inherited from class AbstractCRS

  `castOrCopy, getCoordinateSystem`

  ### Methods inherited from class AbstractReferenceSystem

  `getDomainOfValidity, getScope`

  ### 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 CoordinateReferenceSystem

  `getCoordinateSystem`

  ### Methods inherited from interface IdentifiedObject

  `getAlias, getIdentifiers, getName, getRemarks, toWKT`

  ### Methods inherited from interface ReferenceSystem

  `getDomainOfValidity, getScope`

- ## Constructor Details

  - ### DefaultCompoundCRS

    public DefaultCompoundCRS(Map<String,?> properties, CoordinateReferenceSystem... components)
    Constructs a compound CRS from the given properties and CRS. 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" | `ReferenceIdentifier` or `String` | `AbstractIdentifiedObject.getName()`
    "alias" | `GenericName` or `CharSequence` (optionally as array) | `AbstractIdentifiedObject.getAlias()`
    "identifiers" | `ReferenceIdentifier` (optionally as array) | `AbstractIdentifiedObject.getIdentifiers()`
    "remarks" | `InternationalString` or `String` | `AbstractIdentifiedObject.getRemarks()`
    "domainOfValidity" | `Extent` | `AbstractReferenceSystem.getDomainOfValidity()`
    "scope" | `InternationalString` or `String` | `AbstractReferenceSystem.getScope()`

    Parameters:
      `properties` - the properties to be given to the coordinate reference system.
      `components` - the sequence of coordinate reference systems making this compound CRS.
    Throws:
      `IllegalArgumentException` - if the given array does not contain at least two components, or if two consecutive components are a geographic CRS with an ellipsoidal height.
    See Also:
      - `GeodeticObjectFactory​.createCompoundCRS(Map, CoordinateReferenceSystem...)`

  - ### DefaultCompoundCRS

    protected DefaultCompoundCRS(CompoundCRS crs)
    Constructs a new coordinate reference system 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:
      `crs` - the coordinate reference system to copy.

- ## Method Details

  - ### castOrCopy

    public static DefaultCompoundCRS castOrCopy(CompoundCRS object)
    Returns a SIS CRS implementation with the same values than the given arbitrary implementation. If the given object is `null`, then this method returns `null`. Otherwise if the given object is already a SIS implementation, then the given object is returned unchanged. Otherwise a new SIS implementation is created and initialized to the attribute values of the given object.
    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 CompoundCRS> getInterface()
    Returns the GeoAPI interface implemented by this class. The SIS implementation returns `CompoundCRS​.class`.
    Note for implementers: Subclasses usually do not need to override this method since GeoAPI does not define `CompoundCRS` sub-interface. Overriding possibility is left mostly for implementers who wish to extend GeoAPI with their own set of interfaces.
    Overrides:
      `getInterface` in class `AbstractCRS`
    Returns:
      `CompoundCRS​.class` or a user-defined sub-interface.

  - ### getComponents

    public List<CoordinateReferenceSystem> getComponents()
    Returns the ordered list of coordinate reference systems. This is the list of CRS given at construction time. This list may contains other `CompoundCRS` instances, as described in class Javadoc. For a flattened list of `SingleCRS` instances, see `getSingleComponents()`.
    Specified by:
      `getComponents` in interface `CompoundCRS`
    Returns:
      the coordinate reference systems as an unmodifiable list.

  - ### getSingleComponents

    public List<SingleCRS> getSingleComponents()
    Returns the ordered list of single coordinate reference systems. If this compound CRS contains other compound CRS, then all of them are flattened in a sequence of `SingleCRS` objects. See class Javadoc for more information.
    Returns:
      the single coordinate reference systems as an unmodifiable list.
    See Also:
      - `CRS​.getSingleComponents(CoordinateReferenceSystem)`

  - ### forConvention

    public DefaultCompoundCRS forConvention(AxesConvention convention)
    Returns a coordinate reference system equivalent to this one but with axes rearranged according the given convention. If this CRS is already compatible with the given convention, then this method returns `this`.

    If the given convention is `AxesConvention​.DISPLAY_ORIENTED` or `AxesConvention​.NORMALIZED`, then this method will also reorder the components with horizontal CRS (geodetic or projected) first, then vertical CRS, then temporal CRS.

    Overrides:
      `forConvention` in class `AbstractCRS`
    Parameters:
      `convention` - the axes convention for which a coordinate reference system is desired.
    Returns:
      a coordinate reference system compatible with the given convention (may be `this`).
    See Also:
      - `AbstractCS​.forConvention(AxesConvention)`

  - ### equals

    public boolean equals(Object object, ComparisonMode mode)
    Compares this coordinate reference system with the specified object for equality.
    Specified by:
      `equals` in interface `LenientComparable`
    Overrides:
      `equals` in class `AbstractCRS`
    Parameters:
      `object` - the object to compare to `this`.
      `mode` - `STRICT` for performing a strict comparison, or `IGNORE_METADATA` for comparing only properties relevant to transformations.
    Returns:
      `true` if both objects are equal.
    See Also:
      - `AbstractIdentifiedObject​.computeHashCode()`
      - `Utilities​.deepEquals(Object, Object, ComparisonMode)`

  - ### computeHashCode

    protected long computeHashCode()
    Invoked by `hashCode()` for computing the hash code when first needed. See `AbstractIdentifiedObject​.computeHashCode()` for more information.
    Overrides:
      `computeHashCode` in class `AbstractCRS`
    Returns:
      the hash code value. This value may change in any future Apache SIS version.

  - ### formatTo

    protected String formatTo(Formatter formatter)
    Formats this CRS as a Well Known Text `CompoundCRS[…]` element.

    #### WKT validity

    The WKT version 2 format restricts compound CRS to the following components in that order:
    - A mandatory horizontal CRS (only one of two-dimensional `GeographicCRS` or `ProjectedCRS` or `EngineeringCRS`).
    - Optionally followed by a `VerticalCRS` or a `ParametricCRS` (but not both).
    - Optionally followed by a `TemporalCRS`.
    SIS does not check if this CRS is compliant with the above-cited restrictions.
    Overrides:
      `formatTo` in class `AbstractCRS`
    Parameters:
      `formatter` - the formatter where to format the inner content of this WKT element.
    Returns:
      `"CompoundCRS"` (WKT 2) or `"Compd_CS"` (WKT 1).
    See Also:
      - WKT 2 specification §16