GEOS  3.9.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 #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
34 namespace geos {
35 namespace geom {
36 class GeometryFactory;
37 class Geometry;
38 class Polygon;
39 class MultiPolygon;
40 class Envelope;
41 }
42 namespace index {
43 namespace strtree {
44 class ItemsList;
45 }
46 }
47 }
48 
49 namespace geos {
50 namespace operation { // geos::operation
51 namespace geounion { // geos::operation::geounion
52 
53 
59 class GEOS_DLL ClassicUnionStrategy : public UnionStrategy {
60 
61 public:
62 
64 
70  std::unique_ptr<geom::Geometry> Union(const geom::Geometry*, const geom::Geometry*) override;
71 
81  bool isFloatingPrecision() const override;
82 
83 private:
84 
90  std::unique_ptr<geom::Geometry> unionPolygonsByBuffer(const geom::Geometry* g0, const geom::Geometry* g1);
91 
92 };
93 
94 
95 
112 class GEOS_DLL CascadedPolygonUnion {
113 private:
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 
142 public:
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 
180  static geom::Geometry* Union(const geom::MultiPolygon* polys);
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 
207  geom::Geometry* Union();
208 
209 private:
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
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition: CascadedPolygonUnion.h:189
Definition: MultiPolygon.h:59
Implementation of UnionStrategy that provides overlay using the first generation overlay routines...
Definition: CascadedPolygonUnion.h:59
Definition: UnionStrategy.h:40
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
Provides an efficient method of unioning a collection of polygonal geometries.
Definition: CascadedPolygonUnion.h:112
static geom::Geometry * Union(T start, T end, UnionStrategy *unionStrategy)
Computes the union of a set of polygonal Geometrys.
Definition: CascadedPolygonUnion.h:164