00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00022 #define GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00023
00024 #include <geos/export.h>
00025
00026 #include <vector>
00027 #include <algorithm>
00028 #include <memory>
00029
00030 #include "GeometryListHolder.h"
00031
00032
00033 namespace geos {
00034 namespace geom {
00035 class GeometryFactory;
00036 class Geometry;
00037 class Polygon;
00038 class MultiPolygon;
00039 class Envelope;
00040 }
00041 namespace index {
00042 namespace strtree {
00043 class ItemsList;
00044 }
00045 }
00046 }
00047
00048 namespace geos {
00049 namespace operation {
00050 namespace geounion {
00051
00071 class GEOS_DLL CascadedPolygonUnion
00072 {
00073 private:
00074 std::vector<geom::Polygon*>* inputPolys;
00075 geom::GeometryFactory const* geomFactory;
00076
00084 static int const STRTREE_NODE_CAPACITY = 4;
00085
00100 static std::auto_ptr<geom::Geometry> restrictToPolygons(std::auto_ptr<geom::Geometry> g);
00101
00102 public:
00103 CascadedPolygonUnion();
00104
00112 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
00113
00121 template <class T>
00122 static geom::Geometry* Union(T start, T end)
00123 {
00124 std::vector<geom::Polygon*> polys;
00125 for (T i=start; i!=end; ++i) {
00126 const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
00127 polys.push_back(const_cast<geom::Polygon*>(p));
00128 }
00129 return Union(&polys);
00130 }
00131
00139 static geom::Geometry* Union(const geom::MultiPolygon* polys);
00140
00148 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
00149 : inputPolys(polys),
00150 geomFactory(NULL)
00151 {}
00152
00159 geom::Geometry* Union();
00160
00161 private:
00162 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
00163
00169 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
00170
00180 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
00181 std::size_t end);
00182
00190 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
00191
00201 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
00202
00203 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
00204
00224 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
00225 geom::Geometry* g1, geom::Envelope const& common);
00226
00227 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
00228 geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
00229
00230 void extractByEnvelope(geom::Envelope const& env,
00231 geom::Geometry* geom,
00232 std::vector<geom::Geometry*>& intersectingGeoms,
00233 std::vector<geom::Geometry*>& disjointGeoms);
00234
00235 void extractByEnvelope(geom::Envelope const& env,
00236 std::vector<geom::Geometry*>& sourceGeoms,
00237 std::vector<geom::Geometry*>& intersectingGeoms,
00238 std::vector<geom::Geometry*>& disjointGeoms);
00239
00247 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
00248 };
00249
00250 }
00251 }
00252 }
00253
00254 #endif