我想将目录中的所有 shapefile 读入全局环境但是,当我在工作目录中获取文件列表时,该列表包含 .shp 和 .shp.xml 文件,后者是我不想要的。我的草稿代码读取 .shp 和 .shp.xml 文件。我怎样才能阻止它这样做?
草案代码如下:
库(地图工具)
# get all files with the .shp extension from working directory
setwd("N:/Dropbox/_BonesFirst/139_Transit_Metros_Points_Subset_by_R")
shps <- dir(getwd(), "*.shp")
# the assign function will take the string representing shp
# and turn it into a variable which holds the spatial points data
for (shp in shps) {
cat("now loading", shp, "...", '\n\r')
assign(shp, readOGR(shp))
}
Run Code Online (Sandbox Code Playgroud)
编辑:问题似乎出在 readShapePoints 中。readOGR(来自 rgdal)或 shapefile(来自 raster)效果更好。