I need to erase different vector layers(shapefiles) using R, but I am not sure how to do it in a fast way.
I have 10 different shapefiles and a basemap (also shapefile) that I need to erase my vectors from (I need something equivalent to using the "difference" tool in QGIS).
I know how to do it manually, using the ms_erase
tool, but I was wondering if there is an easy way of iterating this process:
output1 <- ms_erase(basemap, vector1)
output2 <- ms_erase(output1 , vector2)
output3 <- ms_erase(output2 , vector3)
I loaded the vectors using the st_read
function, so their class in R is data.frame.
ms_dissolve
your combined files afterrbind
and beforems_erase
if the shapes are complex or overlap. Installing Node.js and usingsys = TRUE
inms_erase
can also boost performance quite a bit if your first attempt crashes or takes too long.dplyr::bind_rows()
will work betterms_erase
function come from? Why aren't you using thest_difference
function fromsf
? Can you read all your shapefiles into a list of objects and loop over that list?