GEOS  3.3.3
CascadedPolygonUnion.h
1 /**********************************************************************
2  * $Id: CascadedPolygonUnion.h 3532 2011-12-09 08:46:21Z strk $
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
8  * Copyright (C) 2006 Refractions Research Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: operation/union/CascadedPolygonUnion.java r487 (JTS-1.12+)
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 {
73 private:
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 
102 public:
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 
139  static geom::Geometry* Union(const geom::MultiPolygon* polys);
140 
148  CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
149  : inputPolys(polys),
150  geomFactory(NULL)
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 
237  static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
238 };
239 
240 } // namespace geos::operation::union
241 } // namespace geos::operation
242 } // namespace geos
243 
244 #endif
245 
246 /**********************************************************************
247  * $Log$
248  *
249  **********************************************************************/
250