Package org.geotools.geometry
Class GeneralPosition
Object
AbstractPosition
GeneralPosition
- All Implemented Interfaces:
Serializable,Cloneable,Position,Cloneable
- Direct Known Subclasses:
TransformedPosition
Holds the coordinates for a position within some coordinate reference system. Since
DirectPositions, as data
types, will often be included in larger objects (such as geometries) that
have references to CoordinateReferenceSystem, the getCoordinateReferenceSystem() method may returns
null if this particular DirectPosition is included in a larger object with such a reference to a
coordinate reference system. In this case, the cordinate reference system is
implicitly assumed to take on the value of the containing object's CoordinateReferenceSystem.
This particular implementation of DirectPosition is said "General" because it uses an
array of ordinates of an arbitrary length. If the direct position is know to be always
two-dimensional, then Position2D may provides a more efficient implementation.
Most methods in this implementation are final for performance reason.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGeneralPosition(double[] ordinates) Constructs a position with the specified ordinates.GeneralPosition(double x, double y) Constructs a 2D position from the specified ordinates.GeneralPosition(double x, double y, double z) Constructs a 3D position from the specified ordinates.GeneralPosition(int numDim) Constructs a position with the specified number of dimensions.GeneralPosition(Point2D point) Constructs a position from the specifiedPoint2D.GeneralPosition(Position point) Constructs a position initialized to the same values than the specified point.Constructs a position using the specified coordinate reference system. -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a deep copy of this position.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 ordinate at the specified dimension.inthashCode()Returns a hash value for this coordinate.voidSet the coordinate reference system in which the coordinate is given.final voidsetLocation(Point2D point) Set this coordinate to the specifiedPoint2D.final voidsetLocation(Position position) Set this coordinate to the specified direct position.final voidsetLocation(GeneralPosition position) Set this coordinate to the specified direct position.final voidsetOrdinate(int dimension, double value) Sets the ordinate value along the specified dimension.Returns aPoint2Dwith the same coordinate as this direct position.Methods inherited from class AbstractPosition
checkCoordinateReferenceSystemDimension, equals, getDirectPosition, setPosition, toString
-
Field Details
-
ordinates
public final double[] ordinatesThe ordinates of the direct position.
-
-
Constructor Details
-
GeneralPosition
Constructs a position using the specified coordinate reference system. The number of dimensions is inferred from the coordinate reference system.- Parameters:
crs- The coordinate reference system to be given to this position.- Since:
- 2.2
-
GeneralPosition
Constructs a position with the specified number of dimensions.- Parameters:
numDim- Number of dimensions.- Throws:
NegativeArraySizeException- ifnumDimis negative.
-
GeneralPosition
public GeneralPosition(double[] ordinates) Constructs a position with the specified ordinates. Theordinatesarray will be copied.- Parameters:
ordinates- The ordinate values to copy.
-
GeneralPosition
public GeneralPosition(double x, double y) Constructs a 2D position from the specified ordinates. Despite their name, the (x,y) coordinates don't need to be oriented toward (East, North). See thePosition2Djavadoc for details.- Parameters:
x- The first ordinate value.y- The second ordinate value.
-
GeneralPosition
public GeneralPosition(double x, double y, double z) Constructs a 3D position from the specified ordinates. Despite their name, the (x,y,z) coordinates don't need to be oriented toward (East, North, Up).- Parameters:
x- The first ordinate value.y- The second ordinate value.z- The third ordinate value.
-
GeneralPosition
Constructs a position from the specifiedPoint2D.- Parameters:
point- The position to copy.
-
GeneralPosition
Constructs a position initialized to the same values than the specified point.- Parameters:
point- The position to copy.- Since:
- 2.2
-
-
Method Details
-
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 coordinate reference system.- Specified by:
getCoordinateReferenceSystemin interfacePosition- Returns:
- The coordinate reference system, or
null.
-
setCoordinateReferenceSystem
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws MismatchedDimensionException Set the coordinate reference system in which the coordinate is given.- Parameters:
crs- The new coordinate reference system, ornull.- Throws:
MismatchedDimensionException- if the specified CRS doesn't have the expected number of dimensions.
-
getDimension
public final int getDimension()The length of coordinate sequence (the number of entries). This may be less than or equal to the dimensionality of the coordinate reference system.- Specified by:
getDimensionin interfacePosition- Returns:
- The dimensionality of this position.
-
getCoordinate
public final double[] getCoordinate()Returns a sequence of numbers that hold the coordinate of this position in its reference system.- Specified by:
getCoordinatein interfacePosition- Overrides:
getCoordinatein classAbstractPosition- Returns:
- A copy of the coordinates.
-
getOrdinate
Returns the ordinate at the specified dimension.- Specified by:
getOrdinatein interfacePosition- 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.
-
setOrdinate
Sets the ordinate value along the specified dimension.- Specified by:
setOrdinatein interfacePosition- Parameters:
dimension- the dimension for the ordinate of interest.value- the ordinate value of interest.- Throws:
IndexOutOfBoundsException- if the specified dimension is out of bounds.
-
setLocation
Set this coordinate to the specified direct position. If the specified position contains a coordinate reference system, then the CRS for this position will be set to the CRS of the specified position.- Parameters:
position- The new position for this point.- Throws:
MismatchedDimensionException- if this point doesn't have the expected dimension.- Since:
- 2.2
-
setLocation
Set this coordinate to the specified direct position. This method is identical tosetLocation(Position), but is slightly faster in the special case of anGeneralDirectPositionimplementation.- Parameters:
position- The new position for this point.- Throws:
MismatchedDimensionException- if this point doesn't have the expected dimension.
-
setLocation
Set this coordinate to the specifiedPoint2D. This coordinate must be two-dimensional.- Parameters:
point- The new coordinate for this point.- Throws:
MismatchedDimensionException- if this coordinate point is not two-dimensional.
-
toPoint2D
Returns aPoint2Dwith the same coordinate as this direct position. This is a convenience method for interoperability with Java2D.- Returns:
- This position as a two-dimensional point.
- Throws:
IllegalStateException- if this coordinate point is not two-dimensional.
-
hashCode
public int hashCode()Returns a hash value for this coordinate.- Specified by:
hashCodein interfacePosition- Overrides:
hashCodein classAbstractPosition- Returns:
- A hash code value for this position.
-
clone
Returns a deep copy of this position.
-