3

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.

New contributor
Cowcross is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4

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)
}

Your Answer

Cowcross is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.