Class AbstractCS
- Object
-
- Formattable
-
- AbstractIdentifiedObject
-
- AbstractCS
-
- All Implemented Interfaces:
Serializable
,CoordinateSystem
,IdentifiedObject
- Direct Known Subclasses:
DefaultAffineCS
,DefaultCompoundCS
,DefaultCylindricalCS
,DefaultEllipsoidalCS
,DefaultLinearCS
,DefaultPolarCS
,DefaultSphericalCS
,DefaultTimeCS
,DefaultUserDefinedCS
,DefaultVerticalCS
public class AbstractCS extends AbstractIdentifiedObject implements CoordinateSystem
The set of coordinate system axes that spans a given coordinate space. A coordinate system (CS) is derived from a set of (mathematical) rules for specifying how coordinates in a given space are to be assigned to points. The coordinate values in a coordinate tuple shall be recorded in the order in which the coordinate system axes are recorded, whenever those coordinates use a coordinate reference system that uses this coordinate system.This class is conceptually abstract, even if it is technically possible to instantiate it. Typical applications should create instances of the most specific subclass with
Default
prefix instead. An exception to this rule may occurs when it is not possible to identify the exact type. For example it is not possible to infer the exact coordinate system from Well Known Text is some cases (e.g. in aLOCAL_CS
element). In such exceptional situation, a plainAbstractCS
object may be instantiated.- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
- See Also:
DefaultCoordinateSystemAxis
,javax.measure.unit.Unit
,AbstractDatum
,AbstractCRS
, Serialized Form
-
-
Field Summary
-
Fields inherited from class AbstractIdentifiedObject
EMPTY_ALIAS_ARRAY, EMPTY_IDENTIFIER_ARRAY, IDENTIFIER_COMPARATOR, NAME_COMPARATOR, REMARKS_COMPARATOR
-
Fields inherited from class Formattable
SINGLE_LINE
-
Fields inherited from interface IdentifiedObject
ALIAS_KEY, IDENTIFIERS_KEY, NAME_KEY, REMARKS_KEY
-
-
Constructor Summary
Constructors Constructor Description AbstractCS(String name, CoordinateSystemAxis... axis)
Constructs a coordinate system from a name.AbstractCS(Map<String,?> properties, CoordinateSystemAxis... axis)
Constructs a coordinate system from a set of properties.AbstractCS(CoordinateSystem cs)
Constructs a new coordinate system with the same values than the specified one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Measure
distance(double[] coord1, double[] coord2)
Computes the distance between two points.boolean
equals(AbstractIdentifiedObject object, boolean compareMetadata)
Compares the specified object with this coordinate system for equality.protected String
formatWKT(Formatter formatter)
Format the inner part of a Well Known Text (WKT) element.CoordinateSystemAxis
getAxis(int dimension)
Returns the axis for this coordinate system at the specified dimension.int
getDimension()
Returns the dimension of the coordinate system.int
hashCode()
Returns a hash value for this coordinate system.protected boolean
isCompatibleDirection(AxisDirection direction)
Returnstrue
if the specified axis direction is allowed for this coordinate system.protected boolean
isCompatibleUnit(AxisDirection direction, Unit<?> unit)
Returnstrue
is the specified unit is legal for the specified axis direction.static CoordinateSystem
standard(CoordinateSystem cs)
Returns a coordinate system with "standard" axis order and units.static Matrix
swapAndScaleAxis(CoordinateSystem sourceCS, CoordinateSystem targetCS)
Returns an affine transform between two coordinate systems.-
Methods inherited from class AbstractIdentifiedObject
asSet, ensureAngularUnit, ensureLinearUnit, ensureNonNull, ensureNonNull, ensureTimeUnit, equals, equals, equals, equals, getAlias, getIdentifier, getIdentifier, getIdentifiers, getName, getName, getName, getProperties, getProperties, getRemarks, nameMatches, nameMatches, nameMatches
-
Methods inherited from class Formattable
cleanupThreadLocals, toString, toWKT, toWKT, toWKT, toWKT
-
Methods inherited from interface IdentifiedObject
getAlias, getIdentifiers, getName, getRemarks, toWKT
-
-
-
-
Constructor Detail
-
AbstractCS
public AbstractCS(CoordinateSystem cs)
Constructs a new coordinate system with the same values than the specified one. This copy constructor provides a way to wrap an arbitrary implementation into a Geotools 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:
cs
- The coordinate system to copy.- Since:
- 2.2
-
AbstractCS
public AbstractCS(String name, CoordinateSystemAxis... axis)
Constructs a coordinate system from a name.- Parameters:
name
- The coordinate system name.axis
- The set of axis.
-
AbstractCS
public AbstractCS(Map<String,?> properties, CoordinateSystemAxis... axis)
Constructs a coordinate system from a set of properties. The properties map is given unchanged to the super-class constructor.- Parameters:
properties
- Set of properties. Should contains at least"name"
.axis
- The set of axis.
-
-
Method Detail
-
isCompatibleDirection
protected boolean isCompatibleDirection(AxisDirection direction)
Returnstrue
if the specified axis direction is allowed for this coordinate system. This method is invoked at construction time for checking argument validity. The default implementation returnstrue
for all axis directions. Subclasses will overrides this method in order to put more restrictions on allowed axis directions.- Parameters:
direction
- The direction to test for compatibility.- Returns:
true
if the given direction is compatible with this coordinate system.
-
isCompatibleUnit
protected boolean isCompatibleUnit(AxisDirection direction, Unit<?> unit)
Returnstrue
is the specified unit is legal for the specified axis direction. This method is invoked at construction time for checking units compatibility. The default implementation returnstrue
in all cases. Subclasses can override this method and check for compatibility with meter or degree units.- Parameters:
direction
- The direction of the axis having the given unit.unit
- The unit to test for compatibility.- Returns:
true
if the given unit is compatible with this coordinate system.- Since:
- 2.2
-
getDimension
public int getDimension()
Returns the dimension of the coordinate system. This is the number of axis.- Specified by:
getDimension
in interfaceCoordinateSystem
- Returns:
- The dimension of the coordinate system.
-
getAxis
public CoordinateSystemAxis getAxis(int dimension) throws IndexOutOfBoundsException
Returns the axis for this coordinate system at the specified dimension.- Specified by:
getAxis
in interfaceCoordinateSystem
- Parameters:
dimension
- The zero based index of axis.- Returns:
- The axis at the specified dimension.
- Throws:
IndexOutOfBoundsException
- ifdimension
is out of bounds.
-
swapAndScaleAxis
public static Matrix swapAndScaleAxis(CoordinateSystem sourceCS, CoordinateSystem targetCS) throws IllegalArgumentException
Returns an affine transform between two coordinate systems. Only units and axis order (e.g. transforming from (NORTH,WEST) to (EAST,NORTH are taken in account.Example: If coordinates in
sourceCS
are (x,y) pairs in metres and coordinates intargetCS
are (-y,x) pairs in centimetres, then the transformation can be performed as below:[-y(cm)] [ 0 -100 0 ] [x(m)] [ x(cm)] = [ 100 0 0 ] [y(m)] [ 1 ] [ 0 0 1 ] [1 ]
- Parameters:
sourceCS
- The source coordinate system.targetCS
- The target coordinate system.- Returns:
- The conversion from
sourceCS
totargetCS
as an affine transform. Only axis direction and units are taken in account. - Throws:
IllegalArgumentException
- if axis doesn't matches, or the CS doesn't have the same geometry.ConversionException
- if the unit conversion is non-linear.
-
standard
public static CoordinateSystem standard(CoordinateSystem cs) throws IllegalArgumentException
Returns a coordinate system with "standard" axis order and units. Most of the time, this method returns one of the predefined constants with axis in (longitude,latitude) or (X,Y) order, and units in degrees or metres. In some particular cases like Cartesian CS, this method may create a new instance on the fly. In every cases this method attempts to return a right-handed coordinate system, but this is not garanteed.This method is typically used together with
swapAndScaleAxis
for the creation of a transformation step before some math transform. Example:Matrix step1 = swapAndScaleAxis(sourceCS, standard(sourceCS)); Matrix step2 = ... some transform operating on standard axis ... Matrix step3 = swapAndScaleAxis(standard(targetCS), targetCS);
- Parameters:
cs
- The coordinate system.- Returns:
- A constant similar to the specified
cs
with "standard" axis. - Throws:
IllegalArgumentException
- if the specified coordinate system is unknow to this method.- Since:
- 2.2
-
distance
public Measure distance(double[] coord1, double[] coord2) throws UnsupportedOperationException, MismatchedDimensionException
Computes the distance between two points. This method is not available for all coordinate systems. For example, ellipsoidal CS doesn't have suffisient information.- Parameters:
coord1
- Coordinates of the first point.coord2
- Coordinates of the second point.- Returns:
- The distance between
coord1
andcoord2
. - Throws:
UnsupportedOperationException
- if this coordinate system can't compute distances.MismatchedDimensionException
- if a coordinate doesn't have the expected dimension.
-
equals
public boolean equals(AbstractIdentifiedObject object, boolean compareMetadata)
Compares the specified object with this coordinate system for equality.- Overrides:
equals
in classAbstractIdentifiedObject
- Parameters:
object
- The object to compare tothis
.compareMetadata
-true
for performing a strict comparaison, orfalse
for comparing only properties relevant to transformations.- Returns:
true
if both objects are equal.
-
hashCode
public int hashCode()
Returns a hash value for this coordinate system.- Overrides:
hashCode
in classAbstractIdentifiedObject
- Returns:
- The hash code value. This value doesn't need to be the same in past or future versions of this class.
-
formatWKT
protected String formatWKT(Formatter formatter)
Format the inner part of a Well Known Text (WKT) element. Note that WKT is not yet defined for coordinate system. Current implementation list the axis contained in this CS.- Overrides:
formatWKT
in classFormattable
- Parameters:
formatter
- The formatter to use.- Returns:
- The WKT element name. Current implementation default to the class name.
- See Also:
Formattable.toWKT()
,Formattable.toString()
-
-