0

how to read multiple .shp file as one object?

I want to read simply like under the code.

nc <- st_read(dsn = "nc",
              layer = c("nc1","nc2"))

what is the best method to read multiple files as a object?

library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))

nc1 <- nc[1:50, ]
nc2 <- nc[51:100, ]

st_write(nc1,
         dsn = "nc",
         layer = "nc1",
         driver = "ESRI Shapefile")

st_write(nc2,
         dsn = "nc",
         layer = "nc2",
         driver = "ESRI Shapefile",update = T)
ogw
  • 353
  • 1
  • 2
  • 13
  • 2
    if you are reading them as spatial-polygons data.frame, you could merge them as suggested [here](https://gis.stackexchange.com/questions/155328/merging-multiple-spatialpolygondataframes-into-1-spdf-in-r), If not, you might have to look for arcpy solutions. – Adam Quek Apr 22 '17 at 05:23

1 Answers1

4
do.call(rbind, lapply(c("nc1", "nc2"), function(x) st_read("nc", layer = x)))
Edzer Pebesma
  • 3,814
  • 16
  • 26