com.vividsolutions.jts.geom
Class Coordinate

java.lang.Object
  extended by com.vividsolutions.jts.geom.Coordinate
All Implemented Interfaces:
Serializable, Cloneable, Comparable
Direct Known Subclasses:
ExtendedCoordinate

public class Coordinate
extends 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. 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.

Version:
1.7
See Also:
Serialized Form

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
static double NULL_ORDINATE
          The value used to indicate a null or missing ordinate value.
 double x
          The x-coordinate.
static int X
          Standard ordinate index values
 double y
          The y-coordinate.
static int Y
           
 double z
          The z-coordinate.
static int Z
           
 
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)
          Computes the 2-dimensional Euclidean distance to another location.
 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.
 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 this Coordinates (x,y,z) values to that of other.
 void setOrdinate(int ordinateIndex, double value)
          Sets the ordinate for the given index to a given value.
 String toString()
          Returns a String of the form (x,y,z) .
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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 a Coordinate at (x,y,z).

Parameters:
x - the x-value
y - the y-value
z - the z-value

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
Method Detail

setCoordinate

public void setCoordinate(Coordinate other)
Sets this Coordinates (x,y,z) values to that of other.

Parameters:
other - the Coordinate to copy

getOrdinate

public double getOrdinate(int ordinateIndex)
Gets the ordinate value for the given index. The supported values for the index are X, Y, and Z.

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 are X, Y, and Z.

Parameters:
ordinateIndex - the ordinate index
value - the value to set
Throws:
IllegalArgumentException - if the index is not valid

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.

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.

Overrides:
equals in class Object
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.

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: Note: This method assumes that ordinate values are valid numbers. NaN values are not handled correctly.

Specified by:
compareTo in interface Comparable
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

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.

toString

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

Overrides:
toString in class Object
Returns:
a String of the form (x,y,z)

clone

public Object clone()
Overrides:
clone in class Object

distance

public double distance(Coordinate p)
Computes the 2-dimensional Euclidean distance to another location. The Z-ordinate is ignored.

Parameters:
p - a point
Returns:
the 2-dimensional Euclidean distance between the locations

hashCode

public int hashCode()
Gets a hashcode for this coordinate.

Overrides:
hashCode in class 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


Copyright © 2012. All Rights Reserved.