I'm sure if this is possible in R, and if someone knows of a way to do this with some other program please let me know
Currently I have a raster, and I need to turn a group of pixels into an NA group if there isn't a large enough cluster. My current thought process was to convert the raster to a polygon, and then calculate the polygons area and remove the polygons if they weren't large enough. The only problem with this is that rasterToPolygon
creates a single layer of polygons, and I have no way of individually indexing each one. Any ideas? Here is an example:
library(raster)
area <- raster(matrix(c(1:4,1),5,5))
shape <- rasterToPolygons(area,fun=function(x){x == 1},dissolve=TRUE)