00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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/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/snap/SnapIfNeededOverlayOp.h>
00033
00034 #ifdef _MSC_VER
00035 #pragma warning(push)
00036 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00037 #endif
00038
00039
00040 namespace geos {
00041 namespace geom {
00042 class GeometryFactory;
00043 class Geometry;
00044 }
00045 }
00046
00047 namespace geos {
00048 namespace operation {
00049 namespace geounion {
00050
00084 class GEOS_DLL UnaryUnionOp
00085 {
00086 public:
00087
00088 template <typename T>
00089 static std::auto_ptr<geom::Geometry> Union(const T& geoms)
00090 {
00091 UnaryUnionOp op(geoms);
00092 return op.Union();
00093 }
00094
00095 template <class T>
00096 static std::auto_ptr<geom::Geometry> Union(const T& geoms,
00097 geom::GeometryFactory& geomFact)
00098 {
00099 UnaryUnionOp op(geoms, geomFact);
00100 return op.Union();
00101 }
00102
00103 static std::auto_ptr<geom::Geometry> Union(const geom::Geometry& geom)
00104 {
00105 UnaryUnionOp op(geom);
00106 return op.Union();
00107 }
00108
00109 template <class T>
00110 UnaryUnionOp(const T& geoms, geom::GeometryFactory& geomFactIn)
00111 :
00112 geomFact(&geomFactIn)
00113 {
00114 extractGeoms(geoms);
00115 }
00116
00117 template <class T>
00118 UnaryUnionOp(const T& geoms)
00119 :
00120 geomFact(0)
00121 {
00122 extractGeoms(geoms);
00123 }
00124
00125 UnaryUnionOp(const geom::Geometry& geom)
00126 :
00127 geomFact(geom.getFactory())
00128 {
00129 extract(geom);
00130 }
00131
00142 std::auto_ptr<geom::Geometry> Union();
00143
00144 private:
00145
00146 template <typename T>
00147 void extractGeoms(const T& geoms)
00148 {
00149 for (typename T::const_iterator
00150 i=geoms.begin(),
00151 e=geoms.end();
00152 i!=e;
00153 ++i)
00154 {
00155 const geom::Geometry* geom = *i;
00156 extract(*geom);
00157 }
00158 }
00159
00160 void extract(const geom::Geometry& geom)
00161 {
00162 using namespace geom::util;
00163
00164 if ( ! geomFact ) geomFact = geom.getFactory();
00165
00166 GeometryExtracter::extract<geom::Polygon>(geom, polygons);
00167 GeometryExtracter::extract<geom::LineString>(geom, lines);
00168 GeometryExtracter::extract<geom::Point>(geom, points);
00169 }
00170
00183 std::auto_ptr<geom::Geometry> unionNoOpt(const geom::Geometry& g0)
00184 {
00185 using geos::operation::overlay::OverlayOp;
00186 using geos::operation::overlay::snap::SnapIfNeededOverlayOp;
00187
00188 if ( ! empty.get() ) {
00189 empty.reset( geomFact->createEmptyGeometry() );
00190 }
00191 return SnapIfNeededOverlayOp::overlayOp(g0, *empty, OverlayOp::opUNION);
00192 }
00193
00203 std::auto_ptr<geom::Geometry> unionWithNull(std::auto_ptr<geom::Geometry> g0,
00204 std::auto_ptr<geom::Geometry> g1);
00205
00206 std::vector<const geom::Polygon*> polygons;
00207 std::vector<const geom::LineString*> lines;
00208 std::vector<const geom::Point*> points;
00209
00210 const geom::GeometryFactory* geomFact;
00211
00212 std::auto_ptr<geom::Geometry> empty;
00213 };
00214
00215
00216 }
00217 }
00218 }
00219
00220 #ifdef _MSC_VER
00221 #pragma warning(pop)
00222 #endif
00223
00224 #endif