GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

CascadedPolygonUnion.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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 *
18 **********************************************************************/
19
20 #ifndef GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
21 #define GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
22
23 #include <geos/export.h>
24
25 #include <vector>
26 #include <algorithm>
27 #include <memory>
28
29 #include "GeometryListHolder.h"
30
31 // Forward declarations
32 namespace geos {
33 namespace geom {
34 class GeometryFactory;
35 class Geometry;
36 class Polygon;
37 class MultiPolygon;
38 class Envelope;
39 }
40 namespace index {
41 namespace strtree {
42 class ItemsList;
43 }
44 }
45 }
46
47 namespace geos {
48 namespace operation { // geos::operation
49 namespace geounion { // geos::operation::geounion
50
70 class GEOS_DLL CascadedPolygonUnion
71 {
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::auto_ptr<geom::Geometry> restrictToPolygons(std::auto_ptr<geom::Geometry> g);
100
101 public:
102 CascadedPolygonUnion();
103
111 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
112
120 template <class T>
121 static geom::Geometry* Union(T start, T end)
122 {
123 std::vector<geom::Polygon*> polys;
124 for (T i=start; i!=end; ++i) {
125 const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
126 polys.push_back(const_cast<geom::Polygon*>(p));
127 }
128 return Union(&polys);
129 }
130
138 static geom::Geometry* Union(const geom::MultiPolygon* polys);
139
147 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
148 : inputPolys(polys),
149 geomFactory(NULL)
150 {}
151
158 geom::Geometry* Union();
159
160 private:
161 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
162
168 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
169
179 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
180 std::size_t end);
181
189 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
190
200 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
201
202 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
203
223 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
224 geom::Geometry* g1, geom::Envelope const& common);
225
226 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
227 geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
228
236 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
237 };
238
239 } // namespace geos::operation::union
240 } // namespace geos::operation
241 } // namespace geos
242
243 #endif