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

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?
    – Blazinator
    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....
    – gisnside
    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.
    – Blazinator
    Commented Apr 11, 2019 at 13:37
  • oh I see...You should ask a new question it would be interesting to know ;)
    – gisnside
    Commented Apr 11, 2019 at 19:46
  • Was there a new question posted on removing clumps above a threshold?
    – Binx
    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.
    – Binx
    Commented Mar 10, 2022 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.