Apply a sieve filter. That is, remove "noise", by changing small clumps of cells with a value that is different from the surrounding cells, to the value of the largest neighbouring clump.
Usage
# S4 method for SpatRaster
sieve(x, threshold, directions=8, filename="", ...)
Arguments
x
SpatRaster, single layer with elevation values. Values should have the same unit as the map units
threshold
positive integer. Only clumps smaller than this threshold will be removed
directions
numeric to indicate which cells are connected. Either 4 to only consider the horizontal and vertical neighbors ("rook"), or 8 to consider the vertical, horizontal and diagonal neighbors