GEOS  3.8.0dev
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
28 namespace geos {
29 namespace geom {
30 class Envelope;
31 class CoordinateFilter;
32 class Coordinate;
33 }
34 }
35 
36 namespace geos {
37 namespace geom { // geos::geom
38 
58 class GEOS_DLL CoordinateSequence {
59 
60 protected:
61 
63 
65 
66 public:
67 
68  typedef std::unique_ptr<CoordinateSequence> Ptr;
69 
70  virtual
71  ~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&
89  back() const
90  {
91  return getAt(size() - 1);
92  }
93 
95  const Coordinate&
96  front() const
97  {
98  return getAt(0);
99  }
100 
101  const Coordinate&
102  operator[](std::size_t i) const
103  {
104  return getAt(i);
105  }
106 
110  virtual void getAt(std::size_t i, Coordinate& c) const = 0;
111 
116  //virtual int size() const=0;
117  virtual std::size_t getSize() const = 0;
118 
119  size_t
120  size() const
121  {
122  return getSize();
123  }
124 
145  virtual const std::vector<Coordinate>* toVector() const = 0;
146 
148  //
151  virtual void toVector(std::vector<Coordinate>& coords) const = 0;
152 
160  void add(const std::vector<Coordinate>* vc, bool allowRepeated);
161 
162  /* This is here for backward compatibility.. */
163  //void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
164 
177  void add(const CoordinateSequence* cl, bool allowRepeated,
178  bool direction);
179 
187  virtual void add(const Coordinate& c, bool allowRepeated);
188 
200  virtual void add(std::size_t i, const Coordinate& coord, bool allowRepeated) = 0;
201 
203  virtual bool isEmpty() const = 0;
204 
206  virtual void add(const Coordinate& c) = 0;
207 
208  // Get number of coordinates
209  //virtual int getSize() const=0;
210 
212  //virtual const Coordinate& getAt(std::size_t pos) const=0;
213 
215  virtual void setAt(const Coordinate& c, std::size_t pos) = 0;
216 
218  virtual void deleteAt(std::size_t pos) = 0;
219 
221  virtual std::string toString() const = 0;
222 
224  virtual void setPoints(const std::vector<Coordinate>& v) = 0;
225 
227  bool hasRepeatedPoints() const;
228 
230  const Coordinate* minCoordinate() const;
231 
232 
241  static CoordinateSequence* removeRepeatedPoints(
242  const CoordinateSequence* cl);
243 
245  //
248  virtual CoordinateSequence& removeRepeatedPoints() = 0;
249 
254  static bool hasRepeatedPoints(const CoordinateSequence* cl);
255 
260  static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
261  CoordinateSequence* c);
262 
268  static const Coordinate* minCoordinate(CoordinateSequence* cl);
269 
271  //
275  static size_t indexOf(const Coordinate* coordinate,
276  const CoordinateSequence* cl);
277 
283  static bool equals(const CoordinateSequence* cl1,
284  const CoordinateSequence* cl2);
285 
287  static void scroll(CoordinateSequence* cl, const Coordinate* firstCoordinate);
288 
306  static int increasingDirection(const CoordinateSequence& pts);
307 
309  static void reverse(CoordinateSequence* cl);
310 
312  enum { X, Y, Z, M };
313 
320  virtual std::size_t getDimension() const = 0;
321 
332  virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const = 0;
333 
340  virtual double
341  getX(std::size_t index) const
342  {
343  return getOrdinate(index, X);
344  }
345 
352  virtual double
353  getY(std::size_t index) const
354  {
355  return getOrdinate(index, Y);
356  }
357 
358 
367  virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value) = 0;
368 
376  virtual void expandEnvelope(Envelope& env) const;
377 
378  virtual void apply_rw(const CoordinateFilter* filter) = 0; //Abstract
379  virtual void apply_ro(CoordinateFilter* filter) const = 0; //Abstract
380 
389  template <class T>
390  void
392  {
393  Coordinate c;
394  for(std::size_t i = 0, n = size(); i < n; ++i) {
395  getAt(i, c);
396  f.filter(c);
397  setAt(c, i);
398  }
399  }
400 
401 };
402 
403 GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
404 
405 GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
406 
407 GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
408 
409 } // namespace geos::geom
410 } // namespace geos
411 
412 //#ifdef GEOS_INLINE
413 //# include "geos/geom/CoordinateSequence.inl"
414 //#endif
415 
416 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
void applyCoordinateFilter(T &f)
Apply a fiter to each Coordinate of this sequence. The filter is expected to provide a ...
Definition: CoordinateSequence.h:391
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
const Coordinate & back() const
Return last Coordinate in the sequence.
Definition: CoordinateSequence.h:89
virtual double getY(std::size_t index) const
Definition: CoordinateSequence.h:353
Definition: CoordinateFilter.h:43
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
GEOS_DLL bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
virtual double getX(std::size_t index) const
Definition: CoordinateSequence.h:341
GEOS_DLL bool operator!=(const Coordinate &a, const Coordinate &b)
Inequality operator for Coordinate. 2D only.
const Coordinate & front() const
Return first Coordinate in the sequence.
Definition: CoordinateSequence.h:96