GEOS 3.3.4

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

- File List

CoordinateSequence.h
1 /**********************************************************************
2 * $Id: CoordinateSequence.h 3255 2011-03-01 17:56:10Z mloskot $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2006 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************/
15
16 #ifndef GEOS_GEOM_COORDINATESEQUENCE_H
17 #define GEOS_GEOM_COORDINATESEQUENCE_H
18
19 #include <geos/export.h>
20 #include <geos/platform.h>
21 #include <geos/inline.h>
22
23 #include <geos/geom/Coordinate.h> // for applyCoordinateFilter
24
25 #include <vector>
26 #include <iosfwd> // ostream
27 #include <memory> // for auto_ptr typedef
28
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32 class Envelope;
33 class CoordinateFilter;
34 class Coordinate;
35 }
36 }
37
38 namespace geos {
39 namespace geom { // geos::geom
40
60 class GEOS_DLL CoordinateSequence {
61
62 protected:
63
64 CoordinateSequence() {}
65
66 CoordinateSequence(const CoordinateSequence&) {}
67
68 public:
69
70 typedef std::auto_ptr<CoordinateSequence> AutoPtr;
71
72 virtual ~CoordinateSequence() {}
73
77 virtual CoordinateSequence *clone() const=0;
78
85 //virtual const Coordinate& getCoordinate(int i) const=0;
86 virtual const Coordinate& getAt(std::size_t i) const=0;
87
89 const Coordinate& back() const {
90 return getAt(size()-1);
91 }
92
94 const Coordinate& front() const {
95 return getAt(0);
96 }
97
98 const Coordinate& operator[] (std::size_t i) const {
99 return getAt(i);
100 }
101
105 virtual void getAt(std::size_t i, Coordinate& c) const=0;
106
111 //virtual int size() const=0;
112 virtual std::size_t getSize() const=0;
113
114 size_t size() const { return getSize(); }
115
136 virtual const std::vector<Coordinate>* toVector() const=0;
137
139 //
142 virtual void toVector(std::vector<Coordinate>& coords) const=0;
143
151 void add(const std::vector<Coordinate>* vc, bool allowRepeated);
152
153 /* This is here for backward compatibility.. */
154 //void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
155
168 void add(const CoordinateSequence *cl, bool allowRepeated,
169 bool direction);
170
178 virtual void add(const Coordinate& c, bool allowRepeated);
179
191 virtual void add(std::size_t i, const Coordinate& coord, bool allowRepeated)=0;
192
194 virtual bool isEmpty() const=0;
195
197 virtual void add(const Coordinate& c)=0;
198
199 // Get number of coordinates
200 //virtual int getSize() const=0;
201
203 //virtual const Coordinate& getAt(std::size_t pos) const=0;
204
206 virtual void setAt(const Coordinate& c, std::size_t pos)=0;
207
209 virtual void deleteAt(std::size_t pos)=0;
210
212 virtual std::string toString() const=0;
213
215 virtual void setPoints(const std::vector<Coordinate> &v)=0;
216
218 bool hasRepeatedPoints() const;
219
221 const Coordinate* minCoordinate() const;
222
223
232 static CoordinateSequence* removeRepeatedPoints(
233 const CoordinateSequence *cl);
234
236 //
239 virtual CoordinateSequence& removeRepeatedPoints()=0;
240
245 static bool hasRepeatedPoints(const CoordinateSequence *cl);
246
251 static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
252 CoordinateSequence *c);
253
259 static const Coordinate* minCoordinate(CoordinateSequence *cl);
260
262 //
266 static int indexOf(const Coordinate *coordinate,
267 const CoordinateSequence *cl);
268
274 static bool equals(const CoordinateSequence *cl1,
275 const CoordinateSequence *cl2);
276
278 static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
279
297 static int increasingDirection(const CoordinateSequence& pts);
298
300 static void reverse(CoordinateSequence *cl);
301
303 enum { X,Y,Z,M };
304
311 virtual std::size_t getDimension() const=0;
312
323 virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const=0;
324
331 virtual double getX(std::size_t index) const { return getOrdinate(index, X); }
332
339 virtual double getY(std::size_t index) const { return getOrdinate(index, Y); }
340
341
350 virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value)=0;
351
359 virtual void expandEnvelope(Envelope &env) const;
360
361 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
362 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
363
372 template <class T>
373 void applyCoordinateFilter(T& f)
374 {
375 Coordinate c;
376 for(std::size_t i=0, n=size(); i<n; ++i)
377 {
378 getAt(i, c);
379 f.filter(c);
380 setAt(c, i);
381 }
382 }
383
384 };
385
386 GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
387
388 GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
389
390 GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
391
392 } // namespace geos::geom
393 } // namespace geos
394
395 //#ifdef GEOS_INLINE
396 //# include "geos/geom/CoordinateSequence.inl"
397 //#endif
398
399 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
400
401 /**********************************************************************
402 * $Log$
403 * Revision 1.12 2006/06/12 16:51:23 strk
404 * Added equality and inequality operators and tests
405 *
406 * Revision 1.11 2006/06/12 16:36:22 strk
407 * indentation, notes about things to be fixed.
408 *
409 * Revision 1.10 2006/06/12 15:06:30 strk
410 * Added default ctor and copy ctor (protected)
411 *
412 * Revision 1.9 2006/06/12 10:10:39 strk
413 * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
414 *
415 * Revision 1.8 2006/05/04 08:42:12 strk
416 * Added note about the CoordinateSequence::toVector() method.
417 *
418 * Revision 1.7 2006/05/03 19:47:27 strk
419 * added operator<< for CoordinateSequence
420 *
421 * Revision 1.6 2006/05/03 08:58:34 strk
422 * added new non-static CoordinateSequence::removeRepeatedPoints() mutator.
423 *
424 * Revision 1.5 2006/04/11 11:55:22 strk
425 * Added CoordinateSequence::AutoPtr typedef
426 *
427 * Revision 1.4 2006/04/04 09:53:45 strk
428 * Fixed applyCoordinateFilter() templated function body
429 *
430 * Revision 1.3 2006/03/24 09:52:41 strk
431 * USE_INLINE => GEOS_INLINE
432 *
433 * Revision 1.2 2006/03/20 17:27:03 strk
434 * Bug #72 - Missing <vector> header
435 *
436 * Revision 1.1 2006/03/09 16:46:49 strk
437 * geos::geom namespace definition, first pass at headers split
438 *
439 **********************************************************************/