GEOS  3.14.0dev
OverlapUnion.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: ORIGINAL WORK, generalization of CascadedPolygonUnion
16  *
17  **********************************************************************/
18 
19 #pragma once
20 
21 #include <geos/export.h>
22 
23 #include <vector>
24 #include <algorithm>
25 #include <unordered_set>
26 
27 #include <geos/geom/Geometry.h>
28 #include <geos/operation/union/UnionStrategy.h>
29 #include <geos/operation/union/CascadedPolygonUnion.h>
30 
31 // Forward declarations
32 namespace geos {
33 namespace geom {
34 class Envelope;
35 class LineSegment;
36 }
37 }
38 
39 namespace geos {
40 namespace operation { // geos::operation
41 namespace geounion { // geos::operation::geounion
42 
96 class GEOS_DLL OverlapUnion {
97 
98 public:
99 
100  OverlapUnion(const geom::Geometry* p_g0, const geom::Geometry* p_g1, geounion::UnionStrategy* unionFun)
101  : g0(p_g0)
102  , g1(p_g1)
103  , unionFunction(unionFun)
104  , geomFactory(p_g0->getFactory())
105  , isUnionSafe(false)
106  {};
107 
108  OverlapUnion(const geom::Geometry* p_g0, const geom::Geometry* p_g1)
109  : OverlapUnion(p_g0, p_g1, &defaultUnionFunction)
110  {};
111 
112 
113  std::unique_ptr<geom::Geometry> doUnion();
114 
115 private:
116 
117  const geom::Geometry* g0;
118  const geom::Geometry* g1;
119  geounion::UnionStrategy* unionFunction;
120  const geom::GeometryFactory* geomFactory;
121  bool isUnionSafe;
122 
123  geounion::ClassicUnionStrategy defaultUnionFunction;
124 
125  static geom::Envelope overlapEnvelope(const geom::Geometry* geom0, const geom::Geometry* geom1);
126  std::unique_ptr<geom::Geometry> extractByEnvelope(const geom::Envelope& env, const geom::Geometry* geom, std::vector<std::unique_ptr<geom::Geometry>>& disjointGeoms);
127  static std::unique_ptr<geom::Geometry> combine(std::unique_ptr<geom::Geometry>& unionGeom, std::vector<std::unique_ptr<geom::Geometry>>& disjointPolys);
128  std::unique_ptr<geom::Geometry> unionFull(const geom::Geometry* geom0, const geom::Geometry* geom1);
129  static std::unique_ptr<geom::Geometry> unionBuffer(const geom::Geometry* geom0, const geom::Geometry* geom1);
130  bool isBorderSegmentsSame(const geom::Geometry* result, const geom::Envelope& env);
131  static bool isEqual(std::vector<geom::LineSegment>& segs0, std::vector<geom::LineSegment>& segs1);
132  std::vector<geom::LineSegment> extractBorderSegments(const geom::Geometry* geom0, const geom::Geometry* geom1, const geom::Envelope& env);
133  void extractBorderSegments(const geom::Geometry* geom, const geom::Envelope& penv, std::vector<geom::LineSegment>& psegs);
134 
135 };
136 
137 } // namespace geos::operation::union
138 } // namespace geos::operation
139 } // namespace geos
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:197
const GeometryFactory * getFactory() const
Gets the factory which contains the context in which this geometry was created.
Definition: Geometry.h:227
Implementation of UnionStrategy that provides overlay using the first generation overlay routines.
Definition: CascadedPolygonUnion.h:50
Unions MultiPolygons efficiently by using full topological union only for polygons which may overlap ...
Definition: OverlapUnion.h:96
Definition: UnionStrategy.h:40
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25