GEOS  3.9.1dev
UnaryUnionOp.h
Go to the documentation of this file.
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 #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>
27 #include <geos/geom/Point.h>
28 #include <geos/geom/LineString.h>
29 #include <geos/geom/Polygon.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
41 namespace geos {
42 namespace geom {
43 class GeometryFactory;
44 class Geometry;
45 }
46 }
47 
48 namespace geos {
49 namespace operation { // geos::operation
50 namespace geounion { // geos::operation::geounion
51 
90 public:
91 
92  template <typename T>
93  static std::unique_ptr<geom::Geometry>
94  Union(const T& geoms)
95  {
96  UnaryUnionOp op(geoms);
97  return op.Union();
98  }
99 
100  template <class T>
101  static std::unique_ptr<geom::Geometry>
102  Union(const T& geoms,
103  geom::GeometryFactory& geomFact)
104  {
105  UnaryUnionOp op(geoms, geomFact);
106  return op.Union();
107  }
108 
109  static std::unique_ptr<geom::Geometry>
110  Union(const geom::Geometry& geom)
111  {
112  UnaryUnionOp op(geom);
113  return op.Union();
114  }
115 
116  template <class T>
117  UnaryUnionOp(const T& geoms, geom::GeometryFactory& geomFactIn)
118  : geomFact(&geomFactIn)
119  , unionFunction(&defaultUnionFunction)
120  {
121  extractGeoms(geoms);
122  }
123 
124  template <class T>
125  UnaryUnionOp(const T& geoms)
126  : geomFact(nullptr)
127  , unionFunction(&defaultUnionFunction)
128  {
129  extractGeoms(geoms);
130  }
131 
133  : geomFact(geom.getFactory())
134  , unionFunction(&defaultUnionFunction)
135  {
136  extract(geom);
137  }
138 
140  {
141  unionFunction = unionFun;
142  }
143 
154  std::unique_ptr<geom::Geometry> Union();
155 
156 private:
157 
158  template <typename T>
159  void
160  extractGeoms(const T& geoms)
161  {
162  for(typename T::const_iterator
163  i = geoms.begin(),
164  e = geoms.end();
165  i != e;
166  ++i) {
167  const geom::Geometry* geom = *i;
168  extract(*geom);
169  }
170  }
171 
172  void
173  extract(const geom::Geometry& geom)
174  {
175  using namespace geom::util;
176 
177  if(! geomFact) {
178  geomFact = geom.getFactory();
179  }
180 
181  GeometryExtracter::extract<geom::Polygon>(geom, polygons);
182  GeometryExtracter::extract<geom::LineString>(geom, lines);
183  GeometryExtracter::extract<geom::Point>(geom, points);
184  }
185 
198  std::unique_ptr<geom::Geometry>
200  {
202  //using geos::operation::overlay::snap::SnapIfNeededOverlayOp;
203 
204  if(! empty.get()) {
205  empty = geomFact->createEmptyGeometry();
206  }
207  //return SnapIfNeededOverlayOp::overlayOp(g0, *empty, OverlayOp::opUNION);
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 
231  std::unique_ptr<geom::Geometry> empty;
232 
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 
247 #endif
void setUnionFunction(UnionStrategy *unionFun)
Definition: UnaryUnionOp.h:139
UnaryUnionOp(const T &geoms, geom::GeometryFactory &geomFactIn)
Definition: UnaryUnionOp.h:117
UnaryUnionOp(const geom::Geometry &geom)
Definition: UnaryUnionOp.h:132
static std::unique_ptr< geom::Geometry > Union(const geom::Geometry &geom)
Definition: UnaryUnionOp.h:110
#define GEOS_DLL
Definition: export.h:28
static std::unique_ptr< geom::Geometry > Union(const T &geoms)
Definition: UnaryUnionOp.h:94
std::unique_ptr< geom::Geometry > empty
Definition: UnaryUnionOp.h:231
Unions a collection of Geometry or a single Geometry (which may be a collection) together.
Definition: UnaryUnionOp.h:89
const geom::GeometryFactory * geomFact
Definition: UnaryUnionOp.h:230
Implementation of UnionStrategy that provides overlay using the first generation overlay routines...
Computes the geometric overlay of two Geometry.
Definition: OverlayOp.h:70
std::unique_ptr< geom::Geometry > unionNoOpt(const geom::Geometry &g0)
Definition: UnaryUnionOp.h:199
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
std::vector< const geom::Polygon * > polygons
Definition: UnaryUnionOp.h:226
ClassicUnionStrategy defaultUnionFunction
Definition: UnaryUnionOp.h:234
std::vector< const geom::LineString * > lines
Definition: UnaryUnionOp.h:227
void extract(const geom::Geometry &geom)
Definition: UnaryUnionOp.h:173
const GeometryFactory * getFactory() const
Gets the factory which contains the context in which this geometry was created.
Definition: Geometry.h:218
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
static std::unique_ptr< geom::Geometry > Union(const T &geoms, geom::GeometryFactory &geomFact)
Definition: UnaryUnionOp.h:102
Basic namespace for all GEOS functionalities.
std::vector< const geom::Point * > points
Definition: UnaryUnionOp.h:228