Class AbstractDirectPosition
- All Implemented Interfaces:
org.opengis.geometry.coordinate.Position
,org.opengis.geometry.DirectPosition
- Direct Known Subclasses:
AbstractEnvelope.Point
,DirectPosition1D
,DirectPositionView
,GeneralDirectPosition
DirectPosition
methods, leaving the data storage to subclasses.
A direct position holds the coordinates for a position within some
coordinate reference system.
This base class provides default implementations for toString()
,
equals(Object)
and hashCode()
methods.
This base class does not hold any state and does not implement the Serializable
or Cloneable
interfaces. The internal representation, and the choice to be cloneable or
serializable, is left to subclasses.
- Since:
- 0.3
- Version:
- 1.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractDirectPosition
castOrCopy
(org.opengis.geometry.DirectPosition position) Returns the given position as anAbstractDirectPosition
instance.boolean
Returnstrue
if the specified object is also aDirectPosition
with equal coordinates and equal CRS.protected String
Formats this position in the Well Known Text (WKT) format.double[]
Returns a sequence of numbers that hold the coordinate of this position in its reference system.org.opengis.referencing.crs.CoordinateReferenceSystem
Returns the coordinate reference system in which the coordinate tuple is given.final org.opengis.geometry.DirectPosition
Returns alwaysthis
, the direct position for this position.int
hashCode()
Returns a hash value for this coordinate tuple.boolean
Ensures that the position is contained in the coordinate system domain.(package private) static double[]
parse
(CharSequence wkt) Parses the given WKT.void
setLocation
(org.opengis.geometry.DirectPosition position) Sets this direct position to the given position.void
setOrdinate
(int dimension, double value) Sets the coordinate value along the specified dimension.toString()
Formats this position in the Well Known Text (WKT) format.(package private) static String
toString
(org.opengis.geometry.DirectPosition position, boolean isSinglePrecision) Implementation of the publictoString()
andDirectPosition2D.toString()
methods for formatting aPOINT
element from a direct position in Well Known Text (WKT) format.Methods inherited from class org.apache.sis.io.wkt.FormattableObject
print, toString, toWKT
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opengis.geometry.DirectPosition
getDimension, getOrdinate
-
Constructor Details
-
AbstractDirectPosition
protected AbstractDirectPosition()Constructs a direct position.
-
-
Method Details
-
castOrCopy
Returns the given position as anAbstractDirectPosition
instance. If the given position is already an instance ofAbstractDirectPosition
, then it is returned unchanged. Otherwise the coordinate values and the CRS of the given position are copied in a new position.- Parameters:
position
- the position to cast, ornull
.- Returns:
- the values of the given position as an
AbstractDirectPosition
instance. - Since:
- 1.0
-
getDirectPosition
public final org.opengis.geometry.DirectPosition getDirectPosition()Returns alwaysthis
, the direct position for this position.- Specified by:
getDirectPosition
in interfaceorg.opengis.geometry.coordinate.Position
- Returns:
this
.
-
getCoordinateReferenceSystem
public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()Returns the coordinate reference system in which the coordinate tuple is given. May benull
if this particularDirectPosition
is included in a larger object with such a reference to a coordinate reference system.The default implementation returns
null
. Subclasses should override this method if the CRS can be provided.- Specified by:
getCoordinateReferenceSystem
in interfaceorg.opengis.geometry.DirectPosition
- Returns:
- the coordinate reference system, or
null
.
-
getCoordinate
public double[] getCoordinate()Returns a sequence of numbers that hold the coordinate of this position in its reference system.- Specified by:
getCoordinate
in interfaceorg.opengis.geometry.DirectPosition
- Returns:
- the coordinates.
-
setOrdinate
public void setOrdinate(int dimension, double value) Sets the coordinate value along the specified dimension.The default implementation throws
UnsupportedOperationException
. Subclasses need to override this method if this direct position is mutable.- Specified by:
setOrdinate
in interfaceorg.opengis.geometry.DirectPosition
- 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.UnsupportedOperationException
- if this direct position is immutable.
-
setLocation
public void setLocation(org.opengis.geometry.DirectPosition position) throws org.opengis.geometry.MismatchedDimensionException, MismatchedReferenceSystemException Sets this direct position to the given position. If the given position isnull
, then all coordinate values are set toNaN
.If this position and the given position have a non-null CRS, then the default implementation requires the CRS to be equals (ignoring metadata), otherwise a
MismatchedReferenceSystemException
is thrown. However, subclass may choose to assign the CRS of this position to the CRS of the given position.- Parameters:
position
- the new position, ornull
.- Throws:
org.opengis.geometry.MismatchedDimensionException
- if the given position doesn't have the expected dimension.MismatchedReferenceSystemException
- if the given position doesn't use the expected CRS.
-
normalize
public boolean normalize()Ensures that the position is contained in the coordinate system domain. For each dimension, this method compares the coordinate values against the limits of the coordinate system axis for that dimension. If some coordinates are out of range, then there is a choice depending on the axis range meaning:- If
RangeMeaning.EXACT
(typically latitudes coordinates), then values greater than the axis maximal value are replaced by the axis maximum, and values smaller than the axis minimal value are replaced by the axis minimum. - If
RangeMeaning.WRAPAROUND
(typically longitudes coordinates), then a multiple of the axis range (e.g. 360° for longitudes) is added or subtracted.
- Returns:
true
if this position has been modified as a result of this method call, orfalse
if no change has been done.- See Also:
- If
-
formatTo
Formats this position in the Well Known Text (WKT) format. The format is like below, wherex₀
,x₁
,x₂
, etc. are the coordinate values at index 0, 1, 2, etc.: If the coordinate reference system is geodetic or projected, then coordinate values are formatted with a precision equivalent to one centimetre on Earth (the actual number of fraction digits is adjusted for the axis unit of measurement and the planet size if different than Earth).- Specified by:
formatTo
in classFormattableObject
- Parameters:
formatter
- the formatter where to format the inner content of this point.- Returns:
- the WKT keyword, which is
"Point"
for this element. - Since:
- 1.0
- See Also:
-
toString
Formats this position in the Well Known Text (WKT) format. The returned string is like below, wherex₀
,x₁
,x₂
, etc. are the coordinate values at index 0, 1, 2, etc.: This method formats the numbers as withDouble.toString(double)
(i.e. without fixed number of fraction digits). The string returned by this method can be parsed by theGeneralDirectPosition
constructor.- Overrides:
toString
in classFormattableObject
- Returns:
- this position as a
POINT
in Well Known Text (WKT) format.
-
toString
Implementation of the publictoString()
andDirectPosition2D.toString()
methods for formatting aPOINT
element from a direct position in Well Known Text (WKT) format.- Parameters:
position
- the position to format.isSinglePrecision
-true
if every coordinate values can be casted tofloat
.- Returns:
- the point as a
POINT
in WKT format. - See Also:
-
parse
Parses the given WKT.- Parameters:
wkt
- the WKT to parse.- Returns:
- the coordinates, or
null
if none. - Throws:
NumberFormatException
- if a number cannot be parsed.IllegalArgumentException
- if the parenthesis are not balanced.
-
hashCode
public int hashCode()Returns a hash value for this coordinate tuple. 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. -
equals
Returnstrue
if the specified object is also aDirectPosition
with equal coordinates 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.
-