00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOS_OP_UNION_CASCADEDUNION_H
00020 #define GEOS_OP_UNION_CASCADEDUNION_H
00021
00022 #include <geos/export.h>
00023
00024 #include <vector>
00025 #include <algorithm>
00026
00027 #include "GeometryListHolder.h"
00028
00029
00030 namespace geos {
00031 namespace geom {
00032 class GeometryFactory;
00033 class Geometry;
00034 class Geometry;
00035 class Envelope;
00036 }
00037 namespace index {
00038 namespace strtree {
00039 class ItemsList;
00040 }
00041 }
00042 }
00043
00044 namespace geos {
00045 namespace operation {
00046 namespace geounion {
00047
00055 class GEOS_DLL CascadedUnion
00056 {
00057 private:
00058 const std::vector<geom::Geometry*>* inputGeoms;
00059 geom::GeometryFactory const* geomFactory;
00060
00068 static int const STRTREE_NODE_CAPACITY = 4;
00069
00070 public:
00071 CascadedUnion();
00072
00079 static geom::Geometry* Union(std::vector<geom::Geometry*>* geoms);
00080
00088 template <class T>
00089 static geom::Geometry* Union(T start, T end)
00090 {
00091 std::vector<geom::Geometry*> polys;
00092 for (T i=start; i!=end; ++i) {
00093 const geom::Geometry* p = dynamic_cast<const geom::Geometry*>(*i);
00094 polys.push_back(const_cast<geom::Geometry*>(p));
00095 }
00096 return Union(&polys);
00097 }
00098
00106 CascadedUnion(const std::vector<geom::Geometry*>* geoms)
00107 : inputGeoms(geoms),
00108 geomFactory(NULL)
00109 {}
00110
00117 geom::Geometry* Union();
00118
00119 private:
00120 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
00121
00127 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
00128
00138 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
00139 std::size_t end);
00140
00148 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
00149
00159 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
00160
00161 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
00162
00179 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
00180 geom::Geometry* g1, geom::Envelope const& common);
00181
00182 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
00183 geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
00184
00192 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
00193 };
00194
00195 }
00196 }
00197 }
00198
00199 #endif