Package org.opengis.example.geometry
Class SimpleDirectPosition
- Object
-
- SimpleDirectPosition
-
- All Implemented Interfaces:
Serializable
,Position
,DirectPosition
public class SimpleDirectPosition extends Object implements DirectPosition, Serializable
ADirectPosition
implementation which store ordinate values in adouble[]
array. This implementation can store an optional reference to an existing Coordinate Reference System.- Since:
- 3.1
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected CoordinateReferenceSystem
crs
The coordinate reference system associated to this direct position, ornull
if unspecified.double[]
ordinates
The ordinate values.
-
Constructor Summary
Constructors Constructor Description SimpleDirectPosition(int dimension)
Creates a new direct position of the given dimension.SimpleDirectPosition(DirectPosition position)
Creates a new direct position initialized to the CRS and ordinate values of the given direct position.SimpleDirectPosition(CoordinateReferenceSystem crs)
Creates a new direct position associated to the given coordinate reference system.SimpleDirectPosition(CoordinateReferenceSystem crs, double... ordinates)
Creates a new direct position initialized to the given ordinate values.
-
Method Summary
Modifier and Type Method Description boolean
equals(Object object)
Returnstrue
if the specified object is also aDirectPosition
with equal coordinate and equal CRS.double[]
getCoordinate()
Returns a copy of the ordinates array.CoordinateReferenceSystem
getCoordinateReferenceSystem()
Returns the coordinate reference system in which the coordinate is given.int
getDimension()
The length of coordinate sequence (the number of entries).DirectPosition
getDirectPosition()
Unconditionally returnsthis
, since this object is already a 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.String
toString()
Returns a string representation of this direct position in Well-Known Text (WKT) format.
-
-
-
Field Detail
-
ordinates
public final double[] ordinates
The ordinate values. The length of this array is the dimension of this direct position.This array is public for allowing more efficient ordinates operations, for example using the
Arrays
methods. However we encourage to use only the methods from theDirectPosition
interface in most cases.- See Also:
getCoordinate()
-
crs
protected CoordinateReferenceSystem 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:
getCoordinateReferenceSystem()
-
-
Constructor Detail
-
SimpleDirectPosition
public SimpleDirectPosition(int dimension)
Creates a new direct position of the given dimension. The Coordinate Reference System is left unspecified. All ordinate values are initialized to zero.- Parameters:
dimension
- the dimension.
-
SimpleDirectPosition
public SimpleDirectPosition(CoordinateReferenceSystem crs)
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 ordinate values are initialized to zero.- Parameters:
crs
- the coordinate reference system to associate to the new direct position.
-
SimpleDirectPosition
public SimpleDirectPosition(CoordinateReferenceSystem crs, double... ordinates) throws MismatchedDimensionException
Creates a new direct position initialized to the given ordinate values. If the given CRS is non-null, then its dimension shall be equal to the length of the givenordinates
array.This constructor assigns the given array directly (without clone) to the
ordinates
field, because that field is public anyway. Defensive copy would not protect the state of this object.- Parameters:
crs
- the coordinate reference system, ornull
.ordinates
- the ordinate 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 theordinates
array.
-
SimpleDirectPosition
public SimpleDirectPosition(DirectPosition position)
Creates a new direct position initialized to the CRS and ordinate values of the given direct position. This is a copy constructor.- Parameters:
position
- the direct position from which to copy the CRS and ordinate values.
-
-
Method Detail
-
getCoordinateReferenceSystem
public CoordinateReferenceSystem 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
ordinates
array.
-
getCoordinate
public double[] getCoordinate()
Returns a copy of the ordinates array.- Specified by:
getCoordinate
in interfaceDirectPosition
- Returns:
- a clone of the
ordinates
array.
-
getOrdinate
public double getOrdinate(int dimension) throws IndexOutOfBoundsException
Returns the ordinate 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
ordinates
array at the given index. - Throws:
IndexOutOfBoundsException
- if the given index is negative or is equals or greater than the position dimension.
-
setOrdinate
public void setOrdinate(int dimension, double value) throws IndexOutOfBoundsException
Sets the ordinate value along the specified dimension.- Specified by:
setOrdinate
in interfaceDirectPosition
- 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 position dimension.
-
getDirectPosition
public DirectPosition getDirectPosition()
Unconditionally returnsthis
, since this object is already a direct position.- Specified by:
getDirectPosition
in interfacePosition
-
equals
public boolean equals(Object object)
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
-
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
public String toString()
Returns a string representation of this direct position in Well-Known Text (WKT) format.- Overrides:
toString
in classObject
- Returns:
- the Well-Known Text representation of this direct position.
- See Also:
- Well-known text on Wikipedia
-
-