CoordinateCleaner包cc_sea()函数无法联网获取数据库问题求助
解决CoordinateCleaner::cc_sea()无法联网读取数据的问题
问题描述
使用CoordinateCleaner包的cc_sea()函数检测海洋坐标时,函数无法自动下载所需的陆地数据,但手动复制报错中的链接可以正常下载压缩包。已重装R 4.2.2、RStudio并仅保留基础包,问题仍存在。
示例代码
library(CoordinateCleaner) library(dplyr) decimallongitude <- c(-99.21751470681781, -119.06093862146821) decimallatitude <- c(19.270324424001558, 4.427074308059391) data_cc <- data.frame(decimallongitude, decimallatitude) data_cc %>% as_tibble %>% mutate(sea = cc_sea(., value = "flagged"))
报错信息
Testing sea coordinates trying URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip' # A tibble: 2 x 3 decimallongitude decimallatitude sea <dbl> <dbl> <lgl> 1 -99.2 19.3 NA 2 -119. 4.43 NA Warning messages: 1: Problem while computing `sea = cc_sea(., value = "flagged")`. i Gazetteer for land mass not found at http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip 2: Problem while computing `sea = cc_sea(., value = "flagged")`. i Skipping sea test
解决方案
1. 手动下载数据并指定本地路径
从报错链接下载ne_110m_land.zip,解压后得到ne_110m_land.shp等文件。调用cc_sea()时通过land参数指定该shp文件路径:
# 替换为你的shp文件实际路径 land_shp <- "path/to/ne_110m_land.shp" data_cc %>% as_tibble() %>% mutate(sea = cc_sea(., value = "flagged", land = land_shp))
2. 检查并修复R的网络设置
若R无法正常联网,可能是代理或SSL设置问题:
- 查看当前网络设置:
Sys.getenv(c("http_proxy", "https_proxy", "all_proxy")) - 若有代理,确保设置正确,或临时取消代理:
Sys.unsetenv(c("http_proxy", "https_proxy", "all_proxy")) - 尝试重置SSL下载方式:
options(download.file.method = "libcurl")
3. 升级CoordinateCleaner包到最新版本
报错中的URL存在重复的http//,大概率是旧版本包的URL拼接bug。升级包后可修复该问题:
install.packages("CoordinateCleaner") # 若需要开发版,可从GitHub安装 # devtools::install_github("ropensci/CoordinateCleaner")
内容的提问来源于stack exchange,提问作者Cameron
相关产品推荐
相关产品推荐

