GEOS 3.9.1
CascadedPolygonUnion.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2006 Refractions Research 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/union/CascadedPolygonUnion.java r487 (JTS-1.12+)
17 * Includes custom code to deal with https://trac.osgeo.org/geos/ticket/837
18 *
19 **********************************************************************/
20
21#ifndef GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
22#define GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
23
24#include <geos/export.h>
25
26#include <vector>
27#include <algorithm>
28#include <memory>
29
30#include <geos/operation/union/GeometryListHolder.h>
31#include <geos/operation/union/UnionStrategy.h>
32
33// Forward declarations
34namespace geos {
35namespace geom {
36class GeometryFactory;
37class Geometry;
38class Polygon;
39class MultiPolygon;
40class Envelope;
41}
42namespace index {
43namespace strtree {
44class ItemsList;
45}
46}
47}
48
49namespace geos {
50namespace operation { // geos::operation
51namespace geounion { // geos::operation::geounion
52
53
59class GEOS_DLL ClassicUnionStrategy : public UnionStrategy {
60
61public:
62
64
70 std::unique_ptr<geom::Geometry> Union(const geom::Geometry*, const geom::Geometry*) override;
71
81 bool isFloatingPrecision() const override;
82
83private:
84
90 std::unique_ptr<geom::Geometry> unionPolygonsByBuffer(const geom::Geometry* g0, const geom::Geometry* g1);
91
92};
93
94
95
112class GEOS_DLL CascadedPolygonUnion {
113private:
114 std::vector<geom::Polygon*>* inputPolys;
115 geom::GeometryFactory const* geomFactory;
116
124 static int const STRTREE_NODE_CAPACITY = 4;
125
140 static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
141
142public:
144
151 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
152 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun);
153
162 template <class T>
163 static geom::Geometry*
164 Union(T start, T end, UnionStrategy *unionStrategy)
165 {
166 std::vector<geom::Polygon*> polys;
167 for(T i = start; i != end; ++i) {
168 const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
169 polys.push_back(const_cast<geom::Polygon*>(p));
170 }
171 return Union(&polys, unionStrategy);
172 }
173
181
189 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
190 : inputPolys(polys)
191 , geomFactory(nullptr)
192 , unionFunction(&defaultUnionFunction)
193 {}
194
195 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun)
196 : inputPolys(polys)
197 , geomFactory(nullptr)
198 , unionFunction(unionFun)
199 {}
200
208
209private:
210
211 UnionStrategy* unionFunction;
212 ClassicUnionStrategy defaultUnionFunction;
213
214 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
215
221 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
222
232 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
233 std::size_t end);
234
242 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
243
253 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
254
262 geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
263};
264
265
266
267
268
269} // namespace geos::operation::union
270} // namespace geos::operation
271} // namespace geos
272
273#endif
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Definition: MultiPolygon.h:59
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Provides an efficient method of unioning a collection of polygonal geometries.
Definition: CascadedPolygonUnion.h:112
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition: CascadedPolygonUnion.h:189
geom::Geometry * Union()
Computes the union of the input geometries.
static geom::Geometry * Union(T start, T end, UnionStrategy *unionStrategy)
Computes the union of a set of polygonal Geometrys.
Definition: CascadedPolygonUnion.h:164
static geom::Geometry * Union(std::vector< geom::Polygon * > *polys)
Computes the union of a collection of polygonal Geometrys.
static geom::Geometry * Union(const geom::MultiPolygon *polys)
Computes the union of a collection of polygonal Geometrys.
Implementation of UnionStrategy that provides overlay using the first generation overlay routines.
Definition: CascadedPolygonUnion.h:59
std::unique_ptr< geom::Geometry > Union(const geom::Geometry *, const geom::Geometry *) override
Helper class holding Geometries, part of which are held by reference others are held exclusively.
Definition: GeometryListHolder.h:34
Definition: UnionStrategy.h:40
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26