GEOS  3.13.0dev
Polygonizer.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2010 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: operation/polygonize/Polygonizer.java 0b3c7e3eb0d3e
18  *
19  **********************************************************************/
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 #include <geos/geom/Polygon.h>
25 #include <geos/geom/GeometryComponentFilter.h> // for LineStringAdder inheritance
26 #include <geos/operation/polygonize/PolygonizeGraph.h>
27 
28 #include <memory>
29 #include <vector>
30 
31 #ifdef _MSC_VER
32 #pragma warning(push)
33 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34 #endif
35 
36 // Forward declarations
37 namespace geos {
38 namespace geom {
39 class Geometry;
40 
41 class LineString;
42 
43 class Polygon;
44 }
45 namespace operation {
46 namespace polygonize {
47 class EdgeRing;
48 }
49 }
50 }
51 
52 namespace geos {
53 namespace operation { // geos::operation
54 namespace polygonize { // geos::operation::polygonize
55 
82 class GEOS_DLL Polygonizer {
83 private:
87  class GEOS_DLL LineStringAdder: public geom::GeometryComponentFilter {
88  public:
89  Polygonizer* pol;
90  explicit LineStringAdder(Polygonizer* p);
91  //void filter_rw(geom::Geometry *g);
92  void filter_ro(const geom::Geometry* g) override;
93  };
94 
95  // default factory
96  LineStringAdder lineStringAdder;
97 
103  void add(const geom::LineString* line);
104 
108  void polygonize();
109 
110  static void findValidRings(const std::vector<EdgeRing*>& edgeRingList,
111  std::vector<EdgeRing*>& validEdgeRingList,
112  std::vector<EdgeRing*>& invalidRingList);
113 
119  std::vector<std::unique_ptr<geom::LineString>> extractInvalidLines(
120  std::vector<EdgeRing*>& invalidRings);
121 
137  bool isIncludedInvalid(EdgeRing* invalidRing);
138 
139  void findShellsAndHoles(const std::vector<EdgeRing*>& edgeRingList);
140 
141  void findDisjointShells();
142 
143  static void findOuterShells(std::vector<EdgeRing*>& shellList);
144 
145  static std::vector<std::unique_ptr<geom::Polygon>> extractPolygons(std::vector<EdgeRing*> & shellList, bool includeAll);
146 
147  bool extractOnlyPolygonal;
148  bool computed;
149 
150 protected:
151 
152  std::unique_ptr<PolygonizeGraph> graph;
153 
154  // initialize with empty collections, in case nothing is computed
155  std::vector<const geom::LineString*> dangles;
156  std::vector<const geom::LineString*> cutEdges;
157  std::vector<std::unique_ptr<geom::LineString>> invalidRingLines;
158 
159  std::vector<EdgeRing*> holeList;
160  std::vector<EdgeRing*> shellList;
161  std::vector<std::unique_ptr<geom::Polygon>> polyList;
162 
163 public:
164 
171  explicit Polygonizer(bool onlyPolygonal = false);
172 
173  ~Polygonizer() = default;
174 
183  void add(std::vector<geom::Geometry*>* geomList);
184 
193  void add(std::vector<const geom::Geometry*>* geomList);
194 
203  void add(geom::Geometry* g);
204 
213  void add(const geom::Geometry* g);
214 
222  std::vector<std::unique_ptr<geom::Polygon>> getPolygons();
223 
231  const std::vector<const geom::LineString*>& getDangles();
232 
233  bool hasDangles();
234 
242  const std::vector<const geom::LineString*>& getCutEdges();
243 
244  bool hasCutEdges();
245 
254  const std::vector<std::unique_ptr<geom::LineString>>& getInvalidRingLines();
255 
256  bool hasInvalidRingLines();
257 
258  bool allInputsFormPolygons();
259 
260 // This seems to be needed by GCC 2.95.4
261  friend class Polygonizer::LineStringAdder;
262 };
263 
264 } // namespace geos::operation::polygonize
265 } // namespace geos::operation
266 } // namespace geos
267 
268 #ifdef _MSC_VER
269 #pragma warning(pop)
270 #endif
Definition: GeometryComponentFilter.h:41
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineString.h:65
Represents a ring of PolygonizeDirectedEdge which form a ring of a polygon. The ring may be either an...
Definition: operation/polygonize/EdgeRing.h:59
Polygonizes a set of Geometrys which contain linework that represents the edges of a planar graph.
Definition: Polygonizer.h:82
void add(std::vector< const geom::Geometry * > *geomList)
Add a collection of geometries to be polygonized. May be called multiple times. Any dimension of Geom...
const std::vector< const geom::LineString * > & getDangles()
Get the list of dangling lines found during polygonization.
Polygonizer(bool onlyPolygonal=false)
Create a Polygonizer with the same GeometryFactory as the input Geometrys.
void add(const geom::Geometry *g)
const std::vector< std::unique_ptr< geom::LineString > > & getInvalidRingLines()
Get the list of lines forming invalid rings found during polygonization.
const std::vector< const geom::LineString * > & getCutEdges()
Get the list of cut edges found during polygonization.
std::vector< std::unique_ptr< geom::Polygon > > getPolygons()
Gets the list of polygons formed by the polygonization.
void add(std::vector< geom::Geometry * > *geomList)
Add a collection of geometries to be polygonized. May be called multiple times. Any dimension of Geom...
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25