I would like to get the patch sizes in a R terra object, and then filter patches above a threshold.
How do I get patch sizes in terra (and then filter)? The only output I see is patch ID (see plot).
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
x=app(r,function(x) ifelse(x< 400,NA,x))
y=patches(x)
plot(y)
Best Answer
It is best to avoid using
x[]
withSpatRaster
s as that forces all data into memory. That works fine on these examples, but may fail with your real data. In this case, you can usezonal
in stead.You example data:
To count the number of cells by patch
If you want the area covered by these cells, first use
cellSize