Package org.geotools.api.geometry
Interface Position
-
- All Known Implementing Classes:
AbstractPosition
,GeneralPosition
,Position1D
,Position2D
,Position3D
,TransformedPosition
public interface Position
Holds the coordinates for a position within some coordinate reference system. SinceDirectPosition
s, as data types, will often be included in larger objects (such as geometries) that have references to coordinate reference system, thegetCoordinateReferenceSystem()
method may returnsnull
if this particularDirectPosition
is included in a larger object with such a reference to a coordinate reference system. In this case, the cordinate reference system is implicitly assumed to take on the value of the containing object's coordinate reference system.Note: this interface does not extends
Cloneable
on purpose, sinceDirectPosition
implementations are most likely to be backed by references to internal structures of the geometry containing this position. A direct position may or may not be cloneable at implementor choice.- Since:
- GeoAPI 1.0
- Author:
- Martin Desruisseaux (IRD)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
equals(Object object)
Compares this direct position with the specified object for equality.double[]
getCoordinate()
A copy of the ordinates presented as an array of double values.CoordinateReferenceSystem
getCoordinateReferenceSystem()
The coordinate reference system in which the coordinate is given.int
getDimension()
The length of coordinate sequence (the number of entries).Position
getDirectPosition()
Returns the direct position.double
getOrdinate(int dimension)
Returns the ordinate at the specified dimension.int
hashCode()
Returns a hash code value for this direct position.void
setOrdinate(int dimension, double value)
Sets the ordinate value along the specified dimension.
-
-
-
Method Detail
-
getCoordinateReferenceSystem
@UML(identifier="coordinateReferenceSystem", obligation=MANDATORY, specification=ISO_19107) CoordinateReferenceSystem getCoordinateReferenceSystem()
The coordinate reference system in which the coordinate is given. May benull
if this particularDirectPosition
is included in a larger object with such a reference to a coordinate reference system. In this case, the cordinate reference system is implicitly assumed to take on the value of the containing object's coordinate reference system.- Returns:
- The coordinate reference system, or
null
.
-
getDimension
int getDimension()
The length of coordinate sequence (the number of entries). This is determined by the coordinate reference system.- Returns:
- The dimensionality of this position.
-
getCoordinate
double[] getCoordinate()
A copy of the ordinates presented as an array of double values. Please note that this is only a copy (the real values may be stored in another format) so changes to the returned array will not affect the source DirectPosition.final int dim = position.getDimension(); for (int i=0; i<dim; i++) { position.getOrdinate(i); // no copy overhead }
position.setOrdinate(i, value); // edit in place
- We want an array of coordinates with the intend to modify it for computation purpose
(without modifying the original
DirectPosition
), or we want to protect the array from futureDirectPosition
changes. - If
DirectPosition.getOrdinates()
is garanteed to not return the backing array, then we can work directly on this array. If we don't have this garantee, then we must conservatively clone the array in every cases. - Cloning the returned array is useless if the implementation cloned the array or was forced to returns a new array anyway (for example because the coordinates were computed on the fly)
Precedence is given to data integrity over
getOrdinates()
performance. Performance concern can be avoided with usage ofgetOrdinate(int)
.- Returns:
- A copy of the coordinates. Changes in the returned array will not be reflected back
in this
DirectPosition
object.
- We want an array of coordinates with the intend to modify it for computation purpose
(without modifying the original
-
getDirectPosition
@UML(identifier="direct", obligation=CONDITIONAL, specification=ISO_19107) Position getDirectPosition()
Returns the direct position. This method shall never returnsnull
, but may returnsthis
if invoked on an object which is already aDirectPosition
instance.- Returns:
- The direct position (may be
this
). - Since:
- GeoAPI 2.2
-
getOrdinate
double getOrdinate(int dimension) throws IndexOutOfBoundsException
Returns the ordinate at the specified dimension.- Parameters:
dimension
- The dimension in the range 0 to dimension-1.- Returns:
- The coordinate at the specified dimension.
- Throws:
IndexOutOfBoundsException
- If the given index is negative or is equals or greater than the envelope dimension.
-
setOrdinate
void setOrdinate(int dimension, double value) throws IndexOutOfBoundsException, UnsupportedOperationException
Sets the ordinate value along the specified dimension.- Parameters:
dimension
- the dimension for the ordinate of interest.value
- the ordinate value of interest.- Throws:
IndexOutOfBoundsException
- If the given index is negative or is equals or greater than the envelope dimension.UnsupportedOperationException
- if this direct position is immutable.
-
equals
boolean equals(Object object)
Compares this direct position with the specified object for equality. Two direct positions are considered equal if the following conditions are meet:object
is non-null and is an instance ofDirectPosition
.- Both direct positions have the same number of dimension.
- Both direct positions have the same or equal coordinate reference system.
- For all dimension i, the ordinate value of both
direct positions at that dimension are equals in the sense of
Double.equals(java.lang.Object)
. In other words,Arrays.equals(getCoordinate(), object.getCoordinate())
returnstrue
.
-
hashCode
int hashCode()
Returns a hash code value for this direct position. This method should returns the same value as:{@linkplain java.util.Arrays.hashCode(double[]) Arrays.hashCode}(getCoordinate()) + getCoordinateReferenceSystem().hashCode()
where the right hand side of the addition is omitted if the coordinate reference system is null.
-
-