UnaryUnionOp.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  *
00008  * This is free software; you can redistribute and/or modify it under
00009  * the terms of the GNU Lesser General Public Licence as published
00010  * by the Free Software Foundation. 
00011  * See the COPYING file for more information.
00012  *
00013  **********************************************************************
00014  *
00015  * Last port: operation/union/UnaryUnionOp.java r320 (JTS-1.12)
00016  *
00017  **********************************************************************/
00018 
00019 #ifndef GEOS_OP_UNION_UNARYUNION_H
00020 #define GEOS_OP_UNION_UNARYUNION_H
00021 
00022 #include <memory>
00023 #include <vector>
00024 
00025 #include <geos/export.h>
00026 #include <geos/geom/GeometryFactory.h>
00027 #include <geos/geom/BinaryOp.h>
00028 #include <geos/geom/Point.h>
00029 #include <geos/geom/LineString.h>
00030 #include <geos/geom/Polygon.h>
00031 #include <geos/geom/util/GeometryExtracter.h>
00032 #include <geos/operation/overlay/OverlayOp.h>
00033 //#include <geos/operation/overlay/snap/SnapIfNeededOverlayOp.h>
00034 
00035 #ifdef _MSC_VER
00036 #pragma warning(push)
00037 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00038 #endif
00039 
00040 // Forward declarations
00041 namespace geos {
00042     namespace geom {
00043         class GeometryFactory;
00044         class Geometry;
00045     }
00046 }
00047 
00048 namespace geos {
00049 namespace operation { // geos::operation
00050 namespace geounion {  // geos::operation::geounion
00051 
00085 class GEOS_DLL UnaryUnionOp
00086 {
00087 public:
00088 
00089   template <typename T>
00090   static std::auto_ptr<geom::Geometry> Union(const T& geoms)
00091   {
00092     UnaryUnionOp op(geoms);
00093     return op.Union();
00094   }
00095 
00096   template <class T>
00097   static std::auto_ptr<geom::Geometry> Union(const T& geoms,
00098       geom::GeometryFactory& geomFact)
00099   {
00100     UnaryUnionOp op(geoms, geomFact);
00101     return op.Union();
00102   }
00103 
00104   static std::auto_ptr<geom::Geometry> Union(const geom::Geometry& geom)
00105   {
00106     UnaryUnionOp op(geom);
00107     return op.Union();
00108   }
00109 
00110   template <class T>
00111   UnaryUnionOp(const T& geoms, geom::GeometryFactory& geomFactIn)
00112       :
00113       geomFact(&geomFactIn)
00114   {
00115     extractGeoms(geoms);
00116   }
00117 
00118   template <class T>
00119   UnaryUnionOp(const T& geoms)
00120       :
00121       geomFact(0)
00122   {
00123     extractGeoms(geoms);
00124   }
00125 
00126   UnaryUnionOp(const geom::Geometry& geom)
00127       :
00128       geomFact(geom.getFactory())
00129   {
00130     extract(geom);
00131   }
00132 
00143   std::auto_ptr<geom::Geometry> Union();
00144 
00145 private:
00146 
00147   template <typename T>
00148   void extractGeoms(const T& geoms)
00149   {
00150       for (typename T::const_iterator
00151               i=geoms.begin(),
00152               e=geoms.end();
00153               i!=e;
00154               ++i)
00155       {
00156           const geom::Geometry* geom = *i;
00157           extract(*geom);
00158       }
00159   }
00160 
00161   void extract(const geom::Geometry& geom)
00162   {
00163       using namespace geom::util;
00164 
00165       if ( ! geomFact ) geomFact = geom.getFactory();
00166 
00167       GeometryExtracter::extract<geom::Polygon>(geom, polygons);
00168       GeometryExtracter::extract<geom::LineString>(geom, lines);
00169       GeometryExtracter::extract<geom::Point>(geom, points);
00170   }
00171 
00184   std::auto_ptr<geom::Geometry> unionNoOpt(const geom::Geometry& g0)
00185   {
00186     using geos::operation::overlay::OverlayOp;
00187     //using geos::operation::overlay::snap::SnapIfNeededOverlayOp;
00188 
00189     if ( ! empty.get() ) {
00190       empty.reset( geomFact->createEmptyGeometry() );
00191     }
00192     //return SnapIfNeededOverlayOp::overlayOp(g0, *empty, OverlayOp::opUNION);
00193     return BinaryOp(&g0, empty.get(), overlay::overlayOp(OverlayOp::opUNION));
00194   }
00195 
00205   std::auto_ptr<geom::Geometry> unionWithNull(std::auto_ptr<geom::Geometry> g0,
00206                                               std::auto_ptr<geom::Geometry> g1);
00207 
00208   std::vector<const geom::Polygon*> polygons;
00209   std::vector<const geom::LineString*> lines;
00210   std::vector<const geom::Point*> points;
00211 
00212   const geom::GeometryFactory* geomFact;
00213 
00214   std::auto_ptr<geom::Geometry> empty;
00215 };
00216  
00217 
00218 } // namespace geos::operation::union
00219 } // namespace geos::operation
00220 } // namespace geos
00221 
00222 #ifdef _MSC_VER
00223 #pragma warning(pop)
00224 #endif
00225 
00226 #endif

Generated on 15 May 2014 for GEOS by  doxygen 1.4.7