Given a categorical raster, I'd like filter based on area (ex. number of contiguous pixels) and then:

  1. For island groups (no neighbors) that are smaller than the desired area - remove (set to nodata)
  2. For non island groups that area smaller than the desired area - merge with neighboring group with the longest border

I'm currently using GRASS r.reclass.area method=rmarea for this. The tool works perfectly, but is rather slow as it relies on an intermediate vector conversion step. Are there any alternative tools that are worth checking out?

I've tried various filtering tools (ex. GRASS r.neighbors, SAGA Majority/Minority), but I'm not able to get the desired results.

1 Answer 1


I ended up using GDAL Sieve. It is much faster than the GRASS r.reclass.area method=rmarea approach as it works directly on the raster.

The "-nomask" option can be used to handle the said "island groups".

Here's a sample command for my use case (-st is the size threshold):

gdal_sieve -st 50 -4 -nomask -of GTiff input.tif output.tif

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.