GEOS 3.8.1
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
33namespace geos {
34namespace geom {
35class GeometryFactory;
36class Geometry;
37class Polygon;
38class MultiPolygon;
39class Envelope;
40}
41namespace index {
42namespace strtree {
43class ItemsList;
44}
45}
46}
47
48namespace geos {
49namespace operation { // geos::operation
50namespace geounion { // geos::operation::geounion
51
68class GEOS_DLL CascadedPolygonUnion {
69private:
70 std::vector<geom::Polygon*>* inputPolys;
71 geom::GeometryFactory const* geomFactory;
72
80 static int const STRTREE_NODE_CAPACITY = 4;
81
96 static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
97
98public:
100
107 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
108
116 template <class T>
117 static geom::Geometry*
118 Union(T start, T end)
119 {
120 std::vector<geom::Polygon*> polys;
121 for(T i = start; i != end; ++i) {
122 const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
123 polys.push_back(const_cast<geom::Polygon*>(p));
124 }
125 return Union(&polys);
126 }
127
135
143 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
144 : inputPolys(polys),
145 geomFactory(nullptr)
146 {}
147
155
156private:
157 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
158
164 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
165
175 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
176 std::size_t end);
177
185 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
186
196 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
197
205 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
206};
207
208} // namespace geos::operation::union
209} // namespace geos::operation
210} // namespace geos
211
212#endif
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Models a collection of Polygons.
Definition: MultiPolygon.h:59
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Provides an efficient method of unioning a collection of polygonal geometries.
Definition: CascadedPolygonUnion.h:68
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition: CascadedPolygonUnion.h:143
static geom::Geometry * Union(T start, T end)
Computes the union of a set of polygonal Geometrys.
Definition: CascadedPolygonUnion.h:118
geom::Geometry * Union()
Computes the union of the input geometries.
static geom::Geometry * Union(std::vector< geom::Polygon * > *polys)
Computes the union of a collection of polygonal Geometrys.
static geom::Geometry * Union(const geom::MultiPolygon *polys)
Computes the union of a collection of polygonal Geometrys.
Helper class holding Geometries, part of which are held by reference others are held exclusively.
Definition: GeometryListHolder.h:34
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25