org.jaitools.jts
Class CoordinateSequence2D

java.lang.Object
  extended by org.jaitools.jts.CoordinateSequence2D
All Implemented Interfaces:
com.vividsolutions.jts.geom.CoordinateSequence, Cloneable

public final class CoordinateSequence2D
extends Object
implements com.vividsolutions.jts.geom.CoordinateSequence, Cloneable

A lightweight implementation of JTS CoordinateSequence for 2D points.

Since:
1.1
Version:
$Id$
Author:
Michael Bedward

Field Summary
 
Fields inherited from interface com.vividsolutions.jts.geom.CoordinateSequence
M, X, Y, Z
 
Constructor Summary
CoordinateSequence2D(double... xy)
          Creates a new CoordinateSequence2D object from a sequence of (x,y) pairs.
CoordinateSequence2D(int n)
          Creates a new CoordinateSequence2D object with the given size.
 
Method Summary
 Object clone()
          Creates a deep copy of this sequence.
 com.vividsolutions.jts.geom.Envelope expandEnvelope(com.vividsolutions.jts.geom.Envelope env)
          Returns an envelope which contains env and all points in this sequence.
 com.vividsolutions.jts.geom.Coordinate getCoordinate(int index)
          Gets coordinate values at the specified index.
 void getCoordinate(int index, com.vividsolutions.jts.geom.Coordinate coord)
          Copies the requested coordinate in the sequence to the supplied Coordinate object.
 com.vividsolutions.jts.geom.Coordinate getCoordinateCopy(int index)
          Equivalent to getCoordinate(int).
 int getDimension()
          Gets the dimension of points stored by this CoordinateSequence2D.
 double getOrdinate(int index, int ordinateIndex)
          Returns the ordinate of a coordinate in this sequence.
 double getX(int index)
          
 double getY(int index)
          
 void setOrdinate(int index, int ordinateIndex, double value)
          Sets the ordinate of a coordinate in this sequence.
 void setX(int index, double value)
          Sets the X ordinate of the point at the given index.
 void setXY(int index, double x, double y)
          Sets the coordinate at the given index.
 void setY(int index, double value)
          Sets the Y ordinate of the point at the given index.
 int size()
          
 com.vividsolutions.jts.geom.Coordinate[] toCoordinateArray()
          Returns an array of new Coordinate objects for the point values in this sequence.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoordinateSequence2D

public CoordinateSequence2D(int n)
Creates a new CoordinateSequence2D object with the given size.

Parameters:
n - capacity (number of coordinates)

CoordinateSequence2D

public CoordinateSequence2D(double... xy)
Creates a new CoordinateSequence2D object from a sequence of (x,y) pairs.

 // Example: create an object with 3 coordinates specified
 // as xy pairs
 CoordinateSequence cs = new CoordinateSequence2D(1.1, 1.2, 2.1, 2.2, 3.1, 3.2);
 

Parameters:
xy - x and y values ordered as x0, y0, x1, y1...; if null an empty object is created
Throws:
IllegalArgumentException - if the number of values in xy is greater than 0 but not even
Method Detail

getDimension

public int getDimension()
Gets the dimension of points stored by this CoordinateSequence2D.

Specified by:
getDimension in interface com.vividsolutions.jts.geom.CoordinateSequence
Returns:
always returns 2

getCoordinate

public com.vividsolutions.jts.geom.Coordinate getCoordinate(int index)
Gets coordinate values at the specified index.

Specified by:
getCoordinate in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()
Returns:
a new Coordinate object

getCoordinateCopy

public com.vividsolutions.jts.geom.Coordinate getCoordinateCopy(int index)
Equivalent to getCoordinate(int).

Specified by:
getCoordinateCopy in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()
Returns:
a new Coordinate object

getCoordinate

public void getCoordinate(int index,
                          com.vividsolutions.jts.geom.Coordinate coord)
Copies the requested coordinate in the sequence to the supplied Coordinate object.

Specified by:
getCoordinate in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()
coord - the destination object; ff null a new Coordinate will e created.

getX

public double getX(int index)

Specified by:
getX in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()

getY

public double getY(int index)

Specified by:
getY in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()

getOrdinate

public double getOrdinate(int index,
                          int ordinateIndex)
Returns the ordinate of a coordinate in this sequence.

Specified by:
getOrdinate in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()
ordinateIndex - 0 for the X ordinate or 1 for the Y ordinate
Returns:
the ordinate value
Throws:
IllegalArgumentException - if ordinateIndex is not either 0 or 1

size

public int size()

Specified by:
size in interface com.vividsolutions.jts.geom.CoordinateSequence

setOrdinate

public void setOrdinate(int index,
                        int ordinateIndex,
                        double value)
Sets the ordinate of a coordinate in this sequence.

Specified by:
setOrdinate in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
index - an index ≥0 and < size()
ordinateIndex - 0 for the X ordinate or 1 for the Y ordinate
value - the new ordinate value
Throws:
IllegalArgumentException - if ordinateIndex is not either 0 or 1

setX

public void setX(int index,
                 double value)
Sets the X ordinate of the point at the given index. Equivalent to setOrdinate(int, int, double)(index, 0, value).

Parameters:
index - an index ≥0 and < size()
value - the new value

setY

public void setY(int index,
                 double value)
Sets the Y ordinate of the point at the given index. Equivalent to setOrdinate(int, int, double)(index, 1, value).

Parameters:
index - an index ≥0 and < size()
value - the new value

setXY

public void setXY(int index,
                  double x,
                  double y)
Sets the coordinate at the given index.

Parameters:
index - an index ≥0 and < size()
x - the new X ordinate value
y - the new Y ordinate value

toCoordinateArray

public com.vividsolutions.jts.geom.Coordinate[] toCoordinateArray()
Returns an array of new Coordinate objects for the point values in this sequence.

Specified by:
toCoordinateArray in interface com.vividsolutions.jts.geom.CoordinateSequence
Returns:
array of coordinates

expandEnvelope

public com.vividsolutions.jts.geom.Envelope expandEnvelope(com.vividsolutions.jts.geom.Envelope env)
Returns an envelope which contains env and all points in this sequence. If env contains all points it is returned unchanged.

Specified by:
expandEnvelope in interface com.vividsolutions.jts.geom.CoordinateSequence
Parameters:
env - the test envelope; if null a new Envelope is created
Returns:
an envelope that includes env plus all points in this sequence

clone

public Object clone()
Creates a deep copy of this sequence.

Specified by:
clone in interface com.vividsolutions.jts.geom.CoordinateSequence
Overrides:
clone in class Object
Returns:
a new sequence with values


Copyright © 2009-2013. All Rights Reserved.