Package org.locationtech.jts.geom
Class Coordinate
- java.lang.Object
-
- org.locationtech.jts.geom.Coordinate
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable
- Direct Known Subclasses:
ExtendedCoordinate
public class Coordinate extends java.lang.Object implements java.lang.Comparable, java.lang.Cloneable, java.io.Serializable
A lightweight class used to store coordinates on the 2-dimensional Cartesian plane. It is distinct fromPoint
, which is a subclass ofGeometry
. Unlike objects of typePoint
(which contain additional information such as an envelope, a precision model, and spatial reference system information), aCoordinate
only contains ordinate values and accessor methods.Coordinate
s 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 ofNaN
(which is also the value ofNULL_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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Coordinate.DimensionalComparator
Compares twoCoordinate
s, allowing for either a 2-dimensional or 3-dimensional comparison, and handling NaN values correctly.
-
Field Summary
Fields Modifier and Type Field Description static double
NULL_ORDINATE
The value used to indicate a null or missing ordinate value.private static long
serialVersionUID
double
x
The x-coordinate.static int
X
Standard ordinate index valuesdouble
y
The y-coordinate.static int
Y
double
z
The z-coordinate.static int
Z
-
Constructor Summary
Constructors Constructor Description Coordinate()
Constructs aCoordinate
at (0,0,NaN).Coordinate(double x, double y)
Constructs aCoordinate
at (x,y,NaN).Coordinate(double x, double y, double z)
Constructs aCoordinate
at (x,y,z).Coordinate(Coordinate c)
Constructs aCoordinate
having the same (x,y,z) values asother
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
int
compareTo(java.lang.Object o)
Compares thisCoordinate
with the specifiedCoordinate
for order.Coordinate
copy()
double
distance(Coordinate c)
Computes the 2-dimensional Euclidean distance to another location.double
distance3D(Coordinate c)
Computes the 3-dimensional Euclidean distance to another location.boolean
equalInZ(Coordinate c, double tolerance)
Tests if another coordinate has the same value for Z, within a tolerance.boolean
equals(java.lang.Object other)
Returnstrue
ifother
has the same values for the x and y ordinates.boolean
equals2D(Coordinate other)
Returns whether the planar projections of the twoCoordinate
s are equal.boolean
equals2D(Coordinate c, double tolerance)
Tests if another coordinate has the same values for the X and Y ordinates.boolean
equals3D(Coordinate other)
Tests if another coordinate has the same values for the X, Y and Z ordinates.double
getOrdinate(int ordinateIndex)
Gets the ordinate value for the given index.int
hashCode()
Gets a hashcode for this coordinate.static int
hashCode(double x)
Computes a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"void
setCoordinate(Coordinate other)
Sets thisCoordinate
s (x,y,z) values to that ofother
.void
setOrdinate(int ordinateIndex, double value)
Sets the ordinate for the given index to a given value.java.lang.String
toString()
Returns aString
of the form (x,y,z) .
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
NULL_ORDINATE
public static final double NULL_ORDINATE
The 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:
- Constant Field Values
-
X
public static final int X
Standard ordinate index values- See Also:
- Constant Field Values
-
Y
public static final int Y
- See Also:
- Constant Field Values
-
Z
public static final int Z
- See Also:
- Constant Field Values
-
x
public double x
The x-coordinate.
-
y
public double y
The y-coordinate.
-
z
public double z
The z-coordinate.
-
-
Constructor Detail
-
Coordinate
public Coordinate(double x, double y, double z)
Constructs aCoordinate
at (x,y,z).- Parameters:
x
- the x-valuey
- the y-valuez
- the z-value
-
Coordinate
public Coordinate()
Constructs aCoordinate
at (0,0,NaN).
-
Coordinate
public Coordinate(Coordinate c)
Constructs aCoordinate
having the same (x,y,z) values asother
.- Parameters:
c
- theCoordinate
to copy.
-
Coordinate
public Coordinate(double x, double y)
Constructs aCoordinate
at (x,y,NaN).- Parameters:
x
- the x-valuey
- the y-value
-
-
Method Detail
-
setCoordinate
public void setCoordinate(Coordinate other)
Sets thisCoordinate
s (x,y,z) values to that ofother
.- Parameters:
other
- theCoordinate
to copy
-
getOrdinate
public double getOrdinate(int ordinateIndex)
- Parameters:
ordinateIndex
- the ordinate index- Returns:
- the value of the ordinate
- Throws:
java.lang.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:
java.lang.IllegalArgumentException
- if the index is not valid
-
equals2D
public boolean equals2D(Coordinate other)
Returns whether the planar projections of the twoCoordinate
s are equal.- Parameters:
other
- aCoordinate
with which to do the 2D comparison.- Returns:
true
if the x- and y-coordinates are equal; the z-coordinates do not have to be equal.
-
equals2D
public boolean equals2D(Coordinate c, double tolerance)
Tests if another coordinate has the same values for the X and Y ordinates. The Z ordinate is ignored.- Parameters:
c
- aCoordinate
with which to do the 2D comparison.- Returns:
- true if
other
is aCoordinate
with the same values for X and Y.
-
equals3D
public boolean equals3D(Coordinate other)
Tests if another coordinate has the same values for the X, Y and Z ordinates.- Parameters:
other
- aCoordinate
with which to do the 3D comparison.- Returns:
- true if
other
is aCoordinate
with the same values for X, Y and Z.
-
equalInZ
public boolean equalInZ(Coordinate c, double tolerance)
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
public boolean equals(java.lang.Object other)
Returnstrue
ifother
has the same values for the x and y ordinates. Since Coordinates are 2.5D, this routine ignores the z value when making the comparison.- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- aCoordinate
with which to do the comparison.- Returns:
true
ifother
is aCoordinate
with the same values for the x and y ordinates.
-
compareTo
public int compareTo(java.lang.Object o)
Compares thisCoordinate
with the specifiedCoordinate
for 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:
compareTo
in interfacejava.lang.Comparable
- Parameters:
o
- theCoordinate
with which thisCoordinate
is being compared- Returns:
- -1, zero, or 1 as this
Coordinate
is less than, equal to, or greater than the specifiedCoordinate
-
toString
public java.lang.String toString()
Returns aString
of the form (x,y,z) .- Overrides:
toString
in classjava.lang.Object
- Returns:
- a
String
of the form (x,y,z)
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
copy
public Coordinate copy()
-
distance
public double distance(Coordinate c)
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
public double distance3D(Coordinate c)
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.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- 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
-
-