|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectPoint2D
Point2D.Double
DirectPosition2D
public class DirectPosition2D
Holds the coordinates for a two-dimensional position within some coordinate reference system. This class inherits x and y fields. But despite their names, they don't need to be oriented toward East and North. The (x,y) axis can have any orientation 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.
The rational for avoiding axis orientation restriction is that other DirectPosition
implementation 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.
Caution when used in collections
Do not mix instances of this class with ordinary Point2D instances in a
HashSet or as HashMap keys. It is not possible to
meet both Point2D.hashCode() and DirectPosition.hashCode() contract, and this class
chooses to implements the later. Consequently, hashCode() is inconsistent with
Point2D.equals(java.lang.Object) but is consistent with DirectPosition.equals(java.lang.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 Object.hashCode(), like ArrayList,
are safe in all cases.
DirectPosition1D,
GeneralDirectPosition,
Point2D,
Serialized Form
| referencing/geotk-referencing (download) | View source code for this class |
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class Point2D |
|---|
Point2D.Double, Point2D.Float |
| Field Summary |
|---|
| Fields inherited from class Point2D.Double |
|---|
x, y |
| Constructor Summary | |
|---|---|
DirectPosition2D()
Constructs a position initialized to (0,0) with a null coordinate reference system. |
|
DirectPosition2D(CoordinateReferenceSystem crs)
Constructs a position 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 point)
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. |
|
DirectPosition2D(Point2D point)
Constructs a position from the specified Point2D. |
|
DirectPosition2D(String wkt)
Constructs a position initialized to the values parsed from the given string in Well Known Text (WKT) format. |
|
| Method Summary | |
|---|---|
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(DirectPosition position)
Sets this coordinate to the specified direct position. |
void |
setOrdinate(int dimension,
double value)
Sets the ordinate value along the specified dimension. |
Point2D |
toPoint2D()
Returns a Point2D with the same coordinate as this direct position. |
String |
toString()
Formats this position in the Well Known Text (WKT) format. |
| Methods inherited from class Point2D.Double |
|---|
getX, getY, setLocation |
| Methods inherited from class Point2D |
|---|
distance, distance, distance, distanceSq, distanceSq, distanceSq, setLocation |
| Methods inherited from class Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DirectPosition2D()
null coordinate reference system.
public DirectPosition2D(CoordinateReferenceSystem crs)
crs - The coordinate reference system, or null.
public DirectPosition2D(double x,
double y)
x - The x value.y - The y value.
public DirectPosition2D(CoordinateReferenceSystem crs,
double x,
double y)
crs - The coordinate reference system, or null.x - The x value.y - The y value.public DirectPosition2D(Point2D point)
Point2D.
point - The point to copy.public DirectPosition2D(DirectPosition point)
point - The point to copy.
public DirectPosition2D(String wkt)
throws NumberFormatException,
IllegalArgumentException
POINT
element like below:
POINT(6 10)
wkt - The POINT or other kind of element to parse.
NumberFormatException - If a number can not be parsed.
IllegalArgumentException - If the parenthesis are not balanced.
MismatchedDimensionException - If the given point is not two-dimensional.AbstractDirectPosition.toString(DirectPosition),
CoordinateFormat| Method Detail |
|---|
public DirectPosition getDirectPosition()
this, the direct position for this
position.
getDirectPosition in interface Positionpublic 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 int getDimension()
DirectPosition2D objects.
getDimension in interface DirectPositionpublic double[] getCoordinate()
getCoordinate in interface DirectPosition
public final double getOrdinate(int dimension)
throws IndexOutOfBoundsException
getOrdinate in interface DirectPositiondimension - The dimension in the range 0 to 1 inclusive.
IndexOutOfBoundsException - if the specified dimension is out of bounds.
public final 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
position - The new position for this point.
MismatchedDimensionException - if this point doesn't have the expected dimension.public Point2D toPoint2D()
Point2D with the same coordinate as this direct position.
public String toString()
The output of this method can be parsed by thePOINT(ordinates)
GeneralDirectPosition 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 its
DirectPosition.equals(java.lang.Object) contract. Otherwise the comparison is performed as specified
in Point2D.equals(java.lang.Object).
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()
clone in class Point2D
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||