GEOS 3.6.2
UnaryUnionOp.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: operation/union/UnaryUnionOp.java r320 (JTS-1.12)
16 *
17 **********************************************************************/
18
19#ifndef GEOS_OP_UNION_UNARYUNION_H
20#define GEOS_OP_UNION_UNARYUNION_H
21
22#include <memory>
23#include <vector>
24
25#include <geos/export.h>
26#include <geos/geom/GeometryFactory.h>
27#include <geos/geom/BinaryOp.h>
28#include <geos/geom/Point.h>
29#include <geos/geom/LineString.h>
30#include <geos/geom/Polygon.h>
31#include <geos/geom/util/GeometryExtracter.h>
32#include <geos/operation/overlay/OverlayOp.h>
33//#include <geos/operation/overlay/snap/SnapIfNeededOverlayOp.h>
34
35#ifdef _MSC_VER
36#pragma warning(push)
37#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
38#endif
39
40// Forward declarations
41namespace geos {
42 namespace geom {
43 class GeometryFactory;
44 class Geometry;
45 }
46}
47
48namespace geos {
49namespace operation { // geos::operation
50namespace geounion { // geos::operation::geounion
51
85class GEOS_DLL UnaryUnionOp
86{
87public:
88
89 template <typename T>
90 static std::auto_ptr<geom::Geometry> Union(const T& geoms)
91 {
92 UnaryUnionOp op(geoms);
93 return op.Union();
94 }
95
96 template <class T>
97 static std::auto_ptr<geom::Geometry> Union(const T& geoms,
98 geom::GeometryFactory& geomFact)
99 {
100 UnaryUnionOp op(geoms, geomFact);
101 return op.Union();
102 }
103
104 static std::auto_ptr<geom::Geometry> Union(const geom::Geometry& geom)
105 {
106 UnaryUnionOp op(geom);
107 return op.Union();
108 }
109
110 template <class T>
111 UnaryUnionOp(const T& geoms, geom::GeometryFactory& geomFactIn)
112 :
113 geomFact(&geomFactIn)
114 {
115 extractGeoms(geoms);
116 }
117
118 template <class T>
119 UnaryUnionOp(const T& geoms)
120 :
121 geomFact(0)
122 {
123 extractGeoms(geoms);
124 }
125
126 UnaryUnionOp(const geom::Geometry& geom)
127 :
128 geomFact(geom.getFactory())
129 {
130 extract(geom);
131 }
132
143 std::auto_ptr<geom::Geometry> Union();
144
145private:
146
147 template <typename T>
148 void extractGeoms(const T& geoms)
149 {
150 for (typename T::const_iterator
151 i=geoms.begin(),
152 e=geoms.end();
153 i!=e;
154 ++i)
155 {
156 const geom::Geometry* geom = *i;
157 extract(*geom);
158 }
159 }
160
161 void extract(const geom::Geometry& geom)
162 {
163 using namespace geom::util;
164
165 if ( ! geomFact ) geomFact = geom.getFactory();
166
167 GeometryExtracter::extract<geom::Polygon>(geom, polygons);
168 GeometryExtracter::extract<geom::LineString>(geom, lines);
169 GeometryExtracter::extract<geom::Point>(geom, points);
170 }
171
184 std::auto_ptr<geom::Geometry> unionNoOpt(const geom::Geometry& g0)
185 {
187 //using geos::operation::overlay::snap::SnapIfNeededOverlayOp;
188
189 if ( ! empty.get() ) {
190 empty.reset( geomFact->createEmptyGeometry() );
191 }
192 //return SnapIfNeededOverlayOp::overlayOp(g0, *empty, OverlayOp::opUNION);
193 return BinaryOp(&g0, empty.get(), overlay::overlayOp(OverlayOp::opUNION));
194 }
195
205 std::auto_ptr<geom::Geometry> unionWithNull(std::auto_ptr<geom::Geometry> g0,
206 std::auto_ptr<geom::Geometry> g1);
207
208 std::vector<const geom::Polygon*> polygons;
209 std::vector<const geom::LineString*> lines;
210 std::vector<const geom::Point*> points;
211
212 const geom::GeometryFactory* geomFact;
213
214 std::auto_ptr<geom::Geometry> empty;
215};
216
217
218} // namespace geos::operation::union
219} // namespace geos::operation
220} // namespace geos
221
222#ifdef _MSC_VER
223#pragma warning(pop)
224#endif
225
226#endif
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:67
Geometry * createEmptyGeometry() const
Construct the EMPTY Geometry.
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:167
std::auto_ptr< geom::Geometry > Union()
Gets the union of the input geometries.
Computes the geometric overlay of two Geometry.
Definition OverlayOp.h:68
Provides classes that parse and modify Geometry objects.
Definition ComponentCoordinateExtracter.h:30
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Provides classes for implementing operations on geometries.
Definition IndexedNestedRingTester.h:40
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25