Using the terra package, I want to remove island pixels (or isolated pixels) from a categorical raster with 1 category. I want to remove pixels with area smaller than 25000 m, given that the pixel size is 10 m. I found the patches() might be suitable for this task.
Below is my raster:
> r
class : SpatRaster
dimensions : 3115, 2961, 1 (nrow, ncol, nlyr)
resolution : 9.535331, 9.535331 (x, y)
extent : 833145.8, 861379.9, 2690004, 2719707 (xmin, xmax, ymin, ymax)
coord. ref. : WGS 84 / UTM zone 39N (EPSG:32639)
source(s) : memory
name : b1
min value : 1
max value : 1