Package org.apache.sis.geometry
Class DirectPosition1D
- Object
-
- FormattableObject
-
- AbstractDirectPosition
-
- DirectPosition1D
-
- All Implemented Interfaces:
Serializable,Cloneable,Position,DirectPosition
public class DirectPosition1D extends AbstractDirectPosition implements Serializable, Cloneable
A one-dimensional position within some coordinate reference system.- Since:
- 0.3
- See Also:
DirectPosition2D,GeneralDirectPosition,CoordinateFormat, Serialized Form
Defined in the
sis-referencingmodule
-
-
Field Summary
Fields Modifier and Type Field Description doublecoordinateThe coordinate value.
-
Constructor Summary
Constructors Constructor Description DirectPosition1D()Constructs a position initialized to (0) with anullcoordinate reference system.DirectPosition1D(double coordinate)Constructs a 1D position from the specified coordinate.DirectPosition1D(CharSequence wkt)Constructs a position initialized to the values parsed from the given string in Well Known Text (WKT) format.DirectPosition1D(CoordinateReferenceSystem crs)Constructs a position with the specified coordinate reference system.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectPosition1Dclone()Returns a copy of this position.double[]getCoordinate()Returns a sequence of numbers that hold the coordinate of this position in its reference system.CoordinateReferenceSystemgetCoordinateReferenceSystem()Returns the coordinate reference system in which the coordinate is given.intgetDimension()The length of coordinate sequence (the number of entries).doublegetOrdinate(int dimension)Returns the coordinate at the specified dimension.inthashCode()Returns a hash value for this coordinate tuple.voidsetCoordinateReferenceSystem(CoordinateReferenceSystem crs)Sets the coordinate reference system in which the coordinate is given.voidsetLocation(DirectPosition position)Sets this coordinate to the specified direct position.voidsetOrdinate(int dimension, double value)Sets the coordinate value along the specified dimension.StringtoString()Formats this position in the Well Known Text (WKT) format.-
Methods inherited from class AbstractDirectPosition
castOrCopy, equals, formatTo, getDirectPosition, normalize
-
Methods inherited from class FormattableObject
print, toString, toWKT
-
-
-
-
Constructor Detail
-
DirectPosition1D
public DirectPosition1D()
Constructs a position initialized to (0) with anullcoordinate reference system.
-
DirectPosition1D
public DirectPosition1D(CoordinateReferenceSystem crs)
Constructs a position with the specified coordinate reference system.- Parameters:
crs- the coordinate reference system.
-
DirectPosition1D
public DirectPosition1D(double coordinate)
Constructs a 1D position from the specified coordinate.- Parameters:
coordinate- the coordinate value.
-
DirectPosition1D
public DirectPosition1D(CharSequence wkt) throws IllegalArgumentException
Constructs a position initialized to the values parsed from the given string in Well Known Text (WKT) format. The given string is typically aPOINTelement like below:POINT(6)
- Parameters:
wkt- thePOINTor other kind of element to parse.- Throws:
IllegalArgumentException- if the given string can not be parsed.MismatchedDimensionException- if the given point is not one-dimensional.- See Also:
toString(),CoordinateFormat
-
-
Method Detail
-
getDimension
public final int getDimension()
The length of coordinate sequence (the number of entries). This is always 1 forDirectPosition1Dobjects.- Specified by:
getDimensionin interfaceDirectPosition- Returns:
- the dimensionality of this position.
-
getCoordinateReferenceSystem
public final CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the coordinate reference system in which the coordinate is given. May benullif this particularDirectPositionis included in a larger object with such a reference to a CRS.- Specified by:
getCoordinateReferenceSystemin interfaceDirectPosition- Returns:
- the coordinate reference system, or
null.
-
setCoordinateReferenceSystem
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate is given.- Parameters:
crs- the new coordinate reference system, ornull.
-
getCoordinate
public final double[] getCoordinate()
Returns a sequence of numbers that hold the coordinate of this position in its reference system.API note: This method is final for ensuring consistency with thecoordinatefield, which is public.- Specified by:
getCoordinatein interfaceDirectPosition- Overrides:
getCoordinatein classAbstractDirectPosition- Returns:
- the coordinates.
-
getOrdinate
public final double getOrdinate(int dimension) throws IndexOutOfBoundsExceptionReturns the coordinate at the specified dimension.API note: This method is final for ensuring consistency with thecoordinatefield, which is public.- Specified by:
getOrdinatein interfaceDirectPosition- Parameters:
dimension- the dimension, which must be 0.- Returns:
- the
coordinate. - Throws:
IndexOutOfBoundsException- if the specified dimension is out of bounds.
-
setOrdinate
public void setOrdinate(int dimension, double value) throws IndexOutOfBoundsExceptionSets the coordinate value along the specified dimension.- Specified by:
setOrdinatein interfaceDirectPosition- Parameters:
dimension- the dimension, which must be 0.value- the coordinate value.- Throws:
IndexOutOfBoundsException- if the specified dimension is out of bounds.
-
setLocation
public void setLocation(DirectPosition position) throws MismatchedDimensionException
Sets this coordinate to the specified direct position. If the specified position contains a coordinate reference system (CRS), then the CRS for this position will be set to the CRS of the specified position.- Overrides:
setLocationin classAbstractDirectPosition- Parameters:
position- the new position for this point.- Throws:
MismatchedDimensionException- if this point doesn't have the expected dimension.
-
toString
public String toString()
Formats this position in the Well Known Text (WKT) format. The output is like below:
The string returned by this method can be parsed by thePOINT(coordinate)
DirectPosition1Dconstructor.- Overrides:
toStringin classAbstractDirectPosition- Returns:
- this position as a
POINTin Well Known Text (WKT) format.
-
clone
public DirectPosition1D clone()
Returns a copy of this position.
-
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 differentDirectPositionimplementations in the same hash map.- Specified by:
hashCodein interfaceDirectPosition- Overrides:
hashCodein classAbstractDirectPosition- Returns:
- a hash code value for this position.
-
-