Object
SimpleDirectPosition
- All Implemented Interfaces:
Position
,DirectPosition
A
DirectPosition
implementation which store coordinate values in a double[]
array.
This implementation can store an optional reference to an existing
Coordinate Reference System.- Since:
- 3.1
-
Field Summary
Modifier and TypeFieldDescriptionfinal double[]
The coordinate values.protected CoordinateReferenceSystem
The coordinate reference system associated to this direct position, ornull
if unspecified. -
Constructor Summary
ConstructorDescriptionSimpleDirectPosition
(int dimension) Creates a new direct position of the given dimension.SimpleDirectPosition
(DirectPosition position) Creates a new direct position initialized to the CRS and coordinate values of the given direct position.Creates a new direct position associated to the given coordinate reference system.SimpleDirectPosition
(CoordinateReferenceSystem crs, double... coordinates) Creates a new direct position initialized to the given coordinate values. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the specified object is also aDirectPosition
with equal coordinate and equal CRS.double[]
Returns a copy of the coordinates array.Returns the coordinate reference system in which the coordinate is given.int
The length of coordinate sequence (the number of entries).Unconditionally returnsthis
, since this object is already a direct position.double
getOrdinate
(int dimension) Returns the coordinate at the specified dimension.int
hashCode()
Returns a hash code value for this direct position.void
setOrdinate
(int dimension, double value) Sets the coordinate value along the specified dimension.toString()
Returns a string representation of this direct position in Well-Known Text (WKT) format.
-
Field Details
-
coordinates
public final double[] coordinatesThe coordinate values. The length of this array is the dimension of this direct position.This array is public for allowing more efficient coordinates operations, for example using the
Arrays
methods. However, we encourage to use only the methods from theDirectPosition
interface in most cases.- See Also:
-
crs
The coordinate reference system associated to this direct position, ornull
if unspecified.The
SimpleDirectPosition
class does not provide any setter for this field, since uncontrolled modifications of geometry CRS is often undesirable. The decision to allow modifications or not is left to subclasses.- See Also:
-
-
Constructor Details
-
SimpleDirectPosition
public SimpleDirectPosition(int dimension) Creates a new direct position of the given dimension. The Coordinate Reference System is left unspecified. All coordinate values are initialized to zero.- Parameters:
dimension
- the dimension.
-
SimpleDirectPosition
Creates a new direct position associated to the given coordinate reference system. The dimension of the new direct position is the dimension of the given CRS. All coordinate values are initialized to zero.- Parameters:
crs
- the coordinate reference system to associate to the new direct position.
-
SimpleDirectPosition
public SimpleDirectPosition(CoordinateReferenceSystem crs, double... coordinates) throws MismatchedDimensionException Creates a new direct position initialized to the given coordinate values. If the given CRS is non-null, then its dimension shall be equal to the length of the givencoordinates
array.This constructor assigns the given array directly (without clone) to the
coordinates
field, because that field is public anyway. Defensive copy would not protect the state of this object.- Parameters:
crs
- the coordinate reference system, ornull
.coordinates
- the coordinate values. This array is not cloned.- Throws:
MismatchedDimensionException
- if the given CRS is not null and its dimension is not equals to the length of thecoordinates
array.
-
SimpleDirectPosition
Creates a new direct position initialized to the CRS and coordinate values of the given direct position. This is a copy constructor.- Parameters:
position
- the direct position from which to copy the CRS and coordinate values.
-
-
Method Details
-
getCoordinateReferenceSystem
Returns the coordinate reference system in which the coordinate is given. May benull
if no CRS were specified at construction time. In such case, this particular direct position is assumed included in a larger object with such a reference to a coordinate reference system.- Specified by:
getCoordinateReferenceSystem
in interfaceDirectPosition
- Returns:
- the coordinate reference system, or
null
.
-
getDimension
public int getDimension()The length of coordinate sequence (the number of entries).- Specified by:
getDimension
in interfaceDirectPosition
- Returns:
- the length of the
coordinates
array.
-
getCoordinate
public double[] getCoordinate()Returns a copy of the coordinates array.- Specified by:
getCoordinate
in interfaceDirectPosition
- Returns:
- a clone of the
coordinates
array.
-
getOrdinate
Returns the coordinate at the specified dimension.- Specified by:
getOrdinate
in interfaceDirectPosition
- Parameters:
dimension
- the dimension in the range 0 to dimension-1.- Returns:
- the value in the
coordinates
array at the given index. - Throws:
IndexOutOfBoundsException
- if the given index is negative or is equal or greater than the position dimension.
-
setOrdinate
Sets the coordinate value along the specified dimension.- Specified by:
setOrdinate
in interfaceDirectPosition
- Parameters:
dimension
- the dimension for the coordinate of interest.value
- the coordinate value of interest.- Throws:
IndexOutOfBoundsException
- if the given index is negative or is equal or greater than the position dimension.
-
getDirectPosition
Unconditionally returnsthis
, since this object is already a direct position.- Specified by:
getDirectPosition
in interfacePosition
- Returns:
- the direct position (may be
this
).
-
equals
Returnstrue
if the specified object is also aDirectPosition
with equal coordinate and equal CRS. This method performs the comparison as documented in theDirectPosition.equals(Object)
Javadoc. In particular, the given object is not required to be of the same implementation class. Consequently, it should be possible to mix differentDirectPosition
implementations in the same hash map.- Specified by:
equals
in interfaceDirectPosition
- Overrides:
equals
in classObject
- Parameters:
object
- the object to compare with this direct position for equality.- Returns:
true
if the given object is equal to this direct position.
-
hashCode
public int hashCode()Returns a hash code value for this direct position. This method returns a value compliant with the contract documented in theDirectPosition.hashCode()
javadoc. Consequently, it should be possible to mix differentDirectPosition
implementations in the same hash map.- Specified by:
hashCode
in interfaceDirectPosition
- Overrides:
hashCode
in classObject
- Returns:
- a hash code value for this position.
-
toString
Returns a string representation of this direct position in Well-Known Text (WKT) format.
-