GEOS  3.8.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 "GeometryListHolder.h"
31 
32 // Forward declarations
33 namespace geos {
34 namespace geom {
35 class GeometryFactory;
36 class Geometry;
37 class Polygon;
38 class MultiPolygon;
39 class Envelope;
40 }
41 namespace index {
42 namespace strtree {
43 class ItemsList;
44 }
45 }
46 }
47 
48 namespace geos {
49 namespace operation { // geos::operation
50 namespace geounion { // geos::operation::geounion
51 
71 class GEOS_DLL CascadedPolygonUnion {
72 private:
73  std::vector<geom::Polygon*>* inputPolys;
74  geom::GeometryFactory const* geomFactory;
75 
83  static int const STRTREE_NODE_CAPACITY = 4;
84 
99  static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
100 
101 public:
103 
111  static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
112 
120  template <class T>
121  static geom::Geometry*
122  Union(T start, T end)
123  {
124  std::vector<geom::Polygon*> polys;
125  for(T i = start; i != end; ++i) {
126  const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
127  polys.push_back(const_cast<geom::Polygon*>(p));
128  }
129  return Union(&polys);
130  }
131 
139  static geom::Geometry* Union(const geom::MultiPolygon* polys);
140 
148  CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
149  : inputPolys(polys),
150  geomFactory(nullptr)
151  {}
152 
159  geom::Geometry* Union();
160 
161 private:
162  geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
163 
169  geom::Geometry* binaryUnion(GeometryListHolder* geoms);
170 
180  geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
181  std::size_t end);
182 
190  GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
191 
201  geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
202 
203  geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
204 
224  geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
225  geom::Geometry* g1, geom::Envelope const& common);
226 
227  geom::Geometry* extractByEnvelope(geom::Envelope const& env,
228  geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
229 
230  void extractByEnvelope(geom::Envelope const& env,
231  geom::Geometry* geom,
232  std::vector<geom::Geometry*>& intersectingGeoms,
233  std::vector<geom::Geometry*>& disjointGeoms);
234 
235  void extractByEnvelope(geom::Envelope const& env,
236  std::vector<geom::Geometry*>& sourceGeoms,
237  std::vector<geom::Geometry*>& intersectingGeoms,
238  std::vector<geom::Geometry*>& disjointGeoms);
239 
247  static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
248 };
249 
250 } // namespace geos::operation::union
251 } // namespace geos::operation
252 } // namespace geos
253 
254 #endif
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Definition: CascadedPolygonUnion.h:148
Models a collection of Polygons.
Definition: MultiPolygon.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:187
Represents a linear polygon, which may include holes.
Definition: Polygon.h:65
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
static geom::Geometry * Union(T start, T end)
Definition: CascadedPolygonUnion.h:122
Provides an efficient method of unioning a collection of Polygonal geometries. This algorithm is fast...
Definition: CascadedPolygonUnion.h:71
Helper class holding Geometries, part of which are held by reference others are held exclusively...
Definition: GeometryListHolder.h:34