I have a raster file where all pixels either are 0 (background) or 1 (see below, available at https://drive.google.com/file/d/1s2g8srXSTL6t-znF9nWbwK8f0C0K5FNk/view?usp=sharing).
I want R to find all regions of connected pixels and give them a unique ID. Then, I want to generate a shapefile via
rasterToPolygons with one polygon for each region.
From what I can see,
clump does the region grouping well. My code so far is:
test <- raster("C:/Users/.../sinks.tif") regions <- clump(test) regions_shp <- rasterToPolygons(regions, na.rm = T)
rasterToPolygons gives me a single polygon for every pixel and does not take into account the clump ID. What am I doing wrong?