GEOS 3.15.0beta1
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#include <geos/util/Progress.h>
29
30// Forward declarations
31namespace geos {
32namespace geom {
33class GeometryFactory;
34class Geometry;
35class Polygon;
36class MultiPolygon;
37class Envelope;
38}
39}
40
41namespace geos {
42namespace operation { // geos::operation
43namespace geounion { // geos::operation::geounion
44
45
51class GEOS_DLL ClassicUnionStrategy : public UnionStrategy {
52
53public:
54
55 ClassicUnionStrategy() {};
56
62 std::unique_ptr<geom::Geometry> Union(const geom::Geometry*, const geom::Geometry*) override;
63
73 bool isFloatingPrecision() const override;
74
75private:
76
82 std::unique_ptr<geom::Geometry> unionPolygonsByBuffer(const geom::Geometry* g0, const geom::Geometry* g1);
83
84};
85
86
87
104class GEOS_DLL CascadedPolygonUnion {
105private:
106 std::vector<geom::Polygon*>* inputPolys;
107 geom::GeometryFactory const* geomFactory;
108
116 static int const STRTREE_NODE_CAPACITY = 4;
117
132 static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
133
134public:
135 CascadedPolygonUnion();
136
143 static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys);
144 static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun, geos::util::ProgressFunction* progressFunction);
145
155 template <class T>
156 static std::unique_ptr<geom::Geometry>
157 Union(T start, T end, UnionStrategy *unionStrategy, geos::util::ProgressFunction* progressFunction)
158 {
159 std::vector<geom::Polygon*> polys;
160 for(T i = start; i != end; ++i) {
161 const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
162 polys.push_back(const_cast<geom::Polygon*>(p));
163 }
164 return Union(&polys, unionStrategy, progressFunction);
165 }
166
174 static std::unique_ptr<geom::Geometry> Union(const geom::MultiPolygon* polys, geos::util::ProgressFunction* progressFunction);
175
183 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
184 : inputPolys(polys)
185 , geomFactory(nullptr)
186 , unionFunction(&defaultUnionFunction)
187 {}
188
189 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun)
190 : inputPolys(polys)
191 , geomFactory(nullptr)
192 , unionFunction(unionFun)
193 {}
194
202 std::unique_ptr<geom::Geometry> Union(geos::util::ProgressFunction* progressFunction);
203
204private:
205
206 UnionStrategy* unionFunction;
207 ClassicUnionStrategy defaultUnionFunction;
208
218 std::unique_ptr<geom::Geometry> binaryUnion(
219 const std::vector<const geom::Geometry*> & geoms,
220 std::size_t start,
221 std::size_t end,
222 std::function<void()>* unitProgress);
223
233 std::unique_ptr<geom::Geometry> unionSafe(const geom::Geometry* g0, const geom::Geometry* g1) const;
234
235 std::unique_ptr<geom::Geometry> unionSafe(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&);
236
244 std::unique_ptr<geom::Geometry> unionActual(const geom::Geometry* g0, const geom::Geometry* g1) const;
245
246 std::unique_ptr<geom::Geometry> unionActual(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&) const;
247};
248
249
250
251
252
253} // namespace geos::operation::union
254} // namespace geos::operation
255} // namespace geos
256
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:72
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:201
Definition MultiPolygon.h:57
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:104
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition CascadedPolygonUnion.h:183
static std::unique_ptr< geom::Geometry > Union(T start, T end, UnionStrategy *unionStrategy, geos::util::ProgressFunction *progressFunction)
Computes the union of a set of polygonal Geometrys.
Definition CascadedPolygonUnion.h:157
std::unique_ptr< geom::Geometry > Union(geos::util::ProgressFunction *progressFunction)
Computes the union of the input geometries.
static std::unique_ptr< geom::Geometry > Union(std::vector< geom::Polygon * > *polys)
Computes the union of a collection of polygonal Geometrys.
static std::unique_ptr< geom::Geometry > Union(const geom::MultiPolygon *polys, geos::util::ProgressFunction *progressFunction)
Computes the union of a collection of polygonal Geometrys.
Implementation of UnionStrategy that provides overlay using the first generation overlay routines.
Definition CascadedPolygonUnion.h:51
std::unique_ptr< geom::Geometry > Union(const geom::Geometry *, const geom::Geometry *) override
Definition UnionStrategy.h:40
Definition Angle.h:26
Classes to perform efficient unioning of collections of geometries.
Definition namespaces.h:286
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
std::function< void(double, const char *)> ProgressFunction
Definition Progress.h:29
Basic namespace for all GEOS functionalities.
Definition geos.h:38