# geos::geom::CoordinateSequence Class Reference

The internal representation of a list of coordinates inside a Geometry. More...

`#include <geos.h>`

Inheritance diagram for geos::geom::CoordinateSequence:

List of all members.

## Public Types

enum | { X, Y, Z, M }
| Standard ordinate index values.
typedef std::auto_ptr < CoordinateSequence > | AutoPtr

## Public Member Functions

virtual CoordinateSequence * | clone () const =0
| Returns a deep copy of this collection.
virtual const Coordinate & | getAt (size_t i) const =0
| Returns a read-only reference to Coordinate at position i.
const Coordinate & | back () const
| Return last Coordinate in the sequence.
const Coordinate & | front () const
| Return first Coordinate in the sequence.
const Coordinate & | operator[] (size_t i) const
virtual void | getAt (size_t i, Coordinate &c) const =0
| Write Coordinate at position i to given Coordinate.
virtual size_t | getSize () const =0
| Returns the number of Coordinates (actual or otherwise, as this implementation may not store its data in Coordinate objects).
size_t | size () const
virtual const std::vector < Coordinate > * | toVector () const =0
| Returns a read-only vector with the Coordinates in this collection.
virtual void | toVector (std::vector< Coordinate > &coords) const =0
| Pushes all Coordinates of this sequence onto the provided vector.
void | add (const std::vector< Coordinate > *vc, bool allowRepeated)
| Add an array of coordinates.
void | add (const CoordinateSequence *cl, bool allowRepeated, bool direction)
| Add an array of coordinates.
virtual void | add (const Coordinate &c, bool allowRepeated)
| Add a coordinate.
virtual void | add (size_t i, const Coordinate &coord, bool allowRepeated)=0
| Inserts the specified coordinate at the specified position in this list.
virtual bool | isEmpty () const =0
| Returns `true` it list contains no coordinates.
virtual void | add (const Coordinate &c)=0
| Add a Coordinate to the list.
virtual void | setAt (const Coordinate &c, size_t pos)=0
| Get a reference to Coordinate at position pos.
virtual void | deleteAt (size_t pos)=0
| Delete Coordinate at position pos (list will shrink).
virtual std::string | toString () const =0
| Get a string rapresentation of CoordinateSequence.
virtual void | setPoints (const std::vector< Coordinate > &v)=0
| Substitute Coordinate list with a copy of the given vector.
bool | hasRepeatedPoints () const
| Returns true if contains any two consecutive points.
const Coordinate * | minCoordinate () const
| Returns lower-left Coordinate in list.
virtual CoordinateSequence & | removeRepeatedPoints ()=0
| Remove consecutive equal Coordinates from the sequence.
virtual size_t | getDimension () const =0
virtual double | getOrdinate (size_t index, size_t ordinateIndex) const =0
virtual double | getX (size_t index) const
virtual double | getY (size_t index) const
virtual void | setOrdinate (size_t index, size_t ordinateIndex, double value)=0
virtual void | expandEnvelope (Envelope &env) const
virtual void | apply_rw (const CoordinateFilter *filter)=0
virtual void | apply_ro (CoordinateFilter *filter) const =0
template<class T >
void | applyCoordinateFilter (T &f)
| Apply a fiter to each Coordinate of this sequence. The filter is expected to provide a .filter(Coordinate&) method.

## Static Public Member Functions

static CoordinateSequence * | removeRepeatedPoints (const CoordinateSequence *cl)
| Returns a new CoordinateSequence being a copy of the input with any consecutive equal Coordinate removed.
static bool | hasRepeatedPoints (const CoordinateSequence *cl)
| Returns true if given CoordinateSequence contains any two consecutive Coordinate.
static CoordinateSequence * | atLeastNCoordinatesOrNothing (size_t n, CoordinateSequence *c)
| Returns either the given CoordinateSequence if its length is greater than the given amount, or an empty CoordinateSequence.
static const Coordinate * | minCoordinate (CoordinateSequence *cl)
| Returns lower-left Coordinate in given CoordinateSequence. This is actually the Coordinate with lower X (and Y if needed) ordinate.
static int | indexOf (const Coordinate *coordinate, const CoordinateSequence *cl)
| Return position of a Coordinate, or -1 if not found.
static bool | equals (const CoordinateSequence *cl1, const CoordinateSequence *cl2)
| Returns true if the two arrays are identical, both null, or pointwise equal.
static void | scroll (CoordinateSequence *cl, const Coordinate *firstCoordinate)
| Scroll given CoordinateSequence so to start with given Coordinate.
static int | increasingDirection (const CoordinateSequence &pts)
| Determines which orientation of the Coordinate array is (overall) increasing.
static void | reverse (CoordinateSequence *cl)
| Reverse Coordinate order in given CoordinateSequence.

## Protected Member Functions

| CoordinateSequence (const CoordinateSequence &)

## Friends

std::ostream & | operator<< (std::ostream &os, const CoordinateSequence &cs)
bool | operator== (const CoordinateSequence &seq1, const CoordinateSequence &seq2)
bool | operator!= (const CoordinateSequence &seq1, const CoordinateSequence &seq2)

## Detailed Description

The internal representation of a list of coordinates inside a Geometry.

There are some cases in which you might want Geometries to store their points using something other than the GEOS Coordinate class. For example, you may want to experiment with another implementation, such as an array of Xs and an array of Ys. or you might want to use your own coordinate class, one that supports extra attributes like M-values.

You can do this by implementing the CoordinateSequence and CoordinateSequenceFactory interfaces. You would then create a GeometryFactory parameterized by your CoordinateSequenceFactory, and use this GeometryFactory to create new Geometries. All of these new Geometries will use your CoordinateSequence implementation.

## Member Function Documentation

void geos::geom::CoordinateSequence::add | ( | const std::vector< Coordinate > * | vc,
|  | bool | allowRepeated
| ) |  |

Add an array of coordinates.

Parameters:

  vc | The coordinates
  allowRepeated | if set to false, repeated coordinates are collapsed

Returns:
  true (as by general collection contract)

Referenced by geos::operation::buffer::OffsetCurveVertexList::closeRing().

void geos::geom::CoordinateSequence::add | ( | const CoordinateSequence * | cl,
|  | bool | allowRepeated,
|  | bool | direction
| ) |  |

Add an array of coordinates.

Parameters:

  cl | The coordinates
  allowRepeated | if set to false, repeated coordinates are collapsed
  direction | if false, the array is added in reverse order

Returns:
  true (as by general collection contract)

virtual void geos::geom::CoordinateSequence::add | ( | const Coordinate & | c,
|  | bool | allowRepeated
| ) |  | `[virtual]`

Add a coordinate.

Parameters:

  c | The coordinate to add
  allowRepeated | if set to false, repeated coordinates are collapsed

Returns:
  true (as by general collection contract)

Reimplemented in geos::geom::CoordinateArraySequence.

virtual void geos::geom::CoordinateSequence::add | ( | size_t | i,
|  | const Coordinate & | coord,
|  | bool | allowRepeated
| ) |  | `[pure virtual]`

Inserts the specified coordinate at the specified position in this list.

Parameters:

  i | the position at which to insert
  coord | the coordinate to insert
  allowRepeated | if set to false, repeated coordinates are collapsed

NOTE: this is a CoordinateList interface in JTS

Implemented in geos::geom::CoordinateArraySequence.

template<class T >

void geos::geom::CoordinateSequence::applyCoordinateFilter | ( | T & | f ) | `[inline]`

Apply a fiter to each Coordinate of this sequence. The filter is expected to provide a .filter(Coordinate&) method.

TODO: accept a Functor instead, will be more flexible. actually, define iterators on Geometry

virtual void geos::geom::CoordinateSequence::expandEnvelope | ( | Envelope & | env ) | const`[virtual]`

Expands the given Envelope to include the coordinates in the sequence. Allows implementing classes to optimize access to coordinate values.

Parameters:

  env | the envelope to expand

Reimplemented in geos::geom::CoordinateArraySequence.

virtual const Coordinate& geos::geom::CoordinateSequence::getAt | ( | size_t | i ) | const`[pure virtual]`

Returns a read-only reference to Coordinate at position i.

Whether or not the Coordinate returned is the actual underlying Coordinate or merely a copy depends on the implementation.

Implemented in geos::geom::CoordinateArraySequence.

virtual size_t geos::geom::CoordinateSequence::getDimension | ( | ) | const`[pure virtual]`

Returns the dimension (number of ordinates in each coordinate) for this sequence.

Returns:
  the dimension of the sequence.

Implemented in geos::geom::CoordinateArraySequence.

virtual double geos::geom::CoordinateSequence::getOrdinate | ( | size_t | index,
|  | size_t | ordinateIndex
| ) |  | const`[pure virtual]`

Returns the ordinate of a coordinate in this sequence. Ordinate indices 0 and 1 are assumed to be X and Y. Ordinates indices greater than 1 have user-defined semantics (for instance, they may contain other dimensions or measure values).

Parameters:

  index | the coordinate index in the sequence
  ordinateIndex | the ordinate index in the coordinate (in range [0, dimension-1])

Implemented in geos::geom::CoordinateArraySequence.

virtual double geos::geom::CoordinateSequence::getX | ( | size_t | index ) | const`[inline, virtual]`

Returns ordinate X (0) of the specified coordinate.

Parameters:

  index |

Returns:
  the value of the X ordinate in the index'th coordinate

virtual double geos::geom::CoordinateSequence::getY | ( | size_t | index ) | const`[inline, virtual]`

Returns ordinate Y (1) of the specified coordinate.

Parameters:

  index |

Returns:
  the value of the Y ordinate in the index'th coordinate

static int geos::geom::CoordinateSequence::increasingDirection | ( | const CoordinateSequence & | pts ) | `[static]`

Determines which orientation of the Coordinate array is (overall) increasing.

In other words, determines which end of the array is "smaller" (using the standard ordering on Coordinate). Returns an integer indicating the increasing direction. If the sequence is a palindrome, it is defined to be oriented in a positive direction.

Parameters:

  pts | the array of Coordinates to test

Returns:
  `1` if the array is smaller at the start or is a palindrome, `-1` if smaller at the end

NOTE: this method is found in CoordinateArrays class for JTS

static int geos::geom::CoordinateSequence::indexOf | ( | const Coordinate * | coordinate,
|  | const CoordinateSequence * | cl
| ) |  | `[static]`

Return position of a Coordinate, or -1 if not found.

FIXME: return size_t, using numeric_limits<size_t>::max as 'not found' value.

virtual CoordinateSequence& geos::geom::CoordinateSequence::removeRepeatedPoints | ( | ) | `[pure virtual]`

Remove consecutive equal Coordinates from the sequence.

Equality test is 2D based. Returns a reference to self.

Implemented in geos::geom::CoordinateArraySequence.

static CoordinateSequence* geos::geom::CoordinateSequence::removeRepeatedPoints | ( | const CoordinateSequence * | cl ) | `[static]`

Returns a new CoordinateSequence being a copy of the input with any consecutive equal Coordinate removed.

Equality test is 2D based

Ownership of returned object goes to the caller.

virtual void geos::geom::CoordinateSequence::setAt | ( | const Coordinate & | c,
|  | size_t | pos
| ) |  | `[pure virtual]`

Get a reference to Coordinate at position pos.

Copy Coordinate c to position pos

Implemented in geos::geom::CoordinateArraySequence.

virtual void geos::geom::CoordinateSequence::setOrdinate | ( | size_t | index,
|  | size_t | ordinateIndex,
|  | double | value
| ) |  | `[pure virtual]`

Sets the value for a given ordinate of a coordinate in this sequence.

Parameters:

  index | the coordinate index in the sequence
  ordinateIndex | the ordinate index in the coordinate (in range [0, dimension-1])
  value | the new ordinate value

Implemented in geos::geom::CoordinateArraySequence.

virtual const std::vector<Coordinate>* geos::geom::CoordinateSequence::toVector | ( | ) | const`[pure virtual]`

Returns a read-only vector with the Coordinates in this collection.

Whether or not the Coordinates returned are the actual underlying Coordinates or merely copies depends on the implementation. Note that if this implementation does not store its data as an array of Coordinates, this method will incur a performance penalty because the array needs to be built from scratch.

This method is a port of the toCoordinateArray() method of JTS. It is not much used as memory management requires us to know wheter we should or not delete the returned object in a consistent way. Our options are: use shared_ptr<Coordinate> or always keep ownerhips of an eventual newly created vector. We opted for the second, so the returned object is a const, to also ensure that returning an internal pointer doesn't make the object mutable.

Deprecated:
  use toVector(std::vector<Coordinate>&) instead

Implemented in geos::geom::CoordinateArraySequence.

virtual void geos::geom::CoordinateSequence::toVector | ( | std::vector< Coordinate > & | coords ) | const`[pure virtual]`

Pushes all Coordinates of this sequence onto the provided vector.

This method is a port of the toCoordinateArray() method of JTS.

Implemented in geos::geom::CoordinateArraySequence.

The documentation for this class was generated from the following file:

- CoordinateSequence.h