18#include <geos/geom/Envelope.h>
19#include <geos/constants.h>
20#include <geos/index/quadtree/Quadtree.h>
29 class GeometryFactory;
70 std::vector<const Polygon*> polys;
76 void add(
const Polygon* poly);
77 const Envelope* getEnvelope();
78 double getBorderLength(
const Polygon* adjPoly);
80 bool isAdjacent(RelateNG& rel);
81 std::unique_ptr<Geometry> getUnion();
90 virtual ~MergeStrategy() =
default;
92 virtual std::size_t getTarget()
const = 0;
94 virtual void checkMergeTarget(
95 std::size_t areaIndex,
97 const Polygon* poly) = 0;
102 class BorderMergeStrategy :
public MergeStrategy {
106 std::size_t m_targetIndex = INDEX_UNKNOWN;
107 double m_targetBorderLen;
111 BorderMergeStrategy() {};
113 std::size_t getTarget()
const override {
114 return m_targetIndex;
117 void checkMergeTarget(std::size_t areaIndex, CleanArea* area,
const Polygon* poly)
override {
118 double borderLen = area ==
nullptr ? 0.0 : area->getBorderLength(poly);
119 if (m_targetIndex == INDEX_UNKNOWN || borderLen > m_targetBorderLen) {
120 m_targetIndex = areaIndex;
121 m_targetBorderLen = borderLen;
128 class AreaMergeStrategy :
public MergeStrategy {
132 std::size_t m_targetIndex = INDEX_UNKNOWN;
138 AreaMergeStrategy(
bool isMax) : m_isMax(isMax) {};
140 std::size_t getTarget()
const override {
141 return m_targetIndex;
144 void checkMergeTarget(std::size_t areaIndex, CleanArea* area,
const Polygon* poly)
override {
146 double areaVal = area ==
nullptr ? 0.0 : area->getArea();
147 bool isBetter = m_isMax
148 ? areaVal > m_targetArea
149 : areaVal < m_targetArea;
150 if (m_targetIndex == INDEX_UNKNOWN || isBetter) {
151 m_targetIndex = areaIndex;
152 m_targetArea = areaVal;
159 class IndexMergeStrategy :
public MergeStrategy {
163 std::size_t m_targetIndex = INDEX_UNKNOWN;
168 IndexMergeStrategy(
bool isMax) : m_isMax(isMax) {};
170 std::size_t getTarget()
const override {
171 return m_targetIndex;
174 void checkMergeTarget(std::size_t areaIndex, CleanArea* area,
const Polygon* poly)
override {
177 bool isBetter = m_isMax
178 ? areaIndex > m_targetIndex
179 : areaIndex < m_targetIndex;
181 m_targetIndex = areaIndex;
195 std::vector<std::unique_ptr<CleanArea>> cov;
197 std::unique_ptr<Quadtree> covIndex =
nullptr;
199 void mergeGap(
const Polygon* gap);
201 CleanArea* findMaxBorderLength(
const Polygon* poly, std::vector<CleanArea*>& areas);
203 std::vector<CleanArea*> findAdjacentAreas(
const Geometry* poly);
212 CleanCoverage(std::size_t size);
214 void add(std::size_t i,
const Polygon* poly);
216 void mergeOverlap(
const Polygon* overlap,
217 MergeStrategy& mergeStrategy,
218 std::vector<std::size_t>& parentIndexes);
220 static std::size_t findMergeTarget(
const Polygon* poly,
221 MergeStrategy& strategy,
222 std::vector<std::size_t>& parentIndexes,
223 std::vector<std::unique_ptr<CleanArea>>& cov);
225 void mergeGaps(std::vector<const Polygon*>& gaps);
227 std::vector<std::unique_ptr<Geometry>> toCoverage(
const GeometryFactory* geomFactory);
233 CleanCoverage(
const CleanCoverage&) =
delete;
234 CleanCoverage& operator=(
const CleanCoverage&) =
delete;
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:196
Definition LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
A Quadtree is a spatial index structure for efficient querying of 2D rectangles. If other kinds of sp...
Definition Quadtree.h:70
Basic namespace for all GEOS functionalities.
Definition geos.h:38