Class Coordinate

Hierarchy: Object , Coordinate
All Implemented Interfaces: Serializable , Cloneable , Comparable
Direct Known Subclasses: CoordinateXYM, CoordinateXY, CoordinateXYZM
public class Coordinate
implements Comparable , Cloneable , Serializable
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.

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.

Other

  • version: 1.16
public Coordinate(double x, double y, double z)
Constructs a Coordinate at (x,y,z).
Parameters:
x - x the x-ordinate
y - y the y-ordinate
z - z the z-ordinate
public Coordinate()
Constructs a Coordinate at (0,0,NaN).
public Coordinate(Coordinate c)
Constructs a Coordinate having the same (x,y,z) values as other.
Parameters:
c - c the Coordinate to copy.
public Coordinate(double x, double y)
Constructs a Coordinate at (x,y,NaN).
Parameters:
x - x the x-value
y - y the y-value
public void setCoordinate(Coordinate other)
Sets this Coordinates (x,y,z) values to that of other.
Parameters:
other - other the Coordinate to copy
public double getX()
Retrieves the value of the X ordinate.
Returns:
the value of the X ordinate
public void setX(double x)
Sets the X ordinate value.
Parameters:
x - x the value to set as X
public double getY()
Retrieves the value of the Y ordinate.
Returns:
the value of the Y ordinate
public void setY(double y)
Sets the Y ordinate value.
Parameters:
y - y the value to set as Y
public double getZ()
Retrieves the value of the Z ordinate, if present. If no Z value is present returns NaN.
Returns:
the value of the Z ordinate, or NaN
public void setZ(double z)
Sets the Z ordinate value.
Parameters:
z - z the value to set as Z
public double getM()
Retrieves the value of the measure, if present. If no measure value is present returns NaN.
Returns:
the value of the measure, or NaN
public void setM(double m)
Sets the measure value, if supported.
Parameters:
m - m the value to set as M
public double getOrdinate(int ordinateIndex)
Gets the ordinate value for the given index. The base implementation supports values for the index are X, Y, and Z.
Parameters:
ordinateIndex - ordinateIndex the ordinate index
Returns:
the value of the ordinate
Throws:
IllegalArgumentException - IllegalArgumentException if the index is not valid
public void setOrdinate(int ordinateIndex, double value)
Sets the ordinate for the given index to a given value. The base implementation supported values for the index are X, Y, and Z.
Parameters:
ordinateIndex - ordinateIndex the ordinate index
value - value the value to set
Throws:
IllegalArgumentException - IllegalArgumentException if the index is not valid
public boolean equals2D(Coordinate other)
Returns whether the planar projections of the two Coordinates are equal.
Parameters:
other - other a Coordinate 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.
public 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. The Z ordinate is ignored.
Parameters:
c - c a Coordinate with which to do the 2D comparison.
tolerance - tolerance the tolerance value to use
Returns:
true if other is a Coordinate with the same values for X and Y.
public boolean equals3D(Coordinate other)
Tests if another coordinate has the same values for the X, Y and Z ordinates.
Parameters:
other - other a Coordinate with which to do the 3D comparison.
Returns:
true if other is a Coordinate with the same values for X, Y and Z.
public boolean equalInZ(Coordinate c, double tolerance)
Tests if another coordinate has the same value for Z, within a tolerance.
Parameters:
c - c a coordinate
tolerance - tolerance the tolerance value
Returns:
true if the Z ordinates are within the given tolerance
public boolean equals(Object other)
Returns 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.
Parameters:
other - other a Coordinate with which to do the comparison.
Returns:
true if other is a Coordinate with the same values for the x and y ordinates.
public int compareTo(Coordinate o)
Compares this Coordinate with the specified Coordinate 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))
Note: This method assumes that ordinate values are valid numbers. NaN values are not handled correctly.
Parameters:
o - o the Coordinate with which this Coordinate is being compared
Returns:
-1, zero, or 1 as this Coordinate is less than, equal to, or greater than the specified Coordinate
public String toString()
Returns a String of the form (x,y,z) .
Returns:
a String of the form (x,y,z)
public Object clone()
public Coordinate copy()
Creates a copy of this Coordinate.
Returns:
a copy of this coordinate.
public double distance(Coordinate c)
Computes the 2-dimensional Euclidean distance to another location. The Z-ordinate is ignored.
Parameters:
c - c a point
Returns:
the 2-dimensional Euclidean distance between the locations
public double distance3D(Coordinate c)
Computes the 3-dimensional Euclidean distance to another location.
Parameters:
c - c a coordinate
Returns:
the 3-dimensional Euclidean distance between the locations
public int hashCode()
Gets a hashcode for this coordinate.
Returns:
a hashcode for this coordinate
public static int hashCode(double x)
Computes a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"
Parameters:
x - x the value to compute for
Returns:
a hashcode for x