GEOS 3.15.0beta1
UnaryUnionOp.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
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#pragma once
20
21#include <memory>
22#include <vector>
23
24#include <geos/export.h>
25#include <geos/geom/GeometryFactory.h>
26#include <geos/geom/Point.h>
27#include <geos/geom/LineString.h>
28#include <geos/geom/Polygon.h>
29#include <geos/geom/util/GeometryExtracter.h>
30#include <geos/operation/union/CascadedPolygonUnion.h>
31#include <geos/util/Progress.h>
32
33#include <geos/util.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 {
42namespace geom {
43class GeometryFactory;
44class Geometry;
45}
46}
47
48namespace geos {
49namespace operation { // geos::operation
50namespace geounion { // geos::operation::geounion
51
89class GEOS_DLL UnaryUnionOp {
90public:
91
92 template <typename T>
93 static std::unique_ptr<geom::Geometry>
94 Union(const T& geoms)
95 {
96 UnaryUnionOp op(geoms);
97 geos::util::ProgressFunction* progressFunction = nullptr;
98 return op.Union(progressFunction);
99 }
100
101 template <class T>
102 static std::unique_ptr<geom::Geometry>
103 Union(const T& geoms,
104 geom::GeometryFactory& geomFact)
105 {
106 UnaryUnionOp op(geoms, geomFact);
107 geos::util::ProgressFunction* progressFunction = nullptr;
108 return op.Union(progressFunction);
109 }
110
111 static std::unique_ptr<geom::Geometry>
112 Union(const geom::Geometry& geom, geos::util::ProgressFunction* progressFunction)
113 {
114 UnaryUnionOp op(geom);
115 return op.Union(progressFunction);
116 }
117
118 template <class T>
119 UnaryUnionOp(const T& geoms, geom::GeometryFactory& geomFactIn)
120 : geomFact(&geomFactIn)
121 , unionFunction(&defaultUnionFunction)
122 {
123 extractGeoms(geoms);
124 }
125
126 template <class T>
127 UnaryUnionOp(const T& geoms)
128 : geomFact(nullptr)
129 , unionFunction(&defaultUnionFunction)
130 {
131 extractGeoms(geoms);
132 }
133
134 UnaryUnionOp(const geom::Geometry& geom)
135 : geomFact(geom.getFactory())
136 , unionFunction(&defaultUnionFunction)
137 {
138 extract(geom);
139 }
140
141 void setUnionFunction(UnionStrategy* unionFun)
142 {
143 unionFunction = unionFun;
144 }
145
156 std::unique_ptr<geom::Geometry> Union(geos::util::ProgressFunction* progressFunction);
157
158private:
159
160 template <typename T>
161 void
162 extractGeoms(const T& geoms)
163 {
164 for(typename T::const_iterator
165 i = geoms.begin(),
166 e = geoms.end();
167 i != e;
168 ++i) {
169 const geom::Geometry* geom = *i;
170 extract(*geom);
171 }
172 }
173
174 void
175 extract(const geom::Geometry& geom)
176 {
177 util::ensureNoCurvedComponents(geom);
178
179 using namespace geom::util;
180
181 if(! geomFact) {
182 geomFact = geom.getFactory();
183 }
184
185 GeometryExtracter::extract<geom::Polygon>(geom, polygons);
186 GeometryExtracter::extract<geom::LineString>(geom, lines);
187 GeometryExtracter::extract<geom::Point>(geom, points);
188 }
189
202 std::unique_ptr<geom::Geometry>
203 unionNoOpt(const geom::Geometry& g0)
204 {
205 if(! empty.get()) {
206 empty = geomFact->createEmptyGeometry();
207 }
208 return unionFunction->Union(&g0, empty.get());
209 }
210
220 std::unique_ptr<geom::Geometry> unionWithNull(
221 std::unique_ptr<geom::Geometry> g0,
222 std::unique_ptr<geom::Geometry> g1
223 );
224
225 // Members
226 std::vector<const geom::Polygon*> polygons;
227 std::vector<const geom::LineString*> lines;
228 std::vector<const geom::Point*> points;
229
230 const geom::GeometryFactory* geomFact;
231 std::unique_ptr<geom::Geometry> empty;
232
233 UnionStrategy* unionFunction;
234 ClassicUnionStrategy defaultUnionFunction;
235
236};
237
238
239} // namespace geos::operation::union
240} // namespace geos::operation
241} // namespace geos
242
243#ifdef _MSC_VER
244#pragma warning(pop)
245#endif
246
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:72
std::unique_ptr< Geometry > createEmptyGeometry(GeometryTypeId type=GEOS_GEOMETRYCOLLECTION, bool hasZ=false, bool hasM=false) const
Construct the EMPTY Geometry.
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:201
std::unique_ptr< geom::Geometry > Union(geos::util::ProgressFunction *progressFunction)
Gets the union of the input geometries.
Definition UnionStrategy.h:40
Provides classes that parse and modify Geometry objects.
Definition ComponentCoordinateExtracter.h:28
Definition Angle.h:26
Classes to perform efficient unioning of collections of geometries.
Definition namespaces.h:286
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
std::function< void(double, const char *)> ProgressFunction
Definition Progress.h:29
Basic namespace for all GEOS functionalities.
Definition geos.h:38