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

Rterm与RStudio控制台运行sp::CRS及ggspatial函数报错求助

我使用reprex::reprex()运行下述代码可得到正常结果,但在Rterm和RStudio控制台中执行时出现报错,暂未找到有效解决方案。

Rterm/RStudio控制台报错代码及提示

rgdal::rgdal_extSoftVersion()
#> Error: no such table: metadata
sp::CRS(SRS_string='EPSG:4326')
#> Error in sp::CRS(SRS_string = "EPSG:4326") : NA
sp::CRS("+init=epsg:4326")
#> Error in sp::CRS("+init=epsg:4326") : NA

ggplot2::ggplot() +
   ggspatial::annotation_map_tile(
     zoom = 13, cachedir = system.file("rosm.cache", package = "ggspatial")) +
   ggplot2::geom_sf(data = longlake_waterdf, fill = NA, col = "grey50")
#> Error in sp::CRS(paste0("+init=epsg:", epsg)) : NA

reprex环境下正常运行的代码及输出

sf::sf_extSoftVersion()
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>        "3.9.1"        "3.2.1"        "7.2.1"         "true"         "true" 
#>           PROJ 
#>        "7.2.1"
 
rgdal::rgdal_extSoftVersion()
#>           GDAL GDAL_with_GEOS           PROJ             sp           EPSG 
#>        "3.2.1"         "TRUE"        "7.2.1"        "1.4-5"      "v10.008"

sp::CRS(SRS_string='EPSG:4326')
#> CRS arguments: +proj=longlat +datum=WGS84 +no_defs
sp::CRS("+init=epsg:4326")
#> CRS arguments: +proj=longlat +datum=WGS84 +no_defs
 
wkt <- sf::st_crs(4326)[[2]]
sp::CRS(wkt)
#> CRS arguments: +proj=longlat +datum=WGS84 +no_defs


ggspatial::load_longlake_data()

ggplot2::ggplot() +
  ggspatial::annotation_map_tile(
    zoom = 13, cachedir = system.file("rosm.cache", package = "ggspatial")) +
  ggplot2::geom_sf(data = longlake_waterdf, fill = NA, col = "grey50")
#> Zoom: 13

运行结果图

由reprex包(v2.0.1)于2021-10-22创建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 09:15:08