Skip to content

Commit

Permalink
address #2298
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Dec 21, 2023
1 parent 74e6c7f commit 3150344
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# version 1.0-16

* 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
* if environment variable `R_SF_USE_PROJ_DATA` is `true`, `GDAL_DATA`, `PROJ_DATA` (and deprecated `PROJ_LIB`) will not be ignored.

* environment variables `PROJ_LIB` and `PROJ_DATA` are (again) ignored on `sf` binary CRAN installations (win + macos); #2298

* add `st_line_project()` to find how far a point is when projected on a line; #2291

* add `st_line_interpolate()` to obtain a point at a certain distance along a line; #2291

# version 1.0-15

Expand Down
52 changes: 28 additions & 24 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,43 @@ sf_extSoftVersion = function() {
names = c("GEOS", "GDAL", "proj.4", "GDAL_with_GEOS", "USE_PROJ_H", "PROJ"))
}

if_exists_replace = function(var, new, where) {
if (Sys.getenv(var) != "") {
assign(paste0(".sf.", var), Sys.getenv(var), envir = where)
Sys.setenv(var = new)
}
}

if_exists_restore = function(vars, where) {
fn = function(var, where) {
lname = paste0(".sf.", var)
if (!is.null(get0(lname, envir = where)))
Sys.setenv(var = get(lname, envir = where))
}
lapply(vars, fn, where = where)
}

load_gdal <- function() {
if (file.exists(system.file("proj/nad.lst", package = "sf")[1])) {
# nocov start
prj = system.file("proj", package = "sf")[1]
if (! CPL_set_data_dir(prj)) { # if TRUE, uses C API to set path, leaving PROJ_LIB alone
assign(".sf.PROJ_LIB", Sys.getenv("PROJ_LIB"), envir=.sf_cache)
Sys.setenv("PROJ_LIB" = prj)
if (!identical(Sys.getenv("R_SF_USE_PROJ_DATA"), "true")) {
if (file.exists(prj <- system.file("proj/nad.lst", package = "sf")[1])) {
# nocov start
if (! CPL_set_data_dir(prj)) { # if TRUE, uses C API to set path, leaving PROJ_LIB / PROJ_DATA alone
if_exists_replace("PROJ_LIB", prj, .sf_cache)
if_exists_replace("PROJ_DATA", prj, .sf_cache)
}
CPL_use_proj4_init_rules(1L)
# nocov end
}
CPL_use_proj4_init_rules(1L)
assign(".sf.GDAL_DATA", Sys.getenv("GDAL_DATA"), envir=.sf_cache)
gdl = system.file("gdal", package = "sf")[1]
Sys.setenv("GDAL_DATA" = gdl)
# nocov end
if (file.exists(gdl <- system.file("gdal", package = "sf")[1]))
if_exists_replace("GDAL_DATA", gdl, .sf_cache)
}
CPL_gdal_init()
register_all_s3_methods() # dynamically registers non-imported pkgs (tidyverse)
}

unload_gdal <- function() {
CPL_gdal_cleanup_all()
if (file.exists(system.file("proj/nad.lst", package = "sf")[1])) {
# nocov start
if (! CPL_set_data_dir(system.file("proj", package = "sf")[1])) # set back:
Sys.setenv("PROJ_LIB"=get(".sf.PROJ_LIB", envir=.sf_cache))

Sys.setenv("GDAL_DATA"=get(".sf.GDAL_DATA", envir=.sf_cache))
# nocov end
}
#units::remove_symbolic_unit("link")
#units::remove_symbolic_unit("us_in")
#units::remove_symbolic_unit("ind_yd")
#units::remove_symbolic_unit("ind_ft")
#units::remove_symbolic_unit("ind_ch")
if_exists_restore(c("PROJ_LIB", "PROJ_DATA", "GDAL_DATA"), .sf_cache)
}


Expand Down

0 comments on commit 3150344

Please sign in to comment.