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 #include <geos/export.h>
00023
00024 #include <vector>
00025 #include <algorithm>
00026
00027
00028 namespace geos {
00029 namespace geom {
00030 class GeometryFactory;
00031 class Geometry;
00032 class Polygon;
00033 class MultiPolygon;
00034 class Envelope;
00035 }
00036 namespace index {
00037 namespace strtree {
00038 class ItemsList;
00039 }
00040 }
00041 }
00042
00043 namespace geos {
00044 namespace operation {
00045 namespace geounion {
00046
00051 class GeometryListHolder : public std::vector<geom::Geometry*>
00052 {
00053 private:
00054 typedef std::vector<geom::Geometry*> base_type;
00055
00056 public:
00057 GeometryListHolder() {}
00058 ~GeometryListHolder()
00059 {
00060 std::for_each(ownedItems.begin(), ownedItems.end(),
00061 &GeometryListHolder::deleteItem);
00062 }
00063
00064
00065 void push_back_owned(geom::Geometry* item)
00066 {
00067 this->base_type::push_back(item);
00068 ownedItems.push_back(item);
00069 }
00070
00071 geom::Geometry* getGeometry(std::size_t index)
00072 {
00073 if (index >= this->base_type::size())
00074 return NULL;
00075 return (*this)[index];
00076 }
00077
00078 private:
00079 static void deleteItem(geom::Geometry* item);
00080
00081 private:
00082 std::vector<geom::Geometry*> ownedItems;
00083 };
00084
00104 class GEOS_DLL CascadedPolygonUnion
00105 {
00106 private:
00107 std::vector<geom::Polygon*>* inputPolys;
00108 geom::GeometryFactory const* geomFactory;
00109
00117 static int const STRTREE_NODE_CAPACITY = 4;
00118
00119 public:
00120 CascadedPolygonUnion();
00121
00128 static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
00129
00136 static geom::Geometry* Union(const geom::MultiPolygon* polys);
00137
00144 CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
00145 : inputPolys(polys),
00146 geomFactory(NULL)
00147 {}
00148
00155 geom::Geometry* Union();
00156
00157 private:
00158 geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
00159
00165 geom::Geometry* binaryUnion(GeometryListHolder* geoms);
00166
00176 geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
00177 std::size_t end);
00178
00186 GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
00187
00197 geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
00198
00199 geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
00200
00215 geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
00216 geom::Geometry* g1, geom::Envelope const& common);
00217
00218 geom::Geometry* extractByEnvelope(geom::Envelope const& env,
00219 geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
00220
00228 static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
00229 };
00230
00231 }
00232 }
00233 }
00234
00235 #endif
00236
00237
00238
00239
00240
00241