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
26 namespace geos {
27 namespace geom {
28 class Envelope;
29 class CoordinateFilter;
30 class Coordinate;
31 }
32 }
33 
34 namespace geos {
35 namespace geom { // geos::geom
36 
44 class GEOS_DLL CoordinateSequence {
45 
46 protected:
47 
49 
51 
52 public:
53 
54  typedef std::unique_ptr<CoordinateSequence> Ptr;
55 
56  virtual
57  ~CoordinateSequence() {}
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 
145  static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
146  CoordinateSequence* c);
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 
183  static int increasingDirection(const CoordinateSequence& pts);
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 
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 
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:58
virtual double getY(std::size_t index) const
Definition: CoordinateSequence.h:243
const Coordinate & front() const
Return first Coordinate in the sequence.
Definition: CoordinateSequence.h:81
virtual double getX(std::size_t index) const
Definition: CoordinateSequence.h:231
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:41
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
const Coordinate & back() const
Return last Coordinate in the sequence.
Definition: CoordinateSequence.h:74