forked from gearslaboratory/gdalUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function needed to avoid problems related to side effects upon loading of rgdal/sf on Windows systems with GDAL 3 installed (see r-spatial/discuss#31) The function automatically resets the PROJ_LIB environment variable to the "correct" folder for a GDAL3 installation, and restores the previous value upon exiting from the caller function (to avoid breaking rgdal/sf functionality). The function needs to be called within each function calling a gdal binary requiring the PROJ_LIB environment variable to be properly set.
- Loading branch information
Showing
3 changed files
with
136 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#' @title set_projlibpath | ||
#' @description Function needed to avoid problems related to side effects upon loading | ||
#' of rgdal/sf on Windows systems with GDAL 3 installed (see https://github.com/r-spatial/discuss/issues/31) | ||
#' @return The function is used for its side effects | ||
#' @details The function automatically resets the PROJ_LIB environment variable to the | ||
#' "correct" folder for a GDAL3 installation, and restores the previous value upon | ||
#' exiting from the caller function. | ||
#' @rdname set_projlibpath | ||
|
||
set_projlibpath <- function() { | ||
# reset properly the PROJ_LIB environment library | ||
if (substr(getOption("gdalUtils_gdalPath")[[1]]$version, 1, 1) >= 3 && Sys.info()[["sysname"]] == "Windows") { | ||
rgdal_projlibpath <- Sys.getenv("PROJ_LIB") | ||
projlib_path_ok <- file.path(dirname(getOption("gdalUtils_gdalPath")[[1]]$path), "share/proj") | ||
Sys.setenv("PROJ_LIB" = projlib_path_ok) | ||
do.call(on.exit, | ||
list(substitute(Sys.setenv("PROJ_LIB" = rgdal_projlibpath))), | ||
envir = parent.frame() | ||
) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.