我一天前刚开始使用 R,我正在尝试使用 SF 库读取 geojson 文件,但我不确定正确的方法是什么。
library(dplyr)
library(sf)
geo <- system.file('/my/path/zones.geojson', package = 'sf')
st_read(geo)
当我运行这些代码行时,我收到错误消息:
Cannot open data source
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
Open failed.
请大家告诉我如何修改,谢谢大家!
The sf
包本身无法读取 geojson。不过,有一个包叫geojsonsf
将 geojson 读取到您可以使用的数据中sf
.
显然我没有你的 geojson 文件可以使用,但包本身附带了一些示例数据,以便我可以向你展示原理:
install.packages("geojsonsf")
library(geojsonsf)
library(ggplot2)
geo <- geojson_sf("C:/R/R-3.6.2/library/geojsonsf/examples/geo_melbourne.geojson")
ggplot(geo) + geom_sf(aes(fill = SA2_NAME)) + guides(fill = guide_none())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)