GEOS: CascadedUnion.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# CascadedUnion.h

    00001 /**********************************************************************
    00002  * $Id$
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://trac.osgeo.org/geos
    00006  *
    00007  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
    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: ORIGINAL WORK, generalization of CascadedPolygonUnion
    00017  *
    00018  **********************************************************************/
    00019
    00020 #ifndef GEOS_OP_UNION_CASCADEDUNION_H
    00021 #define GEOS_OP_UNION_CASCADEDUNION_H
    00022
    00023 #include <geos/export.h>
    00024
    00025 #include <vector>
    00026 #include <algorithm>
    00027
    00028 #include "GeometryListHolder.h"
    00029
    00030 // Forward declarations
    00031 namespace geos {
    00032     namespace geom {
    00033         class GeometryFactory;
    00034         class Geometry;
    00035         class Geometry;
    00036         class Envelope;
    00037     }
    00038     namespace index {
    00039         namespace strtree {
    00040             class ItemsList;
    00041         }
    00042     }
    00043 }
    00044
    00045 namespace geos {
    00046 namespace operation { // geos::operation
    00047 namespace geounion {  // geos::operation::geounion
    00048
    00056 class GEOS_DLL CascadedUnion
    00057 {
    00058 private:
    00059     const std::vector<geom::Geometry*>* inputGeoms;
    00060     geom::GeometryFactory const* geomFactory;
    00061
    00069     static int const STRTREE_NODE_CAPACITY = 4;
    00070
    00071 public:
    00072     CascadedUnion();
    00073
    00080     static geom::Geometry* Union(std::vector<geom::Geometry*>* geoms);
    00081
    00089     template <class T>
    00090     static geom::Geometry* Union(T start, T end)
    00091     {
    00092       std::vector<geom::Geometry*> polys;
    00093       for (T i=start; i!=end; ++i) {
    00094         const geom::Geometry* p = dynamic_cast<const geom::Geometry*>(*i);
    00095         polys.push_back(const_cast<geom::Geometry*>(p));
    00096       }
    00097       return Union(&polys);
    00098     }
    00099
    00107     CascadedUnion(const std::vector<geom::Geometry*>* geoms)
    00108       : inputGeoms(geoms),
    00109         geomFactory(NULL)
    00110     {}
    00111
    00118     geom::Geometry* Union();
    00119
    00120 private:
    00121     geom::Geometry* unionTree(index::strtree::ItemsList* geomTree);
    00122
    00128     geom::Geometry* binaryUnion(GeometryListHolder* geoms);
    00129
    00139     geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start,
    00140         std::size_t end);
    00141
    00149     GeometryListHolder* reduceToGeometries(index::strtree::ItemsList* geomTree);
    00150
    00160     geom::Geometry* unionSafe(geom::Geometry* g0, geom::Geometry* g1);
    00161
    00162     geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
    00163
    00180     geom::Geometry* unionUsingEnvelopeIntersection(geom::Geometry* g0,
    00181         geom::Geometry* g1, geom::Envelope const& common);
    00182
    00183     geom::Geometry* extractByEnvelope(geom::Envelope const& env,
    00184         geom::Geometry* geom, std::vector<geom::Geometry*>& disjointGeoms);
    00185
    00193     static geom::Geometry* unionActual(geom::Geometry* g0, geom::Geometry* g1);
    00194 };
    00195
    00196 } // namespace geos::operation::union
    00197 } // namespace geos::operation
    00198 } // namespace geos
    00199
    00200 #endif