GEOS  3.13.0dev
CascadedPolygonUnion.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  * Copyright (C) 2006 Refractions Research Inc.
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
12  * See the COPYING file for more information.
13  *
14  **********************************************************************
15  *
16  * Last port: operation/union/CascadedPolygonUnion.java r487 (JTS-1.12+)
17  * Includes custom code to deal with https://trac.osgeo.org/geos/ticket/837
18  *
19  **********************************************************************/
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 
25 #include <geos/operation/union/UnionStrategy.h>
26 
27 // Forward declarations
28 namespace geos {
29 namespace geom {
30 class GeometryFactory;
31 class Geometry;
32 class Polygon;
33 class MultiPolygon;
34 class Envelope;
35 }
36 }
37 
38 namespace geos {
39 namespace operation { // geos::operation
40 namespace geounion { // geos::operation::geounion
41 
42 
48 class GEOS_DLL ClassicUnionStrategy : public UnionStrategy {
49 
50 public:
51 
53 
59  std::unique_ptr<geom::Geometry> Union(const geom::Geometry*, const geom::Geometry*) override;
60 
70  bool isFloatingPrecision() const override;
71 
72 private:
73 
79  std::unique_ptr<geom::Geometry> unionPolygonsByBuffer(const geom::Geometry* g0, const geom::Geometry* g1);
80 
81 };
82 
83 
84 
101 class GEOS_DLL CascadedPolygonUnion {
102 private:
103  std::vector<geom::Polygon*>* inputPolys;
104  geom::GeometryFactory const* geomFactory;
105 
113  static int const STRTREE_NODE_CAPACITY = 4;
114 
129  static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
130 
131 public:
133 
140  static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys);
141  static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun);
142 
151  template <class T>
152  static std::unique_ptr<geom::Geometry>
153  Union(T start, T end, UnionStrategy *unionStrategy)
154  {
155  std::vector<geom::Polygon*> polys;
156  for(T i = start; i != end; ++i) {
157  const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
158  polys.push_back(const_cast<geom::Polygon*>(p));
159  }
160  return Union(&polys, unionStrategy);
161  }
162 
169  static std::unique_ptr<geom::Geometry> Union(const geom::MultiPolygon* polys);
170 
178  CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
179  : inputPolys(polys)
180  , geomFactory(nullptr)
181  , unionFunction(&defaultUnionFunction)
182  {}
183 
184  CascadedPolygonUnion(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun)
185  : inputPolys(polys)
186  , geomFactory(nullptr)
187  , unionFunction(unionFun)
188  {}
189 
196  std::unique_ptr<geom::Geometry> Union();
197 
198 private:
199 
200  UnionStrategy* unionFunction;
201  ClassicUnionStrategy defaultUnionFunction;
202 
212  std::unique_ptr<geom::Geometry> binaryUnion(const std::vector<const geom::Geometry*> & geoms, std::size_t start, std::size_t end);
213 
223  std::unique_ptr<geom::Geometry> unionSafe(const geom::Geometry* g0, const geom::Geometry* g1) const;
224 
225  std::unique_ptr<geom::Geometry> unionSafe(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&);
226 
234  std::unique_ptr<geom::Geometry> unionActual(const geom::Geometry* g0, const geom::Geometry* g1) const;
235 
236  std::unique_ptr<geom::Geometry> unionActual(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&) const;
237 };
238 
239 
240 
241 
242 
243 } // namespace geos::operation::union
244 } // namespace geos::operation
245 } // namespace geos
246 
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:65
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: MultiPolygon.h:58
Represents a linear polygon, which may include holes.
Definition: Polygon.h:60
Provides an efficient method of unioning a collection of polygonal geometries.
Definition: CascadedPolygonUnion.h:101
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition: CascadedPolygonUnion.h:178
static std::unique_ptr< geom::Geometry > Union(T start, T end, UnionStrategy *unionStrategy)
Computes the union of a set of polygonal Geometrys.
Definition: CascadedPolygonUnion.h:153
std::unique_ptr< geom::Geometry > Union()
Computes the union of the input geometries.
static std::unique_ptr< geom::Geometry > Union(const geom::MultiPolygon *polys)
Computes the union of a collection of polygonal Geometrys.
static std::unique_ptr< geom::Geometry > Union(std::vector< geom::Polygon * > *polys)
Computes the union of a collection of polygonal Geometrys.
Implementation of UnionStrategy that provides overlay using the first generation overlay routines.
Definition: CascadedPolygonUnion.h:48
std::unique_ptr< geom::Geometry > Union(const geom::Geometry *, const geom::Geometry *) override
Definition: UnionStrategy.h:40
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25