public class Coordinate extends Object implements Comparable<Coordinate>, Cloneable, Serializable
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.
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 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.
Implementations may optionally support Z-ordinate and M-measure values
as appropriate for a CoordinateSequence
.
Use of getZ()
and getM()
accessors, or getOrdinate(int)
are recommended.
Modifier and Type | Class and Description |
---|---|
static class |
Coordinate.DimensionalComparator
Compares two
Coordinate s, allowing for either a 2-dimensional
or 3-dimensional comparison, and handling NaN values correctly. |
Modifier and Type | Field and Description |
---|---|
static int |
M
Standard ordinate index value for, where M is 3.
|
static double |
NULL_ORDINATE
The value used to indicate a null or missing ordinate value.
|
double |
x
The x-ordinate.
|
static int |
X
Standard ordinate index value for, where X is 0
|
double |
y
The y-ordinate.
|
static int |
Y
Standard ordinate index value for, where Y is 1
|
double |
z
The z-ordinate.
|
static int |
Z
Standard ordinate index value for, where Z is 2.
|
Constructor and Description |
---|
Coordinate()
Constructs a
Coordinate at (0,0,NaN). |
Coordinate(Coordinate c)
Constructs a
Coordinate having the same (x,y,z) values as
other . |
Coordinate(double x,
double y)
Constructs a
Coordinate at (x,y,NaN). |
Coordinate(double x,
double y,
double z)
Constructs a
Coordinate at (x,y,z). |
Modifier and Type | Method and Description |
---|---|
Object |
clone() |
int |
compareTo(Coordinate o)
Compares this
Coordinate with the specified Coordinate for order. |
Coordinate |
copy()
Creates a copy of this Coordinate.
|
Coordinate |
create()
Create a new Coordinate of the same type as this Coordinate, but with no values.
|
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(Object other)
Returns
true if other has the same values for
the x and y ordinates. |
boolean |
equals2D(Coordinate other)
Returns whether the planar projections of the two
Coordinate s
are equal. |
boolean |
equals2D(Coordinate c,
double tolerance)
Tests if another Coordinate has the same values for the X and Y ordinates,
within a specified tolerance value.
|
boolean |
equals3D(Coordinate other)
Tests if another coordinate has the same values for the X, Y and Z ordinates.
|
double |
getM()
Retrieves the value of the measure, if present.
|
double |
getOrdinate(int ordinateIndex)
Gets the ordinate value for the given index.
|
double |
getX()
Retrieves the value of the X ordinate.
|
double |
getY()
Retrieves the value of the Y ordinate.
|
double |
getZ()
Retrieves the value of the Z ordinate, if present.
|
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"
|
boolean |
isValid()
Tests if the coordinate has valid X and Y ordinate values.
|
void |
setCoordinate(Coordinate other)
Sets this
Coordinate s (x,y,z) values to that of other . |
void |
setM(double m)
Sets the measure value, if supported.
|
void |
setOrdinate(int ordinateIndex,
double value)
Sets the ordinate for the given index
to a given value.
|
void |
setX(double x)
Sets the X ordinate value.
|
void |
setY(double y)
Sets the Y ordinate value.
|
void |
setZ(double z)
Sets the Z ordinate value.
|
String |
toString()
Returns a
String of the form (x,y,z) . |
public static final double NULL_ORDINATE
public static final int X
public static final int Y
public static final int Z
This constant assumes XYZM coordinate sequence definition, please check this assumption
using CoordinateSequence.getDimension()
and CoordinateSequence.getMeasures()
before use.
public static final int M
This constant assumes XYZM coordinate sequence definition, please check this assumption
using CoordinateSequence.getDimension()
and CoordinateSequence.getMeasures()
before use.
public double x
public double y
public double z
Direct access to this field is discouraged; use getZ()
.
public Coordinate(double x, double y, double z)
Coordinate
at (x,y,z).x
- the x-ordinatey
- the y-ordinatez
- the z-ordinatepublic Coordinate()
Coordinate
at (0,0,NaN).public Coordinate(Coordinate c)
Coordinate
having the same (x,y,z) values as
other
.c
- the Coordinate
to copy.public Coordinate(double x, double y)
Coordinate
at (x,y,NaN).x
- the x-valuey
- the y-valuepublic void setCoordinate(Coordinate other)
Coordinate
s (x,y,z) values to that of other
.other
- the Coordinate
to copypublic double getX()
public void setX(double x)
x
- the value to set as Xpublic double getY()
public void setY(double y)
y
- the value to set as Ypublic double getZ()
public void setZ(double z)
z
- the value to set as Zpublic double getM()
public void setM(double m)
m
- the value to set as Mpublic double getOrdinate(int ordinateIndex)
X
, Y
, and Z
.ordinateIndex
- the ordinate indexIllegalArgumentException
- if the index is not validpublic void setOrdinate(int ordinateIndex, double value)
X
, Y
, and Z
.ordinateIndex
- the ordinate indexvalue
- the value to setIllegalArgumentException
- if the index is not validpublic boolean isValid()
Double.isFinite(double)
public boolean equals2D(Coordinate other)
Coordinate
s
are equal.other
- a Coordinate
with which to do the 2D comparison.true
if the x- and y-coordinates are equal; the
z-coordinates do not have to be equal.public boolean equals2D(Coordinate c, double tolerance)
c
- a Coordinate
with which to do the 2D comparison.tolerance
- the tolerance value to useother
is a Coordinate
with the same values for X and Y.public boolean equals3D(Coordinate other)
other
- a Coordinate
with which to do the 3D comparison.other
is a Coordinate
with the same values for X, Y and Z.public boolean equalInZ(Coordinate c, double tolerance)
c
- a coordinatetolerance
- the tolerance valuepublic boolean equals(Object other)
true
if other
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.public int compareTo(Coordinate o)
Coordinate
with the specified Coordinate
for order.
This method ignores the z value when making the comparison.
Returns:
compareTo
in interface Comparable<Coordinate>
o
- the Coordinate
with which this Coordinate
is being comparedCoordinate
is less than, equal to, or greater than the specified Coordinate
public String toString()
String
of the form (x,y,z) .public Coordinate copy()
public Coordinate create()
public double distance(Coordinate c)
c
- a pointpublic double distance3D(Coordinate c)
c
- a coordinatepublic int hashCode()
public static int hashCode(double x)
x
- the value to compute forCopyright © 2022. All rights reserved.