Package org.locationtech.jts.geom
Class Coordinate
java.lang.Object
org.locationtech.jts.geom.Coordinate
- All Implemented Interfaces:
Serializable,Cloneable,Comparable
- Direct Known Subclasses:
ExtendedCoordinate
A lightweight class used to store coordinates
on the 2-dimensional Cartesian plane.
It is distinct from
Point, which is a subclass of Geometry.
Unlike objects of type Point (which contain additional
information such as an envelope, a precision model, and spatial reference
system information), a Coordinate only contains ordinate values
and accessor methods.
Coordinates are two-dimensional points, with an additional Z-ordinate.
If an Z-ordinate value is not specified or not defined,
constructed coordinates have a Z-ordinate of NaN
(which is also the value of NULL_ORDINATE).
The standard comparison functions ignore the Z-ordinate.
Apart from the basic accessor functions, JTS supports
only specific operations involving the Z-ordinate.
- Version:
- 1.7
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCompares twoCoordinates, allowing for either a 2-dimensional or 3-dimensional comparison, and handling NaN values correctly. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe value used to indicate a null or missing ordinate value.private static final longdoubleThe x-coordinate.static final intStandard ordinate index valuesdoubleThe y-coordinate.static final intdoubleThe z-coordinate.static final int -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aCoordinateat (0,0,NaN).Coordinate(double x, double y) Constructs aCoordinateat (x,y,NaN).Coordinate(double x, double y, double z) Constructs aCoordinateat (x,y,z).Constructs aCoordinatehaving the same (x,y,z) values asother. -
Method Summary
Modifier and TypeMethodDescriptionclone()intCompares thisCoordinatewith the specifiedCoordinatefor order.copy()doubleComputes the 2-dimensional Euclidean distance to another location.doubleComputes the 3-dimensional Euclidean distance to another location.booleanequalInZ(Coordinate c, double tolerance) Tests if another coordinate has the same value for Z, within a tolerance.booleanReturnstrueifotherhas the same values for the x and y ordinates.booleanequals2D(Coordinate other) Returns whether the planar projections of the twoCoordinates are equal.booleanequals2D(Coordinate c, double tolerance) Tests if another coordinate has the same values for the X and Y ordinates.booleanequals3D(Coordinate other) Tests if another coordinate has the same values for the X, Y and Z ordinates.doublegetOrdinate(int ordinateIndex) Gets the ordinate value for the given index.inthashCode()Gets a hashcode for this coordinate.static inthashCode(double x) Computes a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"voidsetCoordinate(Coordinate other) Sets thisCoordinates (x,y,z) values to that ofother.voidsetOrdinate(int ordinateIndex, double value) Sets the ordinate for the given index to a given value.toString()Returns aStringof the form (x,y,z) .
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
NULL_ORDINATE
public static final double NULL_ORDINATEThe value used to indicate a null or missing ordinate value. In particular, used for the value of ordinates for dimensions greater than the defined dimension of a coordinate.- See Also:
-
X
public static final int XStandard ordinate index values- See Also:
-
Y
public static final int Y- See Also:
-
Z
public static final int Z- See Also:
-
x
public double xThe x-coordinate. -
y
public double yThe y-coordinate. -
z
public double zThe z-coordinate.
-
-
Constructor Details
-
Coordinate
public Coordinate(double x, double y, double z) Constructs aCoordinateat (x,y,z).- Parameters:
x- the x-valuey- the y-valuez- the z-value
-
Coordinate
public Coordinate()Constructs aCoordinateat (0,0,NaN). -
Coordinate
Constructs aCoordinatehaving the same (x,y,z) values asother.- Parameters:
c- theCoordinateto copy.
-
Coordinate
public Coordinate(double x, double y) Constructs aCoordinateat (x,y,NaN).- Parameters:
x- the x-valuey- the y-value
-
-
Method Details
-
setCoordinate
Sets thisCoordinates (x,y,z) values to that ofother.- Parameters:
other- theCoordinateto copy
-
getOrdinate
public double getOrdinate(int ordinateIndex) - Parameters:
ordinateIndex- the ordinate index- Returns:
- the value of the ordinate
- Throws:
IllegalArgumentException- if the index is not valid
-
setOrdinate
public void setOrdinate(int ordinateIndex, double value) Sets the ordinate for the given index to a given value. The supported values for the index areX,Y, andZ.- Parameters:
ordinateIndex- the ordinate indexvalue- the value to set- Throws:
IllegalArgumentException- if the index is not valid
-
equals2D
Returns whether the planar projections of the twoCoordinates are equal.- Parameters:
other- aCoordinatewith which to do the 2D comparison.- Returns:
trueif the x- and y-coordinates are equal; the z-coordinates do not have to be equal.
-
equals2D
Tests if another coordinate has the same values for the X and Y ordinates. The Z ordinate is ignored.- Parameters:
c- aCoordinatewith which to do the 2D comparison.- Returns:
- true if
otheris aCoordinatewith the same values for X and Y.
-
equals3D
Tests if another coordinate has the same values for the X, Y and Z ordinates.- Parameters:
other- aCoordinatewith which to do the 3D comparison.- Returns:
- true if
otheris aCoordinatewith the same values for X, Y and Z.
-
equalInZ
Tests if another coordinate has the same value for Z, within a tolerance.- Parameters:
c- a coordinatetolerance- the tolerance value- Returns:
- true if the Z ordinates are within the given tolerance
-
equals
Returnstrueifotherhas the same values for the x and y ordinates. Since Coordinates are 2.5D, this routine ignores the z value when making the comparison. -
compareTo
Compares thisCoordinatewith the specifiedCoordinatefor order. This method ignores the z value when making the comparison. Returns:- -1 : this.x < other.x || ((this.x == other.x) && (this.y < other.y))
- 0 : this.x == other.x && this.y = other.y
- 1 : this.x > other.x || ((this.x == other.x) && (this.y > other.y))
- Specified by:
compareToin interfaceComparable- Parameters:
o- theCoordinatewith which thisCoordinateis being compared- Returns:
- -1, zero, or 1 as this
Coordinateis less than, equal to, or greater than the specifiedCoordinate
-
toString
Returns aStringof the form (x,y,z) . -
clone
-
copy
-
distance
Computes the 2-dimensional Euclidean distance to another location. The Z-ordinate is ignored.- Parameters:
c- a point- Returns:
- the 2-dimensional Euclidean distance between the locations
-
distance3D
Computes the 3-dimensional Euclidean distance to another location.- Parameters:
c- a coordinate- Returns:
- the 3-dimensional Euclidean distance between the locations
-
hashCode
public int hashCode()Gets a hashcode for this coordinate. -
hashCode
public static int hashCode(double x) Computes a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"- Returns:
- a hashcode for the double value
-