R/zzz.R

Defines functions PROJ_unload_proj PROJ_load_proj .onAttach .onUnload .onLoad

## 2022-10-30  up/down stuff cribbed from vapour cribbed from sf
.PROJ_cache <- new.env(FALSE, parent=globalenv())


.onLoad = function(libname, pkgname) {
  PROJ_load_proj()
}

.onUnload = function(libname, pkgname) {
  PROJ_unload_proj()
}

.onAttach = function(libname, pkgname) {

}

PROJ_load_proj <- function() {
  ## data only on
  ## - windows because tools/winlibs.R
  ## - macos because   CRAN mac binary libs, and configure --with-data-copy=yes --with-proj-data=/usr/local/share/proj

  ##PROJ  data, only if the files are in package (will fix in gdalheaders)
  if (file.exists(system.file("proj/nad.lst", package = "PROJ"))) {
    prj = system.file("proj", package = "PROJ")[1L]
    assign(".PROJ.PROJ_LIB", Sys.getenv("PROJ_LIB"), envir=.PROJ_cache)
    Sys.setenv("PROJ_LIB" = prj)
  }

}
# todo
PROJ_unload_proj <- function() {

  if (file.exists(system.file("proj/alaska", package = "PROJ")[1L])) {
    Sys.setenv("PROJ_LIB"=get(".PROJ.PROJ_LIB", envir=.PROJ_cache))
  }
}

Try the PROJ package in your browser

Any scripts or data that you put into this service are public.

PROJ documentation built on April 3, 2025, 9:23 p.m.