Skip to content

Commit 3150344

Browse files
committed
address #2298
1 parent 74e6c7f commit 3150344

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

NEWS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# version 1.0-16
22

3-
* add `st_line_project()` to find how far a point is when projected on a line, and `st_line_interpolate()` to obtain a point at a certain distance along a line; #2291
3+
* if environment variable `R_SF_USE_PROJ_DATA` is `true`, `GDAL_DATA`, `PROJ_DATA` (and deprecated `PROJ_LIB`) will not be ignored.
4+
5+
* environment variables `PROJ_LIB` and `PROJ_DATA` are (again) ignored on `sf` binary CRAN installations (win + macos); #2298
6+
7+
* add `st_line_project()` to find how far a point is when projected on a line; #2291
8+
9+
* add `st_line_interpolate()` to obtain a point at a certain distance along a line; #2291
410

511
# version 1.0-15
612

R/init.R

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,43 @@ sf_extSoftVersion = function() {
7272
names = c("GEOS", "GDAL", "proj.4", "GDAL_with_GEOS", "USE_PROJ_H", "PROJ"))
7373
}
7474

75+
if_exists_replace = function(var, new, where) {
76+
if (Sys.getenv(var) != "") {
77+
assign(paste0(".sf.", var), Sys.getenv(var), envir = where)
78+
Sys.setenv(var = new)
79+
}
80+
}
81+
82+
if_exists_restore = function(vars, where) {
83+
fn = function(var, where) {
84+
lname = paste0(".sf.", var)
85+
if (!is.null(get0(lname, envir = where)))
86+
Sys.setenv(var = get(lname, envir = where))
87+
}
88+
lapply(vars, fn, where = where)
89+
}
90+
7591
load_gdal <- function() {
76-
if (file.exists(system.file("proj/nad.lst", package = "sf")[1])) {
77-
# nocov start
78-
prj = system.file("proj", package = "sf")[1]
79-
if (! CPL_set_data_dir(prj)) { # if TRUE, uses C API to set path, leaving PROJ_LIB alone
80-
assign(".sf.PROJ_LIB", Sys.getenv("PROJ_LIB"), envir=.sf_cache)
81-
Sys.setenv("PROJ_LIB" = prj)
92+
if (!identical(Sys.getenv("R_SF_USE_PROJ_DATA"), "true")) {
93+
if (file.exists(prj <- system.file("proj/nad.lst", package = "sf")[1])) {
94+
# nocov start
95+
if (! CPL_set_data_dir(prj)) { # if TRUE, uses C API to set path, leaving PROJ_LIB / PROJ_DATA alone
96+
if_exists_replace("PROJ_LIB", prj, .sf_cache)
97+
if_exists_replace("PROJ_DATA", prj, .sf_cache)
98+
}
99+
CPL_use_proj4_init_rules(1L)
100+
# nocov end
82101
}
83-
CPL_use_proj4_init_rules(1L)
84-
assign(".sf.GDAL_DATA", Sys.getenv("GDAL_DATA"), envir=.sf_cache)
85-
gdl = system.file("gdal", package = "sf")[1]
86-
Sys.setenv("GDAL_DATA" = gdl)
87-
# nocov end
102+
if (file.exists(gdl <- system.file("gdal", package = "sf")[1]))
103+
if_exists_replace("GDAL_DATA", gdl, .sf_cache)
88104
}
89105
CPL_gdal_init()
90106
register_all_s3_methods() # dynamically registers non-imported pkgs (tidyverse)
91107
}
92108

93109
unload_gdal <- function() {
94110
CPL_gdal_cleanup_all()
95-
if (file.exists(system.file("proj/nad.lst", package = "sf")[1])) {
96-
# nocov start
97-
if (! CPL_set_data_dir(system.file("proj", package = "sf")[1])) # set back:
98-
Sys.setenv("PROJ_LIB"=get(".sf.PROJ_LIB", envir=.sf_cache))
99-
100-
Sys.setenv("GDAL_DATA"=get(".sf.GDAL_DATA", envir=.sf_cache))
101-
# nocov end
102-
}
103-
#units::remove_symbolic_unit("link")
104-
#units::remove_symbolic_unit("us_in")
105-
#units::remove_symbolic_unit("ind_yd")
106-
#units::remove_symbolic_unit("ind_ft")
107-
#units::remove_symbolic_unit("ind_ch")
111+
if_exists_restore(c("PROJ_LIB", "PROJ_DATA", "GDAL_DATA"), .sf_cache)
108112
}
109113

110114

0 commit comments

Comments
 (0)