GEOS 3.14.0dev
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#pragma once
22
23#include <vector>
24
25#include <geos/export.h>
26
27#include <geos/operation/union/UnionStrategy.h>
28
29// Forward declarations
30namespace geos {
31namespace geom {
32class GeometryFactory;
33class Geometry;
34class Polygon;
35class MultiPolygon;
36class Envelope;
37}
38}
39
40namespace geos {
41namespace operation { // geos::operation
42namespace geounion { // geos::operation::geounion
43
44
50class GEOS_DLL ClassicUnionStrategy : public UnionStrategy {
51
52public:
53
55
61 std::unique_ptr<geom::Geometry> Union(const geom::Geometry*, const geom::Geometry*) override;
62
72 bool isFloatingPrecision() const override;
73
74private:
75
81 std::unique_ptr<geom::Geometry> unionPolygonsByBuffer(const geom::Geometry* g0, const geom::Geometry* g1);
82
83};
84
85
86
103class GEOS_DLL CascadedPolygonUnion {
104private:
105 std::vector<geom::Polygon*>* inputPolys;
106 geom::GeometryFactory const* geomFactory;
107
115 static int const STRTREE_NODE_CAPACITY = 4;
116
131 static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
132
133public:
135
142 static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys);
143 static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun);
144
153 template <class T>
154 static std::unique_ptr<geom::Geometry>
155 Union(T start, T end, UnionStrategy *unionStrategy)
156 {
157 std::vector<geom::Polygon*> polys;
158 for(T i = start; i != end; ++i) {
159 const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
160 polys.push_back(const_cast<geom::Polygon*>(p));
161 }
162 return Union(&polys, unionStrategy);
163 }
164
171 static std::unique_ptr<geom::Geometry> Union(const geom::MultiPolygon* polys);
172
180 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
181 : inputPolys(polys)
182 , geomFactory(nullptr)
183 , unionFunction(&defaultUnionFunction)
184 {}
185
186 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun)
187 : inputPolys(polys)
188 , geomFactory(nullptr)
189 , unionFunction(unionFun)
190 {}
191
198 std::unique_ptr<geom::Geometry> Union();
199
200private:
201
202 UnionStrategy* unionFunction;
203 ClassicUnionStrategy defaultUnionFunction;
204
214 std::unique_ptr<geom::Geometry> binaryUnion(const std::vector<const geom::Geometry*> & geoms, std::size_t start, std::size_t end);
215
225 std::unique_ptr<geom::Geometry> unionSafe(const geom::Geometry* g0, const geom::Geometry* g1) const;
226
227 std::unique_ptr<geom::Geometry> unionSafe(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&);
228
236 std::unique_ptr<geom::Geometry> unionActual(const geom::Geometry* g0, const geom::Geometry* g1) const;
237
238 std::unique_ptr<geom::Geometry> unionActual(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&) const;
239};
240
241
242
243
244
245} // namespace geos::operation::union
246} // namespace geos::operation
247} // namespace geos
248
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition MultiPolygon.h:58
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Provides an efficient method of unioning a collection of polygonal geometries.
Definition CascadedPolygonUnion.h:103
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition CascadedPolygonUnion.h:180
static std::unique_ptr< geom::Geometry > Union(T start, T end, UnionStrategy *unionStrategy)
Computes the union of a set of polygonal Geometrys.
Definition CascadedPolygonUnion.h:155
static std::unique_ptr< geom::Geometry > Union(std::vector< geom::Polygon * > *polys)
Computes the union of a collection of polygonal Geometrys.
std::unique_ptr< geom::Geometry > Union()
Computes the union of the input geometries.
static std::unique_ptr< 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:50
std::unique_ptr< geom::Geometry > Union(const geom::Geometry *, const geom::Geometry *) override
Definition UnionStrategy.h:40
Basic namespace for all GEOS functionalities.
Definition geos.h:39