new QgsGeos Function
QgsGeos::coverageClean(snapping
calling GEOSCoverageCleanWithParams_r
with GEOSCoverageCleanWithParams:
snappingDistance: -1.0 (automatic snapping distance based on input extent)
gapMaximumWidth: 0.0 (gap merging disabled)
overlapMergeStrategy:
- MERGE_LONGEST_BORDER
- MERGE_MAX_AREA
- MERGE_MIN_AREA
- MERGE_MIN_INDEX
And build a processing algorithm QgsCoverageCleanAlgorithm
With QgsCoverageCleanAlgorithm::processAlgorithm
QgsGeometryCollection collection;
QgsGeos geos( &collection );
QgsFeatureIterator features = source->getFeatures();
while ( features.nextFeature( inFeature ) )
{
if ( feedback->isCanceled() )
{
break;
}
if ( inFeature.hasGeometry() )
{
featuresWithGeom.append( inFeature );
collection.addGeometry( inFeature.geometry().constGet()->clone() );
[...]
geos.coverageClean(collection, snappingDistance, maxGapWith, strategy) etc.
looking a little like:
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Vector Coverage - Clean Coverage │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Parameters Log │ Clean coverage │
│ │ │
│ Input layer │ This algorithm operates on a polygonal │
│ ┌──────────────────────────────────────────────┬───┬───┬───┐ │ coverage (a set of polygon features that │
│ │ - My uncoveraged Layer [EPSG:2052] │ r │ │...│ │ may contain topological errors such as │
│ └──────────────────────────────────────────────┴───┴───┴───┘ │ gaps and overlaps) to produce a valid, │
│ [x] Selected features only │ clean coverage. │
│ │ │
│ Snapping distance (-1 for automatic or 0 to disable) │ Nearby vertices and line segments are │
│ ┌──────────────────────────────────────────────────────────┐ │ snapped together to eliminate micro-errors, │
│ │ -1.000000 │ │ gaps narrower than the specified width │
│ └──────────────────────────────────────────────────────────┘ │ are closed, and overlapping areas are │
│ │ merged into adjacent polygons according to │
│ Maximum gap width │ the chosen strategy. │
│ ┌──────────────────────────────────────────────────────────┐ │ Small or fully overlapped geometries may │
│ │ 0.000000 │ │ be collapsed or removed, while maintaining │
│ └──────────────────────────────────────────────────────────┘ │ a one-to-one relationship with the input │
│ │ feature attributes where possible. │
│ Overlap merge strategy │ │
│ ┌──────────────────────────────────────────────────────────┐ │ │
│ │ Longest border (MERGE_LONGEST_BORDER) │ │ │
│ └──────────────────────────────────────────────────────────┘ │ │
│ │ │
│ Cleaned │ │
│ ┌──────────────────────────────────────────────────────┬───┐ │ │
│ │ - [Create temporary layer] │...│ │ │
│ └──────────────────────────────────────────────────────┴───┘ │ │
│ [x] Open output file after running algorithm │ │
│ │ │
├───────────────────────────────────────────────────────────────┴─────────────────────────────────────────────┤
│ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0% ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ [ Cancel ] │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ [ Help ] [ Advanced ] [ Run as Batch Process... ] [ Close ] [ Run ] │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────┘