GEOS  3.9.0dev
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.
12  *
13  **********************************************************************
14  *
15  * Last port: ORIGINAL WORK, generalization of CascadedPolygonUnion
16  *
17  **********************************************************************/
18
21
22 #include <geos/export.h>
23
24 #include <vector>
25 #include <algorithm>
26
27 #include "GeometryListHolder.h"
28
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32 class GeometryFactory;
33 class Geometry;
34 class Geometry;
35 class Envelope;
36 }
37 namespace index {
38 namespace strtree {
39 class ItemsList;
40 }
41 }
42 }
43
44 namespace geos {
45 namespace operation { // geos::operation
46 namespace geounion { // geos::operation::geounion
47
56 private:
57  const std::vector<geom::Geometry*>* inputGeoms;
58  geom::GeometryFactory const* geomFactory;
59
67  static int const STRTREE_NODE_CAPACITY = 4;
68
69 public:
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
107  : inputGeoms(geoms),
108  geomFactory(nullptr)
109  {}
110
117  geom::Geometry* Union();
118
119 private:
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
static geom::Geometry * Union(T start, T end)