[R-sig-Geo] proj.db can't be found when rgdal is loaded (sometimes)
Roger Bivand
Roger@B|v@nd @end|ng |rom nhh@no
Mon Sep 14 20:45:45 CEST 2020
On Mon, 14 Sep 2020, Christian John via R-sig-Geo wrote:
> Hi there folks,
>
> I am running into problems using sf objects when rgdal has been loaded.
> When I run:
The following is not a reprex. What we need is the output of:
> sf::sf_extSoftVersion()
GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H
"3.8.1" "3.1.3" "7.1.1" "true" "true"
> rgdal::rgdal_extSoftVersion()
GDAL GDAL_with_GEOS PROJ sp
"3.1.3" "TRUE" "7.1.1" "1.4-4"
(in my case). In your case, the PROJ seen by sf is 7.1.1, by rgdal is
5.2.0. Loading rgdal after sf resets PROJ_LIB to the pre-PROJ 6 version.
You appear to have installed rgdal binary from CRAN, but installed sf
(using homebrew ?) and local GEOS/GDAL/PROJ. Either re-install rgdal to
match, or re-install sf from CRAN as a binary. Installing CRAM MacOS
binaries should ensure coherence. If problems persist, report back (and
perhaps on R-sig-Mac, I have no way to check which GDAL/PROJ versions are
bundled with CAN MacOS binaries.
We are exploring a shared GDAL/PROJ metadata package, but are stuck on the
same problem - users do not take steps to keep their R packages cleanly
built on external software, and package maintainers must expect a
reasonable amount of insight from users.
This list has been given plenty of information that PROJ < 6 and PROJ >= 6
are different universes, so mixing packages using both is not supported.
In this case, sf needs proj.db, but cannot find it once rgdal has been
loaded, pointing PROJ_LIB to a directory without it.
Roger
>
> Sys.getenv("PROJ_LIB")
> library(sf); library(rnaturalearth); library(ggplot2)
> Sys.getenv("PROJ_LIB")
> ROI1 = ne_countries(returnclass = 'sf') %>%
> st_combine() %>%
> st_buffer(0.5) %>%
> st_wrap_dateline()
> ggplot() + geom_sf(data = ROI1)
> library(rgdal)
> Sys.getenv("PROJ_LIB")
> ROI2 = ne_countries(returnclass = 'sf') %>%
> st_combine() %>%
> st_buffer(0.5) %>%
> st_wrap_dateline()
> ggplot() + geom_sf(data = ROI2)
>
> everything plots fine. The sf startup message is:
>
> Linking to GEOS 3.8.1, GDAL 3.1.2, PROJ 7.1.1
>
> The PROJ_LIB changes upon loading rgdal from "" to
> "/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj".
> Loading rgdal generates the message:
>
> Loading required package: sp
> rgdal: version: 1.5-16, (SVN revision 1050)
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
> Path to GDAL shared files:
> /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/gdal
> GDAL binary built with GEOS: FALSE
> Loaded PROJ runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
> Path to PROJ shared files:
> /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
> Linking to sp version:1.4-2
> Overwritten PROJ_LIB was
> /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
> Warning message:
> package ‘rgdal’ was built under R version 3.6.2
>
> which explains the update in the PROJ_LIB. Notably, the gdal and proj
> runtime in the rgdal startup message are completely different from the sf
> versions. If I run:
>
> Sys.getenv("PROJ_LIB")
> library(sf); library(rnaturalearth); library(ggplot2)
> Sys.getenv("PROJ_LIB")
> library(rgdal)
> Sys.getenv("PROJ_LIB")
> ROI2 = ne_countries(returnclass = 'sf') %>%
> st_combine() %>%
> st_buffer(0.5) %>%
> st_wrap_dateline()
> ggplot() + geom_sf(data = ROI2)
>
> which is the same as above, but without the ROI1 generation and plotting, I
> get a stack overflow error upon plotting ROI2. All other messages are the
> same, except when I run the ggplot() line, I get:
>
> Error: node stack overflow
> In addition: There were 50 or more warnings (use warnings() to see the
> first 50)
> Error during wrapup: node stack overflow
>
> Warnings 1:50 are all
>
> 1: In CPL_crs_from_input(x) :
> GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db
>
> So, it seems like loading rgdal before doing anything sf:: related causes
> the issue. Any ideas for troubleshooting? Session info can be found below.
>
> Best,
> Christian
>
>> sessionInfo()
> R version 3.6.1 (2019-07-05)
> Platform: x86_64-apple-darwin15.6.0 (64-bit)
> Running under: macOS Catalina 10.15.6
>
> Matrix products: default
> BLAS:
> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
> LAPACK:
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] rgdal_1.5-16 sp_1.3-2 ggplot2_3.3.0
> rnaturalearth_0.1.0
> [5] sf_0.9-5
>
> loaded via a namespace (and not attached):
> [1] Rcpp_1.0.3 rstudioapi_0.10 magrittr_1.5 units_0.6-5
>
> [5] munsell_0.5.0 tidyselect_0.2.5 colorspace_1.4-1
> lattice_0.20-38
> [9] R6_2.4.1 rlang_0.4.2 dplyr_0.8.3 tools_3.6.1
>
> [13] grid_3.6.1 gtable_0.3.0 KernSmooth_2.23-15 e1071_1.7-3
>
> [17] DBI_1.0.0 withr_2.1.2 rgeos_0.5-5 class_7.3-15
>
> [21] assertthat_0.2.1 lifecycle_0.1.0 tibble_2.1.3 crayon_1.3.4
>
> [25] purrr_0.3.3 glue_1.3.1 compiler_3.6.1 pillar_1.4.3
>
> [29] scales_1.1.0 classInt_0.4-2 pkgconfig_2.0.3
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
More information about the R-sig-Geo
mailing list