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

UnaryUnionOp.h

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

Generated on Wed Jul 4 09:00:05 2012 for GEOS by  doxygen 1.3.9.1