GEOS 3.6.2
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 * 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
33namespace 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
48namespace geos {
49namespace operation { // geos::operation
50namespace geounion { // geos::operation::geounion
51
71class GEOS_DLL CascadedPolygonUnion
72{
73private:
74 std::vector<geom::Polygon*>* inputPolys;
75 geom::GeometryFactory const* geomFactory;
76
84 static int const STRTREE_NODE_CAPACITY = 4;
85
100 static std::auto_ptr<geom::Geometry> restrictToPolygons(std::auto_ptr<geom::Geometry> g);
101
102public:
103 CascadedPolygonUnion();
104
112 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
113
121 template <class T>
122 static geom::Geometry* 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
140
148 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
149 : inputPolys(polys),
150 geomFactory(NULL)
151 {}
152
160
161private:
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,
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:53
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:67
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:167
Models a collection of Polygons.
Definition MultiPolygon.h:61
Represents a linear polygon, which may include holes.
Definition Polygon.h:67
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Definition CascadedPolygonUnion.h:148
static geom::Geometry * Union(T start, T end)
Definition CascadedPolygonUnion.h:122
static geom::Geometry * Union(std::vector< geom::Polygon * > *polys)
static geom::Geometry * Union(const geom::MultiPolygon *polys)
Helper class holding Geometries, part of which are held by reference others are held exclusively.
Definition GeometryListHolder.h:35
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Contains 2-D and 1-D versions of the Sort-Tile-Recursive (STR) tree, a query-only R-tree.
Definition SIRtreePointInRing.h:32
Provides classes for various kinds of spatial indexes.
Definition IndexedNestedRingTester.h:31
Provides classes for implementing operations on geometries.
Definition IndexedNestedRingTester.h:40
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25