GEOS  3.11.1
operation/polygonize/EdgeRing.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
7  * Copyright (C) 2001-2002 Vivid Solutions 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  * Last port: operation/polygonize/EdgeRing.java 0b3c7e3eb0d3e
17  *
18  **********************************************************************/
19 
20 #pragma once
21 
22 #include <geos/export.h>
23 #include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
24 #include <geos/operation/polygonize/PolygonizeDirectedEdge.h>
25 #include <geos/geom/Geometry.h>
26 #include <geos/geom/LinearRing.h>
27 #include <geos/geom/Polygon.h>
28 
29 #include <memory>
30 #include <vector>
31 #include <geos/geom/Location.h>
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40 namespace geom {
41 class LineString;
42 class CoordinateSequence;
43 class GeometryFactory;
44 class Coordinate;
45 }
46 namespace planargraph {
47 class DirectedEdge;
48 }
49 }
50 
51 namespace geos {
52 namespace operation { // geos::operation
53 namespace polygonize { // geos::operation::polygonize
54 
59 class GEOS_DLL EdgeRing {
60 private:
61  const geom::GeometryFactory* factory;
62 
63  typedef std::vector<const PolygonizeDirectedEdge*> DeList;
64  DeList deList;
65 
66  // cache the following data for efficiency
67  std::unique_ptr<geom::LinearRing> ring;
68  std::unique_ptr<geom::CoordinateArraySequence> ringPts;
69  std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ringLocator;
70 
71  std::unique_ptr<std::vector<std::unique_ptr<geom::LinearRing>>> holes;
72 
73  EdgeRing* shell = nullptr;
74  bool is_hole;
75  bool is_processed = false;
76  bool is_included_set = false;
77  bool is_included = false;
78  bool visitedByUpdateIncludedRecursive = false;
79 
86  const geom::CoordinateSequence* getCoordinates();
87 
88  static void addEdge(const geom::CoordinateSequence* coords,
89  bool isForward,
91 
93  if (ringLocator == nullptr) {
94  ringLocator.reset(new algorithm::locate::IndexedPointInAreaLocator(*getRingInternal()));
95  }
96  return ringLocator.get();
97  }
98 
99 public:
105  void add(const PolygonizeDirectedEdge* de);
106 
125  EdgeRing* findEdgeRingContaining(const std::vector<EdgeRing*> & erList);
126 
137  static std::vector<PolygonizeDirectedEdge*> findDirEdgesInRing(PolygonizeDirectedEdge* startDE);
138 
149  static const geom::Coordinate& ptNotInList(
150  const geom::CoordinateSequence* testPts,
151  const geom::CoordinateSequence* pts);
152 
161  static bool isInList(const geom::Coordinate& pt,
162  const geom::CoordinateSequence* pts);
163 
164  explicit EdgeRing(const geom::GeometryFactory* newFactory);
165 
166  ~EdgeRing() = default;
167 
168  void build(PolygonizeDirectedEdge* startDE);
169 
170  void computeHole();
171 
179  bool isHole() const {
180  return is_hole;
181  }
182 
183  /* Indicates whether we know if the ring should be included in a polygonizer
184  * output of only polygons.
185  */
186  bool isIncludedSet() const {
187  return is_included_set;
188  }
189 
190  /* Indicates whether the ring should be included in a polygonizer output of
191  * only polygons.
192  */
193  bool isIncluded() const {
194  return is_included;
195  }
196 
197  void setIncluded(bool included) {
198  is_included = included;
199  is_included_set = true;
200  }
201 
202  bool isProcessed() const {
203  return is_processed;
204  }
205 
206  void setProcessed(bool processed) {
207  is_processed = processed;
208  }
209 
215  void setShell(EdgeRing* shellRing) {
216  shell = shellRing;
217  }
218 
224  bool hasShell() const {
225  return shell != nullptr;
226  }
227 
235  return isHole() ? shell : this;
236  }
237 
244  bool isOuterHole() const {
245  if (!isHole()) {
246  return false;
247  }
248 
249  return !hasShell();
250  }
251 
257  bool isOuterShell() const {
258  return getOuterHole() != nullptr;
259  }
260 
270  EdgeRing* getOuterHole() const;
271 
276  void updateIncludedRecursive();
277 
283  void addHole(geom::LinearRing* hole);
284 
285  void addHole(EdgeRing* holeER);
286 
295  std::unique_ptr<geom::Polygon> getPolygon();
296 
301  bool isValid();
302 
311  std::unique_ptr<geom::LineString> getLineString();
312 
320  geom::LinearRing* getRingInternal();
321 
329  std::unique_ptr<geom::LinearRing> getRingOwnership();
330 
331  bool isInRing(const geom::Coordinate & pt) {
332  return geom::Location::EXTERIOR != getLocator()->locate(&pt);
333  }
334 };
335 
336 } // namespace geos::operation::polygonize
337 } // namespace geos::operation
338 } // namespace geos
339 
340 #ifdef _MSC_VER
341 #pragma warning(pop)
342 #endif
343 
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency...
Definition: IndexedPointInAreaLocator.h:54
The default implementation of CoordinateSequence.
Definition: CoordinateArraySequence.h:35
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition: PointOnGeometryLocator.h:36
A DirectedEdge of a PolygonizeGraph, which represents an edge of a polygon formed by the graph...
Definition: PolygonizeDirectedEdge.h:52
void setShell(EdgeRing *shellRing)
Sets the containing shell ring of a ring that has been determined to be a hole.
Definition: operation/polygonize/EdgeRing.h:215
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
EdgeRing * getShell()
Gets the shell for this ring. The shell is the ring itself if it is not a hole, otherwise it is the p...
Definition: operation/polygonize/EdgeRing.h:234
Represents a ring of PolygonizeDirectedEdge which form a ring of a polygon. The ring may be either an...
Definition: operation/polygonize/EdgeRing.h:59
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
bool isHole() const
Tests whether this ring is a hole.
Definition: operation/polygonize/EdgeRing.h:179
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple...
Definition: LinearRing.h:55
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
bool isOuterShell() const
Tests whether this ring is an outer shell.
Definition: operation/polygonize/EdgeRing.h:257
bool isOuterHole() const
Tests whether this ring is an outer hole. A hole is an outer hole if it is not contained by any shell...
Definition: operation/polygonize/EdgeRing.h:244
bool hasShell() const
Tests whether this ring has a shell assigned to it.
Definition: operation/polygonize/EdgeRing.h:224