2017-04-22 152 views
0

如何將多個.shp文件作爲一個對象讀取?將多個`.shp`文件作爲一個對象讀取?

我想簡單地閱讀代碼。

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

將多個文件作爲對象讀取的最佳方法是什麼?

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) 
+2

如果你在閱讀他們的空間的多邊形data.frame,你可以將它們合併的建議[這裏](https://gis.stackexchange.com/questions/155328/merging-multiple- spatialpolygondataframes-into-1-spdf-in-r),如果沒有,你可能需要尋找arcpy解決方案。 –

回答

2
do.call(rbind, lapply(c("nc1", "nc2"), function(x) st_read("nc", layer = x)))