public class DirectPosition2D extends Point2D.Double implements DirectPosition, Cloneable
Point2D
.
This implementation is provided for inter-operability between Java2D and GeoAPI.
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.
Note:
The rational for avoiding axis orientation restriction is that other 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
,
Serialized FormDefined in the sis-referencing module
Point2D.Double, Point2D.Float
x, 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, setLocation
distance, distance, distance, distanceSq, distanceSq, distanceSq
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 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()
,
org.apache.sis.measure.CoordinateFormat
public final DirectPosition getDirectPosition()
this
, the direct position for this
position.getDirectPosition
in interface Position
public final int getDimension()
DirectPosition2D
objects.getDimension
in interface DirectPosition
public final CoordinateReferenceSystem getCoordinateReferenceSystem()
null
if this particular DirectPosition
is included
in a larger object with such a reference to a CRS.getCoordinateReferenceSystem
in interface DirectPosition
null
.public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
crs
- The new coordinate reference system, or null
.public final double[] getCoordinate()
Note: This method is final for ensuring consistency with thex
andy
fields, which are public.
getCoordinate
in interface DirectPosition
public final double getOrdinate(int dimension) throws IndexOutOfBoundsException
Note: This method is final for ensuring consistency with thex
andy
fields, which are public.
getOrdinate
in interface DirectPosition
dimension
- 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 DirectPosition
dimension
- 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 Point2D
position
- The new position for this point.public String toString()
The string returned by this method can be parsed by thePOINT(x y)
DirectPosition2D
constructor.toString
in class Point2D.Double
public int hashCode()
DirectPosition.hashCode()
contract, not the Point2D.hashCode()
contract.hashCode
in interface DirectPosition
hashCode
in class Point2D
public 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 DirectPosition
equals
in class Point2D
object
- The object to compare with this position.true
if the given object is equal to this position.public DirectPosition2D clone()
Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.