I usually work defining zones within agriculture fields taking into account
environmental layers. I have gridded data within the boundaries of the
field and cluster it to create management zones (between 3 and 6). Many
times i end up having in some groups or single cells of zone "x" within
zone "y". This results in spatially discontinuous zones. For visual (and
also practical) purposes i would like to get rid of these isolated patches
that are below a defined area size. That is, change the value of the
"isolated" cells for the one of the zone that surrounds them.
Example (sorry if i'm nor very good at making reproducible examples):
The idea would be to define a minimum area threshold -in my example 11000
m2- that would detect groups of cells below that size and assign them the
value of the grater zone around it (around meaning 'rook' contiguity). This
would result in the original raster before the comment.