Skip to content

Instantly share code, notes, and snippets.

@signedav
Created September 7, 2026 11:30
Show Gist options
  • Select an option

  • Save signedav/91c42b5e24ef1baab8a5408a84b44b64 to your computer and use it in GitHub Desktop.

Select an option

Save signedav/91c42b5e24ef1baab8a5408a84b44b64 to your computer and use it in GitHub Desktop.
coverageClean-notes

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 ] │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment