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 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 
109  virtual void getAt(std::size_t i, Coordinate& c) const = 0;
110 
115  virtual std::size_t getSize() const = 0;
116 
117  size_t
118  size() const
119  {
120  return getSize();
121  }
122 
127  virtual void toVector(std::vector<Coordinate>& coords) const = 0;
128 
130  virtual bool isEmpty() const = 0;
131 
133  virtual void setAt(const Coordinate& c, std::size_t pos) = 0;
134 
136  std::string toString() const;
137 
139  virtual void setPoints(const std::vector<Coordinate>& v) = 0;
140 
142  bool hasRepeatedPoints() const;
143 
145  const Coordinate* minCoordinate() const;
146 
151  static bool hasRepeatedPoints(const CoordinateSequence* cl);
152 
157  static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
158  CoordinateSequence* c);
159 
161  //
165  static size_t indexOf(const Coordinate* coordinate,
166  const CoordinateSequence* cl);
167 
173  static bool equals(const CoordinateSequence* cl1,
174  const CoordinateSequence* cl2);
175 
177  static void scroll(CoordinateSequence* cl, const Coordinate* firstCoordinate);
178 
196  static int increasingDirection(const CoordinateSequence& pts);
197 
199  static void reverse(CoordinateSequence* cl);
200 
202  enum { X, Y, Z, M };
203 
210  virtual std::size_t getDimension() const = 0;
211 
222  virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const = 0;
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 
293 GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
294 
295 GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
296 
297 GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
298 
299 } // namespace geos::geom
300 } // namespace geos
301 
302 //#ifdef GEOS_INLINE
303 //# include "geos/geom/CoordinateSequence.inl"
304 //#endif
305 
306 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
void applyCoordinateFilter(T &f)
Apply a filter to each Coordinate of this sequence. The filter is expected to provide a ...
Definition: CoordinateSequence.h:281
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
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:88
virtual double getY(std::size_t index) const
Definition: CoordinateSequence.h:243
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
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:231
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:95