GEOS: CascadedPolygonUnion.h Source File

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

- File List

# CascadedPolygonUnion.h

    00001 /**********************************************************************
    00002  * $Id: CascadedPolygonUnion.h 2953 2010-03-26 12:03:45Z mloskot $
    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 #include <geos/export.h>
    00023
    00024 #include <vector>
    00025 #include <algorithm>
    00026
    00027 // Forward declarations
    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 { // geos::operation
    00045 namespace geounion {  // geos::operation::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     // items need to be deleted in the end
    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 } // namespace geos::operation::union
    00232 } // namespace geos::operation
    00233 } // namespace geos
    00234
    00235 #endif
    00236
    00237 /**********************************************************************
    00238  * $Log$
    00239  *
    00240  **********************************************************************/
    00241