Main question towards the end. Details follow now:
I have a slope raster
Region: Bern, Switzerland
CRS: EPSG:2056 - CH1903+ / LV95 - Projected
Extent: 2587757,1186900 : 2613583,1212068
Map units: meters
Cell values: degrees
Theoretical range: 0-90
Range: 0-81
Pixel size: 2x2m
File size: ~ 500 MB
I ran the file through raster calc with the expression
( "filename" < 2 )
to obtain all cells with a slope of less than 2. I have now a raster with cell values of 0 and 1. Some areas of the raster are pretty homogenous, but some areas are veritable checkerboards where the slope of the original file is just around 2 and now alternates almost from cell to cell between 0 and 1.
I need to polygonize the raster. So I tried the GDAL function polygonize
from the QGIS toolbox, but had to kill the task after running for 25 minutes.
How can I generalize or simplify a noisy binary layer to reduce processing time when polygonizing?
Best Answer
Similar to what @WhiteboxDev suggested, another filter type that could be used is a
sieve filter
. Instead of looking at whether the 0s or 1s "win" for a given region, it looks at the number of neighbours a given pixel has, that matches its starting value, and chains those neighbours together.For example, the following case:
With a majority filter, this would end up as all
0
, while asieve filter
, with threshold of 3 would keep the area as is. The strength of asieve filter
is that you can keep long narrow features, which may be desirable, for some applications - for example a binary classification of flooded areas, where a majority filter could end up removing well defined streams.The filter can be found in GDAL and a UI for it is implemented in QGIS.