You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用rnaturalearth下载Natural Earth边界框失败问题咨询

关于rnaturalearth下载边界框失败的问题

问题背景

此前正常运行的Natural Earth边界框下载命令现在报错,代码及运行日志如下:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE

bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
                  returnclass = "sf")
#> Warning 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_wgs84_bounding_box.zip':
#> HTTP status was '404 Not Found'
#> 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_wgs84_bounding_box.zip'

sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux 11 (bullseye)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] sf_1.0-9            rnaturalearth_0.1.0 dplyr_1.0.10       
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9         compiler_4.2.2     pillar_1.8.1       highr_0.9         
#>  [5] class_7.3-20       R.methodsS3_1.8.2  R.utils_2.12.1     tools_4.2.2       
#>  [9] digest_0.6.30      lattice_0.20-45    evaluate_0.18      lifecycle_1.0.3   
#> [13] tibble_3.1.8       R.cache_0.16.0     pkgconfig_2.0.3    rlang_1.0.6       
#> [17] reprex_2.0.2       cli_3.4.1          DBI_1.1.3          yaml_2.3.6        
#> [21] xfun_0.35          fastmap_1.1.0      e1071_1.7-12       withr_2.5.0       
#> [25] styler_1.8.0       stringr_1.5.0      knitr_1.41         generics_0.1.3    
#> [29] fs_1.5.2           vctrs_0.5.1        grid_4.2.2         classInt_0.4-8    
#> [33] tidyselect_1.2.0   glue_1.6.2         R6_2.5.1           fansi_1.0.3       
#> [37] rmarkdown_2.17     sp_1.5-1           purrr_1.0.0        magrittr_2.0.3    
#> [41] units_0.8-0        htmltools_0.5.3    assertthat_0.2.1   KernSmooth_2.23-20
#> [45] utf8_1.2.2         proxy_0.4-27       stringi_1.7.8      R.oo_1.25.0

Created on 2023-01-05 with reprex v2.0.2

该边界框文件的正确路径可用,但ne_download生成了重复域名的错误链接,导致404。现咨询两个问题:

  1. 这是否是rnaturalearth包的bug?
  2. 若手动将zip文件下载至工作目录,有无可行的解决办法?

问题解答

1. 是否为rnaturalearth包的bug?

是。从错误链接能看到,ne_download拼接URL时重复了域名部分,生成了包含两次域名的无效地址,这属于包内部URL构造逻辑的错误。这个问题在rnaturalearth的旧版本(比如你使用的0.1.0)中存在,后续版本已修复该URL拼接问题。

2. 手动下载后的解决办法

如果已经把zip文件下载到工作目录,可以用以下步骤读取:

  • 先解压zip文件到临时目录或指定文件夹:
unzip("ne_110m_wgs84_bounding_box.zip", exdir = tempdir())
  • 再用sf::st_read读取解压后的shp文件:
bb <- st_read(file.path(tempdir(), "ne_110m_wgs84_bounding_box.shp"), quiet = TRUE)

若直接解压到工作目录,也可简化为:

bb <- st_read("ne_110m_wgs84_bounding_box.shp", quiet = TRUE)

更彻底的解决方式是升级rnaturalearth到最新版本,这样ne_download就能正常生成正确URL下载文件:

install.packages("rnaturalearth")

内容的提问来源于stack exchange,提问作者larry77

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 22:40:56