CPL_transform(x, crs, aoi, pipeline, reverse) 中的错误:OGRCreateCoordinateTransformation() 返回 NULL:PROJ 可用?

Dav*_*ond 10 r proj tmap

我正在使用 ubuntu 18.04 并且以下代码生成错误

library(sf)
library(tmap)
library(dplyr)
library(raster)
#sudo apt install libproj-dev
#devtools::install_github("robinlovelace/geocompr")
library(spDataLarge)
if(!file.exists("e.tif"))
  download.file("https://github.com/geocompr/geocompkg/releases/download/0.1/e.tif",
                "e.tif")
elev = raster("e.tif")
urban = spData::urban_agglomerations %>% 
  filter(year == 2030) %>% 
  dplyr::select(population_millions) 
summary(urban)

tm_shape(elev) +
  tm_raster(breaks = c(-10000, 0, 10, 50, 100, 10000)) +
  tm_shape(urban) +
  tm_dots(size = "population_millions", scale = 0.5)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Error in CPL_transform(x, crs, aoi, pipeline, reverse) : 
  OGRCreateCoordinateTransformation() returned NULL: PROJ available?
In addition: Warning message:
In CPL_transform(x, crs, aoi, pipeline, reverse) :
  GDAL Error 1: No PROJ.4 translation for source SRS, coordinate transformation initialization has failed.
Run Code Online (Sandbox Code Playgroud)

如果我更新 PROJ 使用

sudo apt-get install proj-bin
Run Code Online (Sandbox Code Playgroud)

它说我有最新版本

proj-bin is already the newest version (5.2.0-1~bionic0).
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。

Rem*_*sma 16

感谢sf我现在知道解决方案(和问题)的开发人员:

请参阅此处的 github 问题

回顾:

  • 如果您使用较新版本的 GDAL 保存 sf-dataframe,然后尝试st_transform使用较旧版本的 GDAL 的系统,则无法正确读取投影信息(至少在 Ubuntu 18 附带的版本中 - 这也是我遇到了这个问题)。

  • 解决方法是重新设置投影:

st_crs(data) <- 4326  # or whatever projection your data is in
Run Code Online (Sandbox Code Playgroud)

如果您有多个几何列,您可能需要单独设置它:

st_crs(data$areacolumn) <- 4326
Run Code Online (Sandbox Code Playgroud)