lovalery
lovalery

Reputation: 4662

R package "RQGIS3" cannot find proj.db

When I try to launch the RQGIS3 package, R returns the following error message : "proj_create_from_database: Cannot find proj.db"

> library(reticulate)
> library(RQGIS3)
> set_env(root="C:/Program Files/QGIS 3.12")
$root
[1] "C:/Program Files/QGIS 3.12"

$qgis_prefix_path
[1] "C:/Program Files/QGIS 3.12/apps/qgis"

$python_plugins
[1] "C:/Program Files/QGIS 3.12/apps/qgis/python/plugins"

$platform
[1] "Windows"

> open_app()
proj_create_from_database: Cannot find proj.db
proj_create_from_database: Cannot find proj.db

Yet, PROJ_LIB does exist...

> Sys.getenv("PROJ_LIB")
[1] "C:/Program Files/QGIS 3.12/share/proj;C:/Users/toto/Documents/R/win-library/3.6/rgdal/proj"

I would be very grateful if you could help me. Thank you in advance.

If it helps, below is the information about my R session :

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C
[5] LC_TIME=French_France.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] RQGIS3_1.0.1.9000 reticulate_1.16

loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6       rstudioapi_0.11    raster_3.1-5       magrittr_1.5       units_0.6-6        hms_0.5.3          lattice_0.20-38
[8] R6_2.4.1           rlang_0.4.6        stringr_1.4.0      tools_3.6.3        parallel_3.6.3     rgdal_1.5-8        grid_3.6.3
[15] KernSmooth_2.23-16 e1071_1.7-3        DBI_1.1.0          class_7.3-15       ellipsis_0.3.1     tibble_3.0.1       lifecycle_0.2.0
[22] crayon_1.3.4       sf_0.9-3           Matrix_1.2-18      readr_1.3.1        vctrs_0.3.0        codetools_0.2-16   sp_1.4-2
[29] stringi_1.4.6      compiler_3.6.3     pillar_1.4.4       classInt_0.4-3     jsonlite_1.6.1     pkgconfig_2.0.3

Upvotes: 1

Views: 1533

Answers (1)

Rui Lima
Rui Lima

Reputation: 7423

Not an R developer here, but I was having the same issue with C# and this seems to sort it out

Osr.SetPROJSearchPath(Environment.GetEnvironmentVariable("PROJ_LIB"));

See if there is an equivalent for R

There seems to be something, maybe you can make more sense out of it

get_proj_search_paths <- function() {
    if (PROJis6ormore()) {
        res <- .Call("get_proj_search_path", PACKAGE="rgdal")
        res <- strsplit(res, .Platform$path.sep)[[1]]
    } else {
        res <- NULL
    }
    res
}

set_proj_search_paths <- function(paths) {
    if (PROJis6ormore()) {
        stopifnot(!missing(paths))
        stopifnot(is.character(paths))
        stopifnot(length(paths) > 0)
        n <- length(paths)
        for (i in 1:n) stopifnot(dir.exists(paths[i]))
        res <- .Call("set_proj_paths", paths, PACKAGE="rgdal")
    } else {
        res <- NULL
    }
    res
}

Upvotes: 1

Related Questions