CascadedPolygonUnion.h

00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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 r487 (JTS-1.12+)
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00021 #define GEOS_OP_UNION_CASCADEDPOLYGONUNION_H
00022 
00023 #include <geos/export.h>
00024 
00025 #include <vector>
00026 #include <algorithm>
00027 #include <memory>
00028 
00029 #include "GeometryListHolder.h"
00030 
00031 // Forward declarations
00032 namespace geos {
00033     namespace geom {
00034         class GeometryFactory;
00035         class Geometry;
00036         class Polygon;
00037         class MultiPolygon;
00038         class Envelope;
00039     }
00040     namespace index {
00041         namespace strtree {
00042             class ItemsList;
00043         }
00044     }
00045 }
00046 
00047 namespace geos {
00048 namespace operation { // geos::operation
00049 namespace geounion {  // geos::operation::geounion
00050 
00070 class GEOS_DLL CascadedPolygonUnion 
00071 {
00072 private:
00073     std::vector<geom::Polygon*>* inputPolys;
00074     geom::GeometryFactory const* geomFactory;
00075 
00083     static int const STRTREE_NODE_CAPACITY = 4;
00084 
00099     static std::auto_ptr<geom::Geometry> restrictToPolygons(std::auto_ptr<geom::Geometry> g);
00100 
00101 public:
00102     CascadedPolygonUnion();
00103 
00111     static geom::Geometry* Union(std::vector<geom::Polygon*>* polys);
00112 
00120     template <class T>
00121     static geom::Geometry* Union(T start, T end)
00122     {
00123       std::vector<geom::Polygon*> polys;
00124       for (T i=start; i!=end; ++i) {
00125         const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
00126         polys.push_back(const_cast<geom::Polygon*>(p));
00127       }
00128       return Union(&polys);
00129     }
00130 
00138     static geom::Geometry* Union(const geom::MultiPolygon* polys);
00139 
00147     CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
00148       : inputPolys(polys),
00149         geomFactory(NULL)
00150     {}
00151 
00158     geom::Geometry* Union();
00159 
00160 private:
00161     geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
00162 
00168     geom::Geometry* binaryUnion(GeometryListHolder* geoms);
00169 
00179     geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start, 
00180         std::size_t end);
00181 
00189     GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
00190 
00200     geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
00201 
00202     geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
00203 
00223     geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0, 
00224         geom::Geometry* g1, geom::Envelope const& common);
00225 
00226     geom::Geometry* extractByEnvelope(geom::Envelope const& env, 
00227         geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
00228 
00236     static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
00237 };
00238 
00239 } // namespace geos::operation::union
00240 } // namespace geos::operation
00241 } // namespace geos
00242 
00243 #endif

Generated on 10 Sep 2013 for GEOS by  doxygen 1.4.7