Class CoordinateSequence2D

Object
CoordinateSequence2D
All Implemented Interfaces:
Cloneable, CoordinateSequence

public final class CoordinateSequence2D extends Object implements CoordinateSequence, Cloneable
A lightweight implementation of JTS CoordinateSequence for 2D points.
Since:
1.1
Author:
Michael Bedward
  • Constructor Details

    • 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 Details

    • getDimension

      public int getDimension()
      Gets the dimension of points stored by this CoordinateSequence2D.
      Specified by:
      getDimension in interface CoordinateSequence
      Returns:
      always returns 2
    • getCoordinate

      public Coordinate getCoordinate(int index)
      Gets coordinate values at the specified index.
      Specified by:
      getCoordinate in interface CoordinateSequence
      Parameters:
      index - an index ≥0 and < size()
      Returns:
      a new Coordinate object
    • getCoordinateCopy

      public Coordinate getCoordinateCopy(int index)
      Equivalent to getCoordinate(int).
      Specified by:
      getCoordinateCopy in interface CoordinateSequence
      Parameters:
      index - an index ≥0 and < size()
      Returns:
      a new Coordinate object
    • getCoordinate

      public void getCoordinate(int index, Coordinate coord)
      Copies the requested coordinate in the sequence to the supplied Coordinate object.
      Specified by:
      getCoordinate in interface 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 CoordinateSequence
      Parameters:
      index - an index ≥0 and < size()
    • getY

      public double getY(int index)
      Specified by:
      getY in interface 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 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 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 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 Coordinate[] toCoordinateArray()
      Returns an array of new Coordinate objects for the point values in this sequence.
      Specified by:
      toCoordinateArray in interface CoordinateSequence
      Returns:
      array of coordinates
    • expandEnvelope

      public Envelope expandEnvelope(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 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 CoordinateSequence
      Returns:
      a new sequence with values
    • copy

      public CoordinateSequence copy()
      Specified by:
      copy in interface CoordinateSequence