GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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
29 namespace geos {
30 namespace geom {
31 class Envelope;
32 class CoordinateFilter;
33 class Coordinate;
34 }
35 }
36
37 namespace geos {
38 namespace geom { // geos::geom
39
59 class GEOS_DLL CoordinateSequence {
60
61 protected:
62
63 CoordinateSequence() {}
64
65 CoordinateSequence(const CoordinateSequence&) {}
66
67 public:
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>
372 void applyCoordinateFilter(T& f)
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
385 GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
386
387 GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
388
389 GEOS_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