GEOS 3.6.2
CoordinateSequence.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#ifndef GEOS_GEOM_COORDINATESEQUENCE_H
16#define GEOS_GEOM_COORDINATESEQUENCE_H
17
18#include <geos/export.h>
19#include <geos/platform.h>
20#include <geos/inline.h>
21
22#include <geos/geom/Coordinate.h> // for applyCoordinateFilter
23
24#include <vector>
25#include <iosfwd> // ostream
26#include <memory> // for auto_ptr typedef
27
28// Forward declarations
29namespace geos {
30 namespace geom {
31 class Envelope;
32 class CoordinateFilter;
33 class Coordinate;
34 }
35}
36
37namespace geos {
38namespace geom { // geos::geom
39
59class GEOS_DLL CoordinateSequence {
60
61protected:
62
63 CoordinateSequence() {}
64
65 CoordinateSequence(const CoordinateSequence&) {}
66
67public:
68
69 typedef std::auto_ptr<CoordinateSequence> AutoPtr;
70
71 virtual ~CoordinateSequence() {}
72
76 virtual CoordinateSequence *clone() const=0;
77
84 //virtual const Coordinate& getCoordinate(int i) const=0;
85 virtual const Coordinate& getAt(std::size_t i) const=0;
86
88 const Coordinate& back() const {
89 return getAt(size()-1);
90 }
91
93 const Coordinate& front() const {
94 return getAt(0);
95 }
96
97 const Coordinate& operator[] (std::size_t i) const {
98 return getAt(i);
99 }
100
104 virtual void getAt(std::size_t i, Coordinate& c) const=0;
105
110 //virtual int size() const=0;
111 virtual std::size_t getSize() const=0;
112
113 size_t size() const { return getSize(); }
114
135 virtual const std::vector<Coordinate>* toVector() const=0;
136
138 //
141 virtual void toVector(std::vector<Coordinate>& coords) const=0;
142
150 void add(const std::vector<Coordinate>* vc, bool allowRepeated);
151
152 /* This is here for backward compatibility.. */
153 //void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
154
167 void add(const CoordinateSequence *cl, bool allowRepeated,
168 bool direction);
169
177 virtual void add(const Coordinate& c, bool allowRepeated);
178
190 virtual void add(std::size_t i, const Coordinate& coord, bool allowRepeated)=0;
191
193 virtual bool isEmpty() const=0;
194
196 virtual void add(const Coordinate& c)=0;
197
198 // Get number of coordinates
199 //virtual int getSize() const=0;
200
202 //virtual const Coordinate& getAt(std::size_t pos) const=0;
203
205 virtual void setAt(const Coordinate& c, std::size_t pos)=0;
206
208 virtual void deleteAt(std::size_t pos)=0;
209
211 virtual std::string toString() const=0;
212
214 virtual void setPoints(const std::vector<Coordinate> &v)=0;
215
217 bool hasRepeatedPoints() const;
218
220 const Coordinate* minCoordinate() const;
221
222
231 static CoordinateSequence* removeRepeatedPoints(
232 const CoordinateSequence *cl);
233
235 //
238 virtual CoordinateSequence& removeRepeatedPoints()=0;
239
244 static bool hasRepeatedPoints(const CoordinateSequence *cl);
245
250 static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
251 CoordinateSequence *c);
252
258 static const Coordinate* minCoordinate(CoordinateSequence *cl);
259
261 //
265 static int indexOf(const Coordinate *coordinate,
266 const CoordinateSequence *cl);
267
273 static bool equals(const CoordinateSequence *cl1,
274 const CoordinateSequence *cl2);
275
277 static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
278
296 static int increasingDirection(const CoordinateSequence& pts);
297
299 static void reverse(CoordinateSequence *cl);
300
302 enum { X,Y,Z,M };
303
310 virtual std::size_t getDimension() const=0;
311
322 virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const=0;
323
330 virtual double getX(std::size_t index) const { return getOrdinate(index, X); }
331
338 virtual double getY(std::size_t index) const { return getOrdinate(index, Y); }
339
340
349 virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value)=0;
350
358 virtual void expandEnvelope(Envelope &env) const;
359
360 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
361 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
362
371 template <class T>
373 {
374 Coordinate c;
375 for(std::size_t i=0, n=size(); i<n; ++i)
376 {
377 getAt(i, c);
378 f.filter(c);
379 setAt(c, i);
380 }
381 }
382
383};
384
385GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
386
387GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
388
389GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
390
391} // namespace geos::geom
392} // namespace geos
393
394//#ifdef GEOS_INLINE
395//# include "geos/geom/CoordinateSequence.inl"
396//#endif
397
398#endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
Definition CoordinateFilter.h:43
virtual bool isEmpty() const =0
Returns true it list contains no coordinates.
static void reverse(CoordinateSequence *cl)
Reverse Coordinate order in given CoordinateSequence.
virtual std::size_t getSize() const =0
Returns the number of Coordinates (actual or otherwise, as this implementation may not store its data...
void add(const CoordinateSequence *cl, bool allowRepeated, bool direction)
Add an array of coordinates.
const Coordinate & front() const
Return first Coordinate in the sequence.
Definition CoordinateSequence.h:93
virtual CoordinateSequence * clone() const =0
Returns a deep copy of this collection.
virtual void deleteAt(std::size_t pos)=0
Delete Coordinate at position pos (list will shrink).
virtual void getAt(std::size_t i, Coordinate &c) const =0
Write Coordinate at position i to given Coordinate.
void add(const std::vector< Coordinate > *vc, bool allowRepeated)
Add an array of coordinates.
static bool hasRepeatedPoints(const CoordinateSequence *cl)
Returns true if given CoordinateSequence contains any two consecutive Coordinate.
virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const =0
virtual void setAt(const Coordinate &c, std::size_t pos)=0
Get a reference to Coordinate at position pos.
virtual double getX(std::size_t index) const
Definition CoordinateSequence.h:330
virtual double getY(std::size_t index) const
Definition CoordinateSequence.h:338
virtual std::string toString() const =0
Get a string rapresentation of CoordinateSequence.
virtual const std::vector< Coordinate > * toVector() const =0
Returns a read-only vector with the Coordinates in this collection.
virtual void add(std::size_t i, const Coordinate &coord, bool allowRepeated)=0
Inserts the specified coordinate at the specified position in this list.
virtual void expandEnvelope(Envelope &env) const
void applyCoordinateFilter(T &f)
Apply a fiter to each Coordinate of this sequence. The filter is expected to provide a ....
Definition CoordinateSequence.h:372
virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value)=0
const Coordinate & back() const
Return last Coordinate in the sequence.
Definition CoordinateSequence.h:88
static CoordinateSequence * removeRepeatedPoints(const CoordinateSequence *cl)
Returns a new CoordinateSequence being a copy of the input with any consecutive equal Coordinate remo...
static int increasingDirection(const CoordinateSequence &pts)
Determines which orientation of the Coordinate array is (overall) increasing.
virtual CoordinateSequence & removeRepeatedPoints()=0
Remove consecutive equal Coordinates from the sequence.
static CoordinateSequence * atLeastNCoordinatesOrNothing(std::size_t n, CoordinateSequence *c)
Returns either the given CoordinateSequence if its length is greater than the given amount,...
virtual std::size_t getDimension() const =0
virtual const Coordinate & getAt(std::size_t i) const =0
Returns a read-only reference to Coordinate at position i.
bool hasRepeatedPoints() const
Returns true if contains any two consecutive points.
virtual void toVector(std::vector< Coordinate > &coords) const =0
Pushes all Coordinates of this sequence onto the provided vector.
static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate)
Scroll given CoordinateSequence so to start with given Coordinate.
static int indexOf(const Coordinate *coordinate, const CoordinateSequence *cl)
Return position of a Coordinate, or -1 if not found.
virtual void add(const Coordinate &c, bool allowRepeated)
Add a coordinate.
const Coordinate * minCoordinate() const
Returns lower-left Coordinate in list.
virtual void setPoints(const std::vector< Coordinate > &v)=0
Substitute Coordinate list with a copy of the given vector.
static bool equals(const CoordinateSequence *cl1, const CoordinateSequence *cl2)
Returns true if the two arrays are identical, both null, or pointwise equal.
virtual void add(const Coordinate &c)=0
Add a Coordinate to the list.
static const Coordinate * minCoordinate(CoordinateSequence *cl)
Returns lower-left Coordinate in given CoordinateSequence. This is actually the Coordinate with lower...
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:53
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
GEOS_DLL bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
GEOS_DLL bool operator!=(const Coordinate &a, const Coordinate &b)
Inequality operator for Coordinate. 2D only.
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
Provides classes for various kinds of spatial indexes.
Definition IndexedNestedRingTester.h:31
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25