GEOS 3.9.1
CascadedUnion.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://trac.osgeo.org/geos
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: ORIGINAL WORK, generalization of CascadedPolygonUnion
16 *
17 **********************************************************************/
18
19#ifndef GEOS_OP_UNION_CASCADEDUNION_H
20#define GEOS_OP_UNION_CASCADEDUNION_H
21
22#include <geos/export.h>
23
24#include <vector>
25#include <algorithm>
26
27#include "GeometryListHolder.h"
28
29// Forward declarations
30namespace geos {
31namespace geom {
32class GeometryFactory;
33class Geometry;
34class Geometry;
35class Envelope;
36}
37namespace index {
38namespace strtree {
39class ItemsList;
40}
41}
42}
43
44namespace geos {
45namespace operation { // geos::operation
46namespace geounion { // geos::operation::geounion
47
55class GEOS_DLL CascadedUnion {
56private:
57 const std::vector<geom::Geometry*>* inputGeoms;
58 geom::GeometryFactory const* geomFactory;
59
67 static int const STRTREE_NODE_CAPACITY = 4;
68
69public:
71
78 static geom::Geometry* Union(std::vector<geom::Geometry*>* geoms);
79
87 template <class T>
88 static geom::Geometry*
89 Union(T start, T end)
90 {
91 std::vector<geom::Geometry*> polys;
92 for(T i = start; i != end; ++i) {
93 const geom::Geometry* p = dynamic_cast<const geom::Geometry*>(*i);
94 polys.push_back(const_cast<geom::Geometry*>(p));
95 }
96 return Union(&polys);
97 }
98
106 CascadedUnion(const std::vector<geom::Geometry*>* geoms)
107 : inputGeoms(geoms),
108 geomFactory(nullptr)
109 {}
110
118
119private:
120 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
121
127 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
128
138 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
139 std::size_t end);
140
148 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
149
159 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
160
161 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
162
179 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
180 geom::Geometry* g1, geom::Envelope const& common);
181
182 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
183 geom::Geometry* geom, std::vector<const geom::Geometry*>& disjointGeoms);
184
192 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
193};
194
195} // namespace geos::operation::union
196} // namespace geos::operation
197} // namespace geos
198
199#endif
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
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
Provides an efficient method of unioning a collection of Geometries.
Definition: CascadedUnion.h:55
CascadedUnion(const std::vector< geom::Geometry * > *geoms)
Definition: CascadedUnion.h:106
static geom::Geometry * Union(std::vector< geom::Geometry * > *geoms)
static geom::Geometry * Union(T start, T end)
Definition: CascadedUnion.h:89
Helper class holding Geometries, part of which are held by reference others are held exclusively.
Definition: GeometryListHolder.h:34
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26