00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00021 #define GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00022
00023 #include <vector>
00024 #include <algorithm>
00025
00026
00027 namespace geos {
00028 namespace geom {
00029 class GeometryFactory;
00030 class Geometry;
00031 class Polygon;
00032 class MultiPolygon;
00033 class Envelope;
00034 }
00035 namespace index {
00036 namespace strtree {
00037 class ItemsList;
00038 }
00039 }
00040 }
00041
00042 namespace geos {
00043 namespace operation {
00044 namespace geounion {
00045
00050 class GeometryListHolder : public std::vector<geom::Geometry*>
00051 {
00052 private:
00053 typedef std::vector<geom::Geometry*> base_type;
00054
00055 public:
00056 GeometryListHolder() {}
00057 ~GeometryListHolder()
00058 {
00059 std::for_each(ownedItems.begin(), ownedItems.end(),
00060 &GeometryListHolder::deleteItem);
00061 }
00062
00063
00064 void push_back_owned(geom::Geometry* item)
00065 {
00066 this->base_type::push_back(item);
00067 ownedItems.push_back(item);
00068 }
00069
00070 geom::Geometry* getGeometry(std::size_t index)
00071 {
00072 if (index >= this->base_type::size())
00073 return NULL;
00074 return (*this)[index];
00075 }
00076
00077 private:
00078 static void deleteItem(geom::Geometry* item);
00079
00080 private:
00081 std::vector<geom::Geometry*> ownedItems;
00082 };
00083
00103 class CascadedPolygonUnion
00104 {
00105 private:
00106 std::vector<geom::Polygon*>* inputPolys;
00107 geom::GeometryFactory const* geomFactory;
00108
00116 static int const STRTREE_NODE_CAPACITY = 4;
00117
00118 public:
00119 CascadedPolygonUnion();
00120
00127 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
00128
00135 static geom::Geometry* Union(const geom::MultiPolygon* polys);
00136
00143 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
00144 : inputPolys(polys),
00145 geomFactory(NULL)
00146 {}
00147
00154 geom::Geometry* Union();
00155
00156 private:
00157 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
00158
00164 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
00165
00175 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
00176 std::size_t end);
00177
00185 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
00186
00196 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
00197
00198 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
00199
00214 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
00215 geom::Geometry* g1, geom::Envelope const& common);
00216
00217 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
00218 geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
00219
00227 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
00228 };
00229
00230 }
00231 }
00232 }
00233
00234 #endif
00235
00236
00237
00238
00239
00240