GEOS 3.15.0dev
CoverageCleaner.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (c) 2025 Martin Davis
7 * Copyright (C) 2025 Paul Ramsey <pramsey@cleverelephant.ca>
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#pragma once
17
18#include <geos/index/strtree/TemplateSTRtree.h>
19#include <geos/coverage/CleanCoverage.h>
20#include <geos/geom/Envelope.h>
21#include <geos/constants.h>
22#include <geos/export.h>
23
24#include <vector>
25#include <memory>
26#include <map>
27
28
29// Forward declarations
30namespace geos {
31namespace geom {
32 class Coordinate;
33 class CoordinateSequence;
34 class Geometry;
35 class GeometryFactory;
36 class LineString;
37 class LinearRing;
38 class Polygon;
39}
40namespace index {
41}
42namespace noding {
43 class SegmentString;
44}
45namespace coverage {
46 class CleanCoverage;
47}
48}
49
50namespace geos { // geos.
51namespace coverage { // geos.coverage
52
53
128class GEOS_DLL CoverageCleaner {
129
134 using Point = geos::geom::Point;
140
141public:
142
144 static constexpr int MERGE_LONGEST_BORDER = 0;
146 static constexpr int MERGE_MAX_AREA = 1;
148 static constexpr int MERGE_MIN_AREA = 2;
150 static constexpr int MERGE_MIN_INDEX = 3;
151
152private:
153
154 std::vector<const Geometry*> coverage;
155 const GeometryFactory* geomFactory;
156 double snappingDistance;
157
158 double gapMaximumWidth = 0.0;
159 int overlapMergeStrategy = MERGE_LONGEST_BORDER;
160 std::unique_ptr<index::strtree::TemplateSTRtree<std::size_t>> covIndex;
161 std::vector<std::unique_ptr<Polygon>> resultants;
162 std::unique_ptr<CleanCoverage> cleanCov;
163 std::map<std::size_t, std::vector<std::size_t>> overlapParentMap;
164 std::vector<const Polygon*> overlaps;
165 std::vector<const Polygon*> gaps;
166 std::vector<const Polygon*> mergableGaps;
167
168 static constexpr double DEFAULT_SNAPPING_FACTOR = 1.0e8;
169
170
171 static double computeDefaultSnappingDistance(
172 std::vector<const Geometry*>& geoms);
173
174 static Envelope extent(std::vector<const Geometry*>& geoms);
175
176 void mergeOverlaps(
177 std::map<std::size_t, std::vector<std::size_t>>& overlapMap);
178
179 std::unique_ptr<CleanCoverage::MergeStrategy> mergeStrategy(
180 int mergeStrategyId);
181
182 void computeResultants(double tolerance);
183
184 void createCoverageIndex();
185
186 void classifyResult(std::vector<std::unique_ptr<Polygon>>& rs);
187
188 void classifyResultant(std::size_t resultIndex, const Polygon* resPoly);
189
190 static bool covers(const Geometry* poly, const Point* intPt);
191
192 std::vector<const Polygon*> findMergableGaps(
193 std::vector<const Polygon*> gaps);
194
195 bool isMergableGap(const Polygon* gap);
196
197 static std::vector<std::unique_ptr<geom::Polygon>> polygonize(
198 const Geometry* cleanEdges);
199
200 static bool isPolygonal(const Geometry* geom);
201
202 static std::vector<const Polygon*> toPolygonArray(
203 const Geometry* geom);
204
205
206public:
207
213 CoverageCleaner(std::vector<const Geometry*>& coverage);
214
225 static std::vector<std::unique_ptr<Geometry>> clean(
226 std::vector<const Geometry*>& coverage,
227 double snapDistance,
228 int mergeStrategy,
229 double maxWidth);
230
240 static std::vector<std::unique_ptr<Geometry>> clean(
241 std::vector<const Geometry*>& coverage,
242 double snapDistance,
243 double maxWidth);
244
254 static std::vector<std::unique_ptr<Geometry>> cleanOverlapGap(
255 std::vector<const Geometry*>& coverage,
256 int mergeStrategy,
257 double maxWidth);
258
268 static std::vector<std::unique_ptr<Geometry>> cleanGapWidth(
269 std::vector<const Geometry*>& coverage,
270 double maxWidth);
271
279 void setSnappingDistance(double snapDistance);
280
287 void setOverlapMergeStrategy(int mergeStrategy);
288
296 void setGapMaximumWidth(double maxWidth);
297
301 void clean();
302
308 std::vector<std::unique_ptr<Geometry>> getResult();
309
316 std::vector<const Polygon*> getOverlaps();
317
324 std::vector<const Polygon*> getMergedGaps();
325
326 std::unique_ptr<Geometry> toGeometry(
327 std::vector<SegmentString*>& segStrings,
328 const GeometryFactory* geomFact);
329
330 std::unique_ptr<Geometry> node(
331 std::vector<const Geometry*>& coverage,
332 double snapDistance);
333
339 CoverageCleaner& operator=(const CoverageCleaner&) = delete;
340
341};
342
343} // namespace geos.coverage
344} // namespace geos
345
346
347
348
349
Definition CoverageCleaner.h:128
void setGapMaximumWidth(double maxWidth)
static std::vector< std::unique_ptr< Geometry > > clean(std::vector< const Geometry * > &coverage, double snapDistance, double maxWidth)
std::vector< const Polygon * > getMergedGaps()
static std::vector< std::unique_ptr< Geometry > > clean(std::vector< const Geometry * > &coverage, double snapDistance, int mergeStrategy, double maxWidth)
CoverageCleaner(std::vector< const Geometry * > &coverage)
CoverageCleaner(const CoverageCleaner &)=delete
void setOverlapMergeStrategy(int mergeStrategy)
std::vector< const Polygon * > getOverlaps()
static std::vector< std::unique_ptr< Geometry > > cleanGapWidth(std::vector< const Geometry * > &coverage, double maxWidth)
static std::vector< std::unique_ptr< Geometry > > cleanOverlapGap(std::vector< const Geometry * > &coverage, int mergeStrategy, double maxWidth)
std::vector< std::unique_ptr< Geometry > > getResult()
void setSnappingDistance(double snapDistance)
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
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
Definition Point.h:61
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
Basic namespace for all GEOS functionalities.
Definition geos.h:38