GEOS 3.8.1
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/inline.h>
20
21#include <geos/geom/Coordinate.h> // for applyCoordinateFilter
22
23#include <vector>
24#include <iosfwd> // ostream
25#include <memory> // for unique_ptr typedef
26
27// Forward declarations
28namespace geos {
29namespace geom {
30class Envelope;
31class CoordinateFilter;
32class Coordinate;
33}
34}
35
36namespace geos {
37namespace geom { // geos::geom
38
58class GEOS_DLL CoordinateSequence {
59
60protected:
61
63
65
66public:
67
68 typedef std::unique_ptr<CoordinateSequence> Ptr;
69
70 virtual
72
76 virtual std::unique_ptr<CoordinateSequence> clone() const = 0;
77
84 virtual const Coordinate& getAt(std::size_t i) const = 0;
85
87 const Coordinate&
88 back() const
89 {
90 return getAt(size() - 1);
91 }
92
94 const Coordinate&
95 front() const
96 {
97 return getAt(0);
98 }
99
100 const Coordinate&
101 operator[](std::size_t i) const
102 {
103 return getAt(i);
104 }
105
106 virtual Envelope getEnvelope() const;
107
111 virtual void getAt(std::size_t i, Coordinate& c) const = 0;
112
117 virtual std::size_t getSize() const = 0;
118
119 size_t
120 size() const
121 {
122 return getSize();
123 }
124
129 virtual void toVector(std::vector<Coordinate>& coords) const = 0;
130
132 virtual bool isEmpty() const = 0;
133
135 virtual void setAt(const Coordinate& c, std::size_t pos) = 0;
136
138 std::string toString() const;
139
141 virtual void setPoints(const std::vector<Coordinate>& v) = 0;
142
144 bool hasRepeatedPoints() const;
145
147 const Coordinate* minCoordinate() const;
148
153 static bool hasRepeatedPoints(const CoordinateSequence* cl);
154
161
163 //
167 static size_t indexOf(const Coordinate* coordinate,
168 const CoordinateSequence* cl);
169
175 static bool equals(const CoordinateSequence* cl1,
176 const CoordinateSequence* cl2);
177
179 static void scroll(CoordinateSequence* cl, const Coordinate* firstCoordinate);
180
199
201 static void reverse(CoordinateSequence* cl);
202
204 enum { X, Y, Z, M };
205
212 virtual std::size_t getDimension() const = 0;
213
224 virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const;
225
232 virtual double
233 getX(std::size_t index) const
234 {
235 return getOrdinate(index, X);
236 }
237
244 virtual double
245 getY(std::size_t index) const
246 {
247 return getOrdinate(index, Y);
248 }
249
250
259 virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value) = 0;
260
268 virtual void expandEnvelope(Envelope& env) const;
269
270 virtual void apply_rw(const CoordinateFilter* filter) = 0; //Abstract
271 virtual void apply_ro(CoordinateFilter* filter) const = 0; //Abstract
272
281 template <class T>
282 void
284 {
285 Coordinate c;
286 for(std::size_t i = 0, n = size(); i < n; ++i) {
287 getAt(i, c);
288 f.filter(c);
289 setAt(c, i);
290 }
291 }
292
293};
294
295GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
296
297GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
298
299GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
300
301} // namespace geos::geom
302} // namespace geos
303
304//#ifdef GEOS_INLINE
305//# include "geos/geom/CoordinateSequence.inl"
306//#endif
307
308#endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:43
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
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...
const Coordinate & front() const
Return first Coordinate in the sequence.
Definition: CoordinateSequence.h:95
virtual void getAt(std::size_t i, Coordinate &c) const =0
Write Coordinate at position i to given Coordinate.
static bool hasRepeatedPoints(const CoordinateSequence *cl)
Returns true if given CoordinateSequence contains any two consecutive Coordinate.
virtual void setAt(const Coordinate &c, std::size_t pos)=0
Copy Coordinate c to position pos.
virtual double getX(std::size_t index) const
Definition: CoordinateSequence.h:233
virtual double getY(std::size_t index) const
Definition: CoordinateSequence.h:245
virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const
virtual void expandEnvelope(Envelope &env) const
void applyCoordinateFilter(T &f)
Apply a filter to each Coordinate of this sequence. The filter is expected to provide a ....
Definition: CoordinateSequence.h:283
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 int increasingDirection(const CoordinateSequence &pts)
Determines which orientation of the Coordinate array is (overall) increasing.
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.
static size_t indexOf(const Coordinate *coordinate, const CoordinateSequence *cl)
Return position of a Coordinate, or -1 if not found.
virtual void toVector(std::vector< Coordinate > &coords) const =0
virtual std::unique_ptr< CoordinateSequence > clone() const =0
Returns a deep copy of this collection.
std::string toString() const
Get a string representation of CoordinateSequence.
static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate)
Scroll given CoordinateSequence so to start with given 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.
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:58
bool operator!=(const Coordinate &a, const Coordinate &b)
Inequality operator for Coordinate. 2D only.
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25