5

I have a raster with the extent of some sinks. Now I need to delete the sinks smaller than 10 squaremetres, 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...)

16

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 thing 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.

| improve this answer | |
  • Ah, but what about eliminating large clumps? – Blazinator Apr 10 '19 at 19:12
  • Depends what you call "large". You could just raise the threshold.. but you will probably remove areas you need.... – gisnside Apr 11 '19 at 6:42
  • But gdal_sieve.py only eliminates pixel clumps below a certain threshold. I'd like an option to eliminate clumps above a threshold. – Blazinator Apr 11 '19 at 13:37
  • oh I see...You should ask a new question it would be interesting to know ;) – gisnside Apr 11 '19 at 19:46
2
  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)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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