com.vividsolutions.jts.geom

Class Coordinate

Implemented Interfaces:
Cloneable, Comparable, Serializable

public class Coordinate
extends java.lang.Object
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. JTS does not support any operations on the z-ordinate except the basic accessor functions. Constructed coordinates will have a z-ordinate of NaN. The standard comparison functions will ignore the z-ordinate.

Version:
1.7

Nested Class Summary

static class
Coordinate.DimensionalComparator
Compares two Coordinates, allowing for either a 2-dimensional or 3-dimensional comparison, and handling NaN values correctly.

Field Summary

double
x
The x-coordinate.
double
y
The y-coordinate.
double
z
The z-coordinate.

Constructor Summary

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).

Method Summary

Object
clone()
int
compareTo(Object o)
Compares this Coordinate with the specified Coordinate for order.
double
distance(Coordinate p)
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 Coordinates are equal.
boolean
equals3D(Coordinate other)
Returns true if other has the same values for x, y and z.
int
hashCode()
static int
hashCode(double x)
Returns a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"
void
setCoordinate(Coordinate other)
Sets this Coordinates (x,y,z) values to that of other .
String
toString()
Returns a String of the form (x,y,z) .

Field Details

x

public double x
The x-coordinate.

y

public double y
The y-coordinate.

z

public double z
The z-coordinate.

Constructor Details

Coordinate

public Coordinate()
Constructs a Coordinate at (0,0,NaN).

Coordinate

public Coordinate(Coordinate c)
Constructs a Coordinate having the same (x,y,z) values as other.
Parameters:
c - the Coordinate to copy.

Coordinate

public Coordinate(double x,
                  double y)
Constructs a Coordinate at (x,y,NaN).
Parameters:
x - the x-value
y - the y-value

Coordinate

public Coordinate(double x,
                  double y,
                  double z)
Constructs a Coordinate at (x,y,z).
Parameters:
x - the x-value
y - the y-value
z - the z-value

Method Details

clone

public Object clone()

compareTo

public int compareTo(Object o)
Compares this Coordinate with the specified Coordinate for order. This method ignores the z value when making the comparison. Returns:
  • -1 : this.x <32other.x || ((this.x == other.x) && (this.y <13 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 - 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

distance

public double distance(Coordinate p)

equals

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 - 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.

equals2D

public boolean equals2D(Coordinate other)
Returns whether the planar projections of the two Coordinates are equal.
Parameters:
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.

equals3D

public boolean equals3D(Coordinate other)
Returns true if other has the same values for x, y and z.
Parameters:
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.

hashCode

public int hashCode()

hashCode

public static int hashCode(double x)
Returns a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"

setCoordinate

public void setCoordinate(Coordinate other)
Sets this Coordinates (x,y,z) values to that of other .
Parameters:
other - the Coordinate to copy

toString

public String toString()
Returns a String of the form (x,y,z) .
Returns:
a String of the form (x,y,z)