r - 无法使用 sf() 和 rnaturalearth() 在 R 中提取湖泊几何数据

标签 r ggplot2 maps shapefile r-sf

我在尝试使用 rnaturalearth 包提取大湖数据时收到错误消息。我已经使用相同的代码一段时间了,直到今天才收到错误。我不确定该网站是否已关闭,但这种情况已经持续了几周了。我posted on their github但尚未收到回复。其他人可以复制此错误或知道如何解决它或获取相同数据的解决方法吗?

install.packages('rnaturalearth','sf')
lakes <- rnaturalearth::ne_download(scale = 110, 
                                    type = 'lakes', 
                                    category = 'physical') %>% 
  sf::st_as_sf(lakes110, crs = 4269) %>% filter(name_alt =="Great Lakes")

错误消息:

trying URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
Error in utils::download.file(file.path(address), zip_file <- tempfile()) : 
  cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
In addition: Warning message:
In utils::download.file(file.path(address), zip_file <- tempfile()) :
  cannot open URL 'https://www.naturalearthdata.com/http/www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip': HTTP status was '404 Not Found'

最佳答案

我最近遇到了同样的问题,并使用以下代码获取了世界上所有湖泊的高分辨率形状文件:

library(sf)

url <- paste0("https://www.naturalearthdata.com/",
              "http//www.naturalearthdata.com/download/10m/physical/",
              "ne_10m_lakes.zip")

path <- tempdir()
download.file(url, paste0(path, "/lakes.zip"))
unzip(paste0(path, "/lakes.zip"))
lakes <- read_sf("ne_10m_lakes.shp")

例如,以下是用于绘制五大湖的数据:

library(ggplot2)

ggplot(lakes) +
  geom_sf(fill = "lightblue") +
  coord_sf(xlim = c(-100, -75), ylim = c(40, 50)) +
  theme(panel.background = element_rect(fill = '#d0d890'),
        panel.grid = element_line(color = '#00000010'))

enter image description here

关于r - 无法使用 sf() 和 rnaturalearth() 在 R 中提取湖泊几何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75149027/

相关文章:

r - 绘制更平滑的多条线

r - 如何将列名传递给处理 data.frames 的函数

R编程,使用变量命名输出文件

r - 使用 scale_colour_brewer 调色板的极值

php - Google map 通过更改 mysql 坐标更新标记

javascript - 谷歌地图可以设置为慢速恒平移吗?就像一场全局革命?

json - 在 R 中将 markdown 转换为 json

r - 在一张图中绘制计数和累积数字

r - 为什么我没有使用 ggplot2 获得两个图例?

带有 3D 标记的 Android 谷歌地图?