-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from brownag/default_opt
Add geotargets options functions, with defaults for raster GDAL driver and creation options
- Loading branch information
Showing
7 changed files
with
127 additions
and
15 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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(geotargets_option_get) | ||
export(geotargets_option_set) | ||
export(tar_terra_rast) | ||
export(tar_terra_vect) | ||
importFrom(rlang,"%||%") | ||
importFrom(rlang,arg_match0) | ||
importFrom(utils,globalVariables) |
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,10 @@ | ||
geotargets.env <- new.env() | ||
|
||
geotargets_env <- function() { | ||
geotargets.env | ||
} | ||
|
||
.onAttach <- function(lib, pkg) { | ||
geotargets.env$geotargets.gdal.raster.creation_options <- "ENCODING=UTF-8" | ||
geotargets.env$geotargets.gdal.raster.driver_name <- "GTiff" | ||
} |
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,65 @@ | ||
#' Get or Set geotargets Options | ||
#' | ||
#' Get or set behavior for geospatial data target stores using geotargets-specific global options. | ||
#' | ||
#' @param option_name Character. Option name. See Details. | ||
#' | ||
#' @details | ||
#' | ||
#' ## Available Options | ||
#' | ||
#' - `"geotargets.gdal.raster.creation_options"` - set the GDAL creation options used when writing raster files to target store (default: `"ENCODING=UTF-8"`) | ||
#' | ||
#' - `"geotargets.gdal.raster.driver_name"` - set the file type used for raster data in target store (default: `"GTiff"`) | ||
#' | ||
#' Each option can be overridden with a system environment variable. Options include: | ||
#' | ||
#' - `GEOTARGETS_GDAL_RASTER_CREATION_OPTIONS` | ||
#' - `GEOTARGETS_GDAL_RASTER_DRIVER_NAME` | ||
#' | ||
#' @rdname geotargets-options | ||
#' @export | ||
geotargets_option_get <- function(option_name) { | ||
if (!startsWith(option_name, "geotargets.")) { | ||
option_name <- paste0("geotargets.", option_name) | ||
} | ||
|
||
option_value <- geotargets_env()[[option_name]] | ||
|
||
get_option <- function(option_name, option_value, name){ | ||
getOption(option_name, default = option_value %||% name) | ||
} | ||
|
||
get_geotargets_gdal_raster_creation_options <- function(option_name, option_value) { | ||
gdal_creation_options <- Sys.getenv( | ||
x = "GEOTARGETS_GDAL_RASTER_CREATION_OPTIONS", | ||
unset = get_option(option_name, option_value, "ENCODING=UTF-8") | ||
) | ||
the_option <- strsplit(gdal_creation_options, ";")[[1]] | ||
the_option | ||
} | ||
|
||
get_geotargets_gdal_raster_driver_name <- function(option_name, option_value) { | ||
Sys.getenv( | ||
x = "GEOTARGETS_GDAL_RASTER_DRIVER_NAME", | ||
unset = get_option(option_name, option_value, "GTiff") | ||
) | ||
} | ||
|
||
switch(option_name, | ||
"geotargets.gdal.raster.creation_options" = | ||
get_geotargets_gdal_raster_creation_options(option_name, option_value), | ||
"geotargets.gdal.raster.driver_name" = | ||
get_geotargets_gdal_raster_driver_name(option_name, option_value) | ||
) | ||
} | ||
|
||
#' @param option_value Value to assign to option `x`. | ||
#' @rdname geotargets-options | ||
#' @export | ||
geotargets_option_set <- function(option_name, option_value) { | ||
if (!startsWith(option_name, "geotargets.")) { | ||
option_name <- paste0("geotargets.", option_name) | ||
} | ||
geotargets.env[[option_name]] <- option_value | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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