GEOS 3.11.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#pragma once
16
17#include <geos/export.h>
18
19#include <geos/geom/Coordinate.h> // for applyCoordinateFilter
20
21#include <vector>
22#include <iosfwd> // ostream
23#include <memory> // for unique_ptr typedef
24
25// Forward declarations
26namespace geos {
27namespace geom {
28class Envelope;
29class CoordinateFilter;
30class Coordinate;
31}
32}
33
34namespace geos {
35namespace geom { // geos::geom
36
44class GEOS_DLL CoordinateSequence {
45
46protected:
47
49
51
52public:
53
54 typedef std::unique_ptr<CoordinateSequence> Ptr;
55
56 virtual
58
62 virtual std::unique_ptr<CoordinateSequence> clone() const = 0;
63
70 virtual const Coordinate& getAt(std::size_t i) const = 0;
71
73 const Coordinate&
74 back() const
75 {
76 return getAt(size() - 1);
77 }
78
80 const Coordinate&
81 front() const
82 {
83 return getAt(0);
84 }
85
86 const Coordinate&
87 operator[](std::size_t i) const
88 {
89 return getAt(i);
90 }
91
92 virtual Envelope getEnvelope() const;
93
97 virtual void getAt(std::size_t i, Coordinate& c) const = 0;
98
103 virtual std::size_t getSize() const = 0;
104
105 size_t
106 size() const
107 {
108 return getSize();
109 }
110
115 virtual void toVector(std::vector<Coordinate>& coords) const = 0;
116
118 virtual bool isEmpty() const = 0;
119
121 virtual void setAt(const Coordinate& c, std::size_t pos) = 0;
122
124 std::string toString() const;
125
127 virtual void setPoints(const std::vector<Coordinate>& v) = 0;
128
130 bool hasRepeatedPoints() const;
131
133 const Coordinate* minCoordinate() const;
134
139 static bool hasRepeatedPoints(const CoordinateSequence* cl);
140
147
149 //
152 static std::size_t indexOf(const Coordinate* coordinate,
153 const CoordinateSequence* cl);
154
160 static bool equals(const CoordinateSequence* cl1,
161 const CoordinateSequence* cl2);
162
164 static void scroll(CoordinateSequence* cl, const Coordinate* firstCoordinate);
165
184
185
192 bool isRing() const;
193
195 static void reverse(CoordinateSequence* cl);
196
198 enum { X, Y, Z, M };
199
206 virtual std::size_t getDimension() const = 0;
207
208 bool hasZ() const {
209 return getDimension() > 2;
210 }
211
222 virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const;
223
230 virtual double
231 getX(std::size_t index) const
232 {
233 return getOrdinate(index, X);
234 }
235
242 virtual double
243 getY(std::size_t index) const
244 {
245 return getOrdinate(index, Y);
246 }
247
248
257 virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value) = 0;
258
266 virtual void expandEnvelope(Envelope& env) const;
267
268 virtual void apply_rw(const CoordinateFilter* filter) = 0; //Abstract
269 virtual void apply_ro(CoordinateFilter* filter) const = 0; //Abstract
270
279 template <class T>
280 void
282 {
283 Coordinate c;
284 for(std::size_t i = 0, n = size(); i < n; ++i) {
285 getAt(i, c);
286 f.filter(c);
287 setAt(c, i);
288 }
289 }
290
291};
292
293GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
294
295GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
296
297GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
298
299} // namespace geos::geom
300} // namespace geos
301
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:41
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
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:81
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:231
virtual double getY(std::size_t index) const
Definition: CoordinateSequence.h:243
virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const
static std::size_t indexOf(const Coordinate *coordinate, const CoordinateSequence *cl)
Return position of a Coordinate.
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:281
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:74
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.
virtual void toVector(std::vector< Coordinate > &coords) const =0
bool isRing() const
Tests whether an a CoordinateSequence forms a ring, by checking length and closure....
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:58
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Basic namespace for all GEOS functionalities.
Definition: geos.h:39