public class GeneralDirectPosition extends AbstractDirectPosition implements Serializable, Cloneable
DirectPosition (the coordinates of a position) of arbitrary dimension.
This particular implementation of DirectPosition is said "General" because it
uses an array of ordinates of an arbitrary length. If the direct
position is known to be always two-dimensional, then DirectPosition2D provides
a more efficient implementation.
DirectPositions, 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.DirectPosition1D,
DirectPosition2D,
CoordinateFormat,
Serialized FormDefined in the sis-referencing module
| Modifier and Type | Field and Description |
|---|---|
double[] |
ordinates
The ordinates of the direct position.
|
| Constructor and Description |
|---|
GeneralDirectPosition(CharSequence wkt)
Constructs a position initialized to the values parsed
from the given string in Well Known Text (WKT) format.
|
GeneralDirectPosition(CoordinateReferenceSystem crs)
Constructs a position using the specified coordinate reference system.
|
GeneralDirectPosition(DirectPosition point)
Constructs a position initialized to the same values than the specified point.
|
GeneralDirectPosition(double... ordinates)
Constructs a position with the specified ordinates.
|
GeneralDirectPosition(int dimension)
Constructs a position with the specified number of dimensions.
|
| Modifier and Type | Method and Description |
|---|---|
GeneralDirectPosition |
clone()
Returns a deep copy of this position.
|
double[] |
getCoordinate()
Returns a sequence of numbers that hold the coordinate of this position in its reference system.
|
CoordinateReferenceSystem |
getCoordinateReferenceSystem()
Returns the coordinate reference system in which the coordinate is given.
|
int |
getDimension()
The length of ordinate sequence (the number of entries).
|
double |
getOrdinate(int dimension)
Returns the ordinate at the specified dimension.
|
int |
hashCode()
Returns a hash value for this coordinate.
|
void |
setCoordinate(double... ordinates)
Sets the ordinate values along all dimensions.
|
void |
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate is given.
|
void |
setLocation(DirectPosition position)
Sets this coordinate to the specified direct position.
|
void |
setOrdinate(int dimension,
double value)
Sets the ordinate value along the specified dimension.
|
String |
toString()
Formats this position in the Well Known Text (WKT) format.
|
equals, getDirectPosition, normalizepublic final double[] ordinates
public GeneralDirectPosition(CoordinateReferenceSystem crs)
crs - the coordinate reference system to be given to this position.public GeneralDirectPosition(int dimension)
throws NegativeArraySizeException
dimension - number of dimensions.NegativeArraySizeException - if dimension is negative.public GeneralDirectPosition(double... ordinates)
ordinates field.
Consequently, callers shall not recycle the same array for creating many instances.
ordinates
field 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,
float or long otherwise the GeneralDirectPosition(int) constructor would be
invoked with a very different meaning. For example for creating a one-dimensional coordinate initialized
to the ordinate value 100, use new GeneralDirectPosition(100.0), not
new GeneralDirectPosition(100), because the later would actually create a position with 100 dimensions.
ordinates - the ordinate values. This array is not cloned.public GeneralDirectPosition(DirectPosition point)
point - the position to copy.public GeneralDirectPosition(CharSequence wkt) throws IllegalArgumentException
POINT element like below:
POINT(6 10)However this constructor is lenient to other types like
POINT ZM.wkt - the POINT or other kind of element to parse.IllegalArgumentException - if the given string can not be parsed.toString(),
CoordinateFormatpublic final int getDimension()
ordinates array.getDimension in interface DirectPositionpublic final CoordinateReferenceSystem getCoordinateReferenceSystem()
null if this particular DirectPosition is included
in a larger object with such a reference to a CRS.getCoordinateReferenceSystem in interface DirectPositionnull.public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws MismatchedDimensionException
crs - the new coordinate reference system, or null.MismatchedDimensionException - if the specified CRS does not have the expected number of dimensions.public final double[] getCoordinate()
ordinates, array field, which is public.getCoordinate in interface DirectPositiongetCoordinate in class AbstractDirectPositionpublic void setCoordinate(double... ordinates)
throws MismatchedDimensionException
ordinates - the new ordinates values, or a null array for
setting all ordinate values to NaN.MismatchedDimensionException - if the length of the specified array is not
equals to the dimension of this position.public final double getOrdinate(int dimension)
throws IndexOutOfBoundsException
ordinates, array field, which is public.getOrdinate in interface DirectPositiondimension - the dimension in the range 0 to dimension-1.IndexOutOfBoundsException - if the specified dimension is out of bounds.public void setOrdinate(int dimension,
double value)
throws IndexOutOfBoundsException
setOrdinate in interface DirectPositiondimension - the dimension for the ordinate of interest.value - the ordinate value of interest.IndexOutOfBoundsException - if the specified dimension is out of bounds.public void setLocation(DirectPosition position) throws MismatchedDimensionException
setLocation in class AbstractDirectPositionposition - the new position for this point,
or null for setting all ordinate values to NaN.MismatchedDimensionException - if the given position does not have the expected dimension.public String toString()
x₀, x₁, x₂, etc.
are the ordinate values at index 0, 1, 2, etc.:
POINT(x₀ x₁ x₂ …)The string returned by this method can be parsed by the
GeneralDirectPosition constructor.toString in class AbstractDirectPositionPOINT in Well Known Text (WKT) format.public GeneralDirectPosition clone()
public int hashCode()
DirectPosition.hashCode() javadoc.
Consequently, it should be possible to mix different DirectPosition
implementations in the same hash map.hashCode in interface DirectPositionhashCode in class AbstractDirectPositionCopyright © 2010–2017 The Apache Software Foundation. All rights reserved.