GEOS 3.8.1
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#ifndef GEOS_OP_POLYGONIZE_POLYGONIZER_H
22#define GEOS_OP_POLYGONIZE_POLYGONIZER_H
23
24#include <geos/export.h>
25#include <geos/geom/Polygon.h>
26#include <geos/geom/GeometryComponentFilter.h> // for LineStringAdder inheritance
27#include <geos/operation/polygonize/PolygonizeGraph.h>
28
29#include <memory>
30#include <vector>
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37// Forward declarations
38namespace geos {
39namespace geom {
40class Geometry;
41
42class LineString;
43
44class Polygon;
45}
46namespace operation {
47namespace polygonize {
48class EdgeRing;
49}
50}
51}
52
53namespace geos {
54namespace operation { // geos::operation
55namespace polygonize { // geos::operation::polygonize
56
83class GEOS_DLL Polygonizer {
84private:
88 class GEOS_DLL LineStringAdder: public geom::GeometryComponentFilter {
89 public:
90 Polygonizer* pol;
91 explicit LineStringAdder(Polygonizer* p);
92 //void filter_rw(geom::Geometry *g);
93 void filter_ro(const geom::Geometry* g) override;
94 };
95
96 // default factory
97 LineStringAdder lineStringAdder;
98
104 void add(const geom::LineString* line);
105
109 void polygonize();
110
111 static void findValidRings(const std::vector<EdgeRing*>& edgeRingList,
112 std::vector<EdgeRing*>& validEdgeRingList,
113 std::vector<std::unique_ptr<geom::LineString>>& invalidRingList);
114
115 void findShellsAndHoles(const std::vector<EdgeRing*>& edgeRingList);
116
117 void findDisjointShells();
118
119 static void findOuterShells(std::vector<EdgeRing*>& shellList);
120
121 static std::unique_ptr<std::vector<std::unique_ptr<geom::Polygon>>> extractPolygons(std::vector<EdgeRing*> & shellList, bool includeAll);
122
123 bool extractOnlyPolygonal;
124
125protected:
126
127 std::unique_ptr<PolygonizeGraph> graph;
128
129 // initialize with empty collections, in case nothing is computed
130 std::vector<const geom::LineString*> dangles;
131 std::vector<const geom::LineString*> cutEdges;
132 std::vector<std::unique_ptr<geom::LineString>> invalidRingLines;
133
134 std::vector<EdgeRing*> holeList;
135 std::vector<EdgeRing*> shellList;
136 std::unique_ptr<std::vector<std::unique_ptr<geom::Polygon>>> polyList;
137
138public:
139
146 explicit Polygonizer(bool onlyPolygonal = false);
147
148 ~Polygonizer() = default;
149
158 void add(std::vector<geom::Geometry*>* geomList);
159
168 void add(std::vector<const geom::Geometry*>* geomList);
169
179
188 void add(const geom::Geometry* g);
189
197 std::unique_ptr<std::vector<std::unique_ptr<geom::Polygon>>> getPolygons();
198
206 const std::vector<const geom::LineString*>& getDangles();
207
208 bool hasDangles();
209
217 const std::vector<const geom::LineString*>& getCutEdges();
218
219 bool hasCutEdges();
220
229 const std::vector<std::unique_ptr<geom::LineString>>& getInvalidRingLines();
230
231 bool hasInvalidRingLines();
232
233 bool allInputsFormPolygons();
234
235// This seems to be needed by GCC 2.95.4
236 friend class Polygonizer::LineStringAdder;
237};
238
239} // namespace geos::operation::polygonize
240} // namespace geos::operation
241} // namespace geos
242
243#ifdef _MSC_VER
244#pragma warning(pop)
245#endif
246
247#endif // GEOS_OP_POLYGONIZE_POLYGONIZER_H
Definition: GeometryComponentFilter.h:43
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Definition: LineString.h:68
Polygonizes a set of Geometrys which contain linework that represents the edges of a planar graph.
Definition: Polygonizer.h:83
const std::vector< const geom::LineString * > & getDangles()
Get the list of dangling lines found during polygonization.
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...
Polygonizer(bool onlyPolygonal=false)
Create a Polygonizer with the same GeometryFactory as the input Geometrys.
const std::vector< std::unique_ptr< geom::LineString > > & getInvalidRingLines()
Get the list of lines forming invalid rings found during polygonization.
void add(const geom::Geometry *g)
const std::vector< const geom::LineString * > & getCutEdges()
Get the list of cut edges found during polygonization.
std::unique_ptr< 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: IndexedNestedRingTester.h:25