Is there a way to replicate the Split Vector Layer function from QGIS in R?
I have a Shapefile containing around 20 polygons that I'd like to split into 20 separate files.
I guess since it's in QGIS there would be a solution in Python, but I'd like to integrate it into a R workflow if possible.
Answer
Yes, you can just loop through the individual features and save them like so:
library (sf)
dat <- read_sf ("~/data.shp")
for (i in seq_len (nrow (dat)))
{
fname <- paste0 ("~/split_", i, ".shp")
write_sf (dat [i, ], fname)
}
No comments:
Post a Comment