00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00016 #define GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00017
00018 #include <vector>
00019 #include <algorithm>
00020
00021
00022 namespace geos {
00023 namespace geom {
00024 class GeometryFactory;
00025 class Geometry;
00026 class Polygon;
00027 class MultiPolygon;
00028 class Envelope;
00029 }
00030 namespace index {
00031 namespace strtree {
00032 class ItemsList;
00033 }
00034 }
00035 }
00036
00037 namespace geos {
00038 namespace operation {
00039 namespace geounion {
00040
00045 class GeometryListHolder : public std::vector<geom::Geometry*>
00046 {
00047 private:
00048 typedef std::vector<geom::Geometry*> base_type;
00049
00050 public:
00051 GeometryListHolder() {}
00052 ~GeometryListHolder()
00053 {
00054 std::for_each(ownedItems.begin(), ownedItems.end(),
00055 &GeometryListHolder::deleteItem);
00056 }
00057
00058
00059 void push_back_owned(geom::Geometry* item)
00060 {
00061 this->base_type::push_back(item);
00062 ownedItems.push_back(item);
00063 }
00064
00065 geom::Geometry* getGeometry(std::size_t index)
00066 {
00067 if (index >= this->base_type::size())
00068 return NULL;
00069 return (*this)[index];
00070 }
00071
00072 private:
00073 static void deleteItem(geom::Geometry* item);
00074
00075 private:
00076 std::vector<geom::Geometry*> ownedItems;
00077 };
00078
00098 class CascadedPolygonUnion
00099 {
00100 private:
00101 std::vector<geom::Polygon*>* inputPolys;
00102 geom::GeometryFactory const* geomFactory;
00103
00111 static int const STRTREE_NODE_CAPACITY = 4;
00112
00113 public:
00114 CascadedPolygonUnion();
00115
00122 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
00123
00130 static geom::Geometry* Union(const geom::MultiPolygon* polys);
00131
00138 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
00139 : inputPolys(polys),
00140 geomFactory(NULL)
00141 {}
00142
00149 geom::Geometry* Union();
00150
00151 private:
00152 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
00153
00159 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
00160
00170 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
00171 std::size_t end);
00172
00180 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
00181
00191 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
00192
00193 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
00194
00209 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
00210 geom::Geometry* g1, geom::Envelope const& common);
00211
00212 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
00213 geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
00214
00222 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
00223 };
00224
00225 }
00226 }
00227 }
00228
00229 #endif
00230
00231
00232
00233
00234
00235