public class DirectPosition2D extends Point2D.Double implements DirectPosition, Cloneable
This class inherits x and y fields. But despite their names, they don't need to be oriented toward East and North respectively. The (x,y) axis can have any direction and should be understood as ordinate 0 and ordinate 1 values instead. This is not specific to this implementation; in Java2D too, the visual axis orientation depend on the affine transform in the graphics context.
DirectPosition implementations
do not have such restriction, and it would be hard to generalize. For example there is no clear "x" or "y"
classification for North-East direction.Point2D instances
in a HashSet or as HashMap keys.
It is not possible to meet both Point2D.hashCode() and DirectPosition.hashCode()
contracts, and this class chooses to implements the later. Consequently, the hashCode()
method of this class is inconsistent with Point2D.equals(Object) but is consistent with
DirectPosition.equals(Object).
In other words, it is safe to add instances of DirectPosition2D in a
HashSet<DirectPosition>, but it is unsafe to add them in a HashSet<Point2D>.
Collections that do not rely on hash codes, like ArrayList, are safe in all cases.
DirectPosition1D,
GeneralDirectPosition,
Point2D,
CoordinateFormat,
Serialized FormDefined in the sis-referencing module
Point2D.Double, Point2D.Floatx, y| Constructor and Description |
|---|
DirectPosition2D()
Constructs a position initialized to (0,0) with a
null coordinate reference system. |
DirectPosition2D(CharSequence wkt)
Constructs a position initialized to the values parsed from the given string in
Well Known Text (WKT) format.
|
DirectPosition2D(CoordinateReferenceSystem crs)
Constructs a position initialized to (0,0) with the specified coordinate reference system.
|
DirectPosition2D(CoordinateReferenceSystem crs,
double x,
double y)
Constructs a 2D position from the specified ordinates in the specified CRS.
|
DirectPosition2D(DirectPosition position)
Constructs a position initialized to the same values than the specified point.
|
DirectPosition2D(double x,
double y)
Constructs a 2D position from the specified ordinates.
|
| Modifier and Type | Method and Description |
|---|---|
DirectPosition2D |
clone()
Returns a clone of this point.
|
boolean |
equals(Object object)
Compares this point with the specified object for equality.
|
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 coordinate sequence (the number of entries).
|
DirectPosition |
getDirectPosition()
Returns always
this, the direct position for this
position. |
double |
getOrdinate(int dimension)
Returns the ordinate at the specified dimension.
|
int |
hashCode()
Returns a hash value for this coordinate.
|
void |
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate is given.
|
void |
setLocation(Point2D position)
Sets this coordinate to the specified point.
|
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.
|
getX, getY, setLocationdistance, distance, distance, distanceSq, distanceSq, distanceSqpublic DirectPosition2D()
null coordinate reference system.public DirectPosition2D(CoordinateReferenceSystem crs)
crs - the coordinate reference system, or null.public DirectPosition2D(double x,
double y)
x - the first ordinate value (not necessarily horizontal).y - the second ordinate value (not necessarily vertical).public DirectPosition2D(CoordinateReferenceSystem crs, double x, double y)
crs - the coordinate reference system, or null.x - the first ordinate value (not necessarily horizontal).y - the second ordinate value (not necessarily vertical).public DirectPosition2D(DirectPosition position) throws MismatchedDimensionException
position - the position to copy.MismatchedDimensionException - if the given position is not two-dimensional.setLocation(Point2D)public DirectPosition2D(CharSequence wkt) throws IllegalArgumentException
POINT
element like below:
POINT(6 10)
wkt - the POINT or other kind of element to parse.IllegalArgumentException - if the given string can not be parsed.MismatchedDimensionException - if the given point is not two-dimensional.toString(),
CoordinateFormatpublic final DirectPosition getDirectPosition()
this, the direct position for this
position.getDirectPosition in interface Positionpublic final int getDimension()
DirectPosition2D objects.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)
crs - the new coordinate reference system, or null.public final double[] getCoordinate()
x and y fields, which are public.getCoordinate in interface DirectPositionpublic final double getOrdinate(int dimension)
throws IndexOutOfBoundsException
x and y fields, which are public.getOrdinate in interface DirectPositiondimension - the dimension in the range 0 to 1 inclusive.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(Point2D position)
DirectPosition containing a non-null coordinate reference system (CRS),
then the CRS for this position will be set to the CRS of the given point.setLocation in class Point2Dposition - the new position for this point.public String toString()
POINT(x y)The string returned by this method can be parsed by the
DirectPosition2D constructor.toString in class Point2D.Doublepublic int hashCode()
DirectPosition.hashCode() contract, not the Point2D.hashCode() contract.hashCode in interface DirectPositionhashCode in class Point2Dpublic boolean equals(Object object)
DirectPosition interface, then the comparison is performed as specified in the
DirectPosition.equals(Object) contract. Otherwise the comparison is performed as
specified in the Point2D.equals(Object) contract.equals in interface DirectPositionequals in class Point2Dobject - the object to compare with this position.true if the given object is equal to this position.public DirectPosition2D clone()
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.