首页 > 解决方案 > 在 R 中读取 shapefile 时出错

问题描述

当我尝试在 R 中循环读取 shapefile 时,它​​总是报告

“.local(x, ...) 中的错误:file.exists(extension(x, ".shp")) 不是 TRUE”。

我用来读取 shapefile 的代码是

 "city.i=shapefile(citynames1[i]) " 

其中 citynames1 是 shapefile 名称的向量,扩展名为.shp.

非常感谢您的帮助。

标签: r

解决方案


问题与您 PC 上的区域设置有关。在我的情况下sf,包可以写汉字文件,请看下面的代码:

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


# write shape
st_write(nc, "你好.shp")


# clear & read
rm(list = ls())
nc <- st_read("你好.shp")
plot(nc)

输出:

地图


推荐阅读