Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

CascadedPolygonUnion.h

00001 /**********************************************************************
00002  * $Id: CascadedPolygonUnion.h 2571 2009-06-08 21:53:35Z strk $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2006 Refractions Research Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************
00015  *
00016  * Last port: operation/union/CascadedPolygonUnion.java rev 1.10 (JTS-1.10)
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 // Forward declarations
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 { // geos::operation
00044 namespace geounion {  // geos::operation::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     // items need to be deleted in the end
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 } // namespace geos::operation::union
00231 } // namespace geos::operation
00232 } // namespace geos
00233 
00234 #endif
00235 
00236 /**********************************************************************
00237  * $Log$
00238  *
00239  **********************************************************************/
00240 

Generated on Thu Jun 11 06:17:00 2009 for GEOS by  doxygen 1.4.4