12

I have a raster with the extent of some sinks. I need to delete the sinks smaller than 10 square metres, because they are not important for my project.

enter image description here

How could I accomplish that? (It's basically the same problem as here: Removing small "salt & pepper" polygons from layer in QGIS?, only for raster instead of vector data...)

1
  • Perhaps by vectorizing the raster first with gdal.org/gdal_polygonize.html, selecting the small polygons and saving them to a shapefile and finally burning white pixels into the original raster with gdal.org/gdal_rasterize.html by using the shapefile as data source. Commented Sep 16, 2015 at 14:26

2 Answers 2

22

I suppose your pixel size is 10m². You could use the gdal sieve function you can find in the Raster menu to remove lonely pixels. You can also launch it by searching in the command line :

Processing algorithm: Sieve 

Details : http://www.gdal.org/gdal_sieve.html

The gdal_sieve.py script removes raster polygons smaller than a provided threshold size (in pixels) and replaces replaces them with the pixel value of the largest neighbour polygon. The result can be written back to the existing raster band, or copied into a new file.

I think the polygon word is not really appropriate but the tool should do what you want without going through heavy polygon vectorisation. You can raise the value to remove bigger areas or should your pixel size was 1m² for example. You would than use 10 as a threshold.

For french readers, the tool is called "Tamiser" but the tool within gdal is still called Sieve.

6
  • Ah, but what about eliminating large clumps? Commented Apr 10, 2019 at 19:12
  • Depends what you call "large". You could just raise the threshold.. but you will probably remove areas you need.... Commented Apr 11, 2019 at 6:42
  • 1
    But gdal_sieve.py only eliminates pixel clumps below a certain threshold. I'd like an option to eliminate clumps above a threshold. Commented Apr 11, 2019 at 13:37
  • oh I see...You should ask a new question it would be interesting to know ;) Commented Apr 11, 2019 at 19:46
  • Was there a new question posted on removing clumps above a threshold? Commented Mar 10, 2022 at 15:09
4
  1. Vectorize your raster with Raster>Conversion>Polygonize.
  2. Then use the filed calculator and create a new field area: Function Geometry > $area
  3. Afterwards you can filter out the small polygons (right click on vector layer)
  4. Save the filtered layer to another vector layer.
  5. Rasterize the filtered vector layer (Raster>Conversion>Rasterize)
1
  • An issue with this is if you raster layer contains too many noncontiguous blocks, the Polygonize tool can take hours. Commented Mar 10, 2022 at 15:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.