Package org.apache.sis.geometry
Class GeneralDirectPosition
Object
FormattableObject
AbstractDirectPosition
GeneralDirectPosition
- All Implemented Interfaces:
- Serializable,- Cloneable,- Position,- DirectPosition
public class GeneralDirectPosition
extends AbstractDirectPosition
implements Serializable, Cloneable
A mutable 
DirectPosition (the coordinates of a position) of arbitrary dimension.
 This particular implementation of DirectPosition is said "General" because it
 uses an array of coordinates of an arbitrary length. If the direct
 position is known to be always two-dimensional, then DirectPosition2D provides
 a more efficient implementation.
 Coordinate Reference System (CRS) optionality
SinceDirectPositions, as data types, will often be included in larger objects
 (such as Geometry) that have references
 to CoordinateReferenceSystem, the getCoordinateReferenceSystem() method
 may returns null if this particular DirectPosition is included in such
 larger object. In this case, the coordinate reference system is implicitly assumed to take
 on the value of the containing object's CoordinateReferenceSystem.- Since:
- 0.3
- See Also:
Defined in the sis-referencing module
- 
Field SummaryFieldsModifier and TypeFieldDescriptionfinal double[]The coordinates of the direct position.
- 
Constructor SummaryConstructorsConstructorDescriptionGeneralDirectPosition(double... coordinates) Constructs a position with the specified coordinates.GeneralDirectPosition(int dimension) Constructs a position with the specified number of dimensions.Constructs a position initialized to the values parsed from the given string in Well Known Text (WKT) format.Constructs a position initialized to the same values than the specified point.Constructs a position using the specified coordinate reference system.
- 
Method SummaryModifier and TypeMethodDescriptionclone()Returns a deep copy of this position.booleanReturnstrueif the specified object is also aDirectPositionwith equal coordinates and equal CRS.final double[]Returns a sequence of numbers that hold the coordinate of this position in its reference system.Returns the coordinate reference system in which the coordinate is given.final intThe length of coordinate sequence (the number of entries).final doublegetOrdinate(int dimension) Returns the coordinate at the specified dimension.intReturns a hash value for this coordinate tuple.voidsetCoordinate(double... coordinates) Sets the coordinate values along all dimensions.voidSets 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.Formats this position in the Well Known Text (WKT) format.Methods inherited from class AbstractDirectPositioncastOrCopy, formatTo, getDirectPosition, normalizeMethods inherited from class FormattableObjectprint, toString, toWKT
- 
Field Details- 
coordinatespublic final double[] coordinatesThe coordinates of the direct position. The length of this array is the dimension of this direct position.
 
- 
- 
Constructor Details- 
GeneralDirectPositionConstructs a position using the specified coordinate reference system. The number of dimensions is inferred from the coordinate reference system. All coordinate values are initialized to zero.- Parameters:
- crs- the coordinate reference system to be given to this position.
 
- 
GeneralDirectPositionConstructs a position with the specified number of dimensions. All coordinate values are initialized to zero.- Parameters:
- dimension- number of dimensions.
- Throws:
- NegativeArraySizeException- if- dimensionis negative.
 
- 
GeneralDirectPositionpublic GeneralDirectPosition(double... coordinates) Constructs a position with the specified coordinates. This constructor assigns the given array directly (without clone) to thecoordinatesfield. Consequently, callers shall not recycle the same array for creating many instances.Implementation note: the array is not cloned because this is usually not needed, especially in the context of variable argument lengths since the array is often created implicitly. Furthermore, thecoordinatesfield is public, so cloning the array would not protect the state of this object anyway.Caution: if only one number is specified, make sure that the number type is double,floatorlongotherwise theGeneralDirectPosition(int)constructor would be invoked with a very different meaning. For example, for creating a one-dimensional coordinate initialized to the coordinate value 100, usenew GeneralDirectPosition(100.0), notnew GeneralDirectPosition(100), because the latter would actually create a position with 100 dimensions.- Parameters:
- coordinates- the coordinate values. This array is not cloned.
 
- 
GeneralDirectPositionConstructs a position initialized to the same values than the specified point. This is a copy constructor.- Parameters:
- point- the position to copy.
 
- 
GeneralDirectPositionConstructs 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:
 However, this constructor is lenient to other types likePOINT(6 10) POINT ZM.- Parameters:
- wkt- the- POINTor other kind of element to parse.
- Throws:
- IllegalArgumentException- if the given string cannot be parsed.
- See Also:
 
 
- 
- 
Method Details- 
getDimensionpublic final int getDimension()The length of coordinate sequence (the number of entries). This is always equals to the length of thecoordinatesarray.- Specified by:
- getDimensionin interface- DirectPosition
- Returns:
- the dimensionality of this position.
 
- 
getCoordinateReferenceSystemReturns 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 interface- DirectPosition
- Overrides:
- getCoordinateReferenceSystemin class- AbstractDirectPosition
- Returns:
- the coordinate reference system, or null.
 
- 
setCoordinateReferenceSystempublic void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws MismatchedDimensionException Sets the coordinate reference system in which the coordinate is given.- Parameters:
- crs- the new coordinate reference system, or- null.
- Throws:
- MismatchedDimensionException- if the specified CRS does not have the expected number of dimensions.
 
- 
getCoordinatepublic 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 thecoordinates, array field, which is public.- Specified by:
- getCoordinatein interface- DirectPosition
- Overrides:
- getCoordinatein class- AbstractDirectPosition
- Returns:
- a copy of the coordinatesarray.
 
- 
setCoordinateSets the coordinate values along all dimensions.- Parameters:
- coordinates- the new coordinates values, or a- nullarray for setting all coordinate values to- NaN.
- Throws:
- MismatchedDimensionException- if the length of the specified array is not equals to the dimension of this position.
 
- 
getOrdinateReturns the coordinate at the specified dimension.API note: This method is final for ensuring consistency with thecoordinates, array field, which is public.- Specified by:
- getOrdinatein interface- DirectPosition
- Parameters:
- dimension- the dimension in the range 0 to dimension-1.
- Returns:
- the coordinate at the specified dimension.
- Throws:
- IndexOutOfBoundsException- if the specified dimension is out of bounds.
 
- 
setOrdinateSets the coordinate value along the specified dimension.- Specified by:
- setOrdinatein interface- DirectPosition
- Overrides:
- setOrdinatein class- AbstractDirectPosition
- Parameters:
- dimension- the dimension for the coordinate of interest.
- value- the coordinate value of interest.
- Throws:
- IndexOutOfBoundsException- if the specified dimension is out of bounds.
 
- 
setLocationSets 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 class- AbstractDirectPosition
- Parameters:
- position- the new position for this point, or- nullfor setting all coordinate values to- NaN.
- Throws:
- MismatchedDimensionException- if the given position does not have the expected dimension.
 
- 
toStringFormats 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 withPOINT(x₀ x₁ x₂ …) Double.toString(double)(i.e. without fixed number of fraction digits). The string returned by this method can be parsed by theGeneralDirectPositionconstructor.- Overrides:
- toStringin class- AbstractDirectPosition
- Returns:
- this position as a POINTin Well Known Text (WKT) format.
 
- 
cloneReturns a deep copy of this position.
- 
hashCodepublic 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 interface- DirectPosition
- Overrides:
- hashCodein class- AbstractDirectPosition
- Returns:
- a hash code value for this position.
 
- 
equalsReturnstrueif the specified object is also aDirectPositionwith 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 differentDirectPositionimplementations in the same hash map.- Specified by:
- equalsin interface- DirectPosition
- Overrides:
- equalsin class- AbstractDirectPosition
- Parameters:
- object- the object to compare with this position.
- Returns:
- trueif the given object is equal to this position.
 
 
-