geotargets_option_set {geotargets} | R Documentation |
Get or Set geotargets Options
Description
Get or set behaviour for geospatial data target stores using geotargets-specific global options.
Usage
geotargets_option_set(
gdal_raster_driver = NULL,
gdal_raster_creation_options = NULL,
gdal_raster_data_type = NULL,
gdal_vector_driver = NULL,
gdal_vector_creation_options = NULL,
terra_preserve_metadata = NULL
)
geotargets_option_get(name)
Arguments
gdal_raster_driver |
character, length 1; set the driver used for raster
data in target store (default: |
gdal_raster_creation_options |
character; set the GDAL creation options
used when writing raster files to target store (default: |
gdal_raster_data_type |
character; Data type for writing raster file.
One of: |
gdal_vector_driver |
character, length 1; set the file type used for
vector data in target store (default: |
gdal_vector_creation_options |
character; set the GDAL layer creation
options used when writing vector files to target store (default:
|
terra_preserve_metadata |
character. When |
name |
character; option name to get. |
Details
These options can also be set using options()
. For example,
geotargets_options_set(gdal_raster_driver = "GTiff")
is equivalent to
options("geotargets.gdal.raster.driver" = "GTiff")
.
Value
Specific options, such as "gdal.raster.driver". See "Details" for more information.
Potential issues retaining metadata
If you have an issue with retaining metadata (such as units, time, etc), this could be due to the versions of GDAL and terra on your machine. We recommend exploring if this issue persists outside of geotargets. That is, try saving the file out and reading it back in using regular R code. If you find that this is an issue with geotargets, please file an issues at https://github.com/ropensci/geotargets/issues/ and we will try and get this working for you.
Examples
# For CRAN. Ensures these examples run under certain conditions.
# To run this locally, run the code inside this if statement
if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") {
# tar_dir() runs code from a temporary directory.
targets::tar_dir({
library(geotargets)
op <- getOption("geotargets.gdal.raster.driver")
withr::defer(options("geotargets.gdal.raster.driver" = op))
geotargets_option_set(
gdal_raster_driver = "COG",
terra_preserve_metadata = "zip"
)
targets::tar_script({
list(
geotargets::tar_terra_rast(
terra_rast_example,
{
new_rast <- system.file("ex/elev.tif", package = "terra") |>
terra::rast()
terra::units(new_rast) <- "m"
new_rast
}
)
)
})
targets::tar_make()
x <- targets::tar_read(terra_rast_example)
x
terra::units(x)
})
}
geotargets_option_get("gdal.raster.driver")
geotargets_option_get("gdal.raster.creation.options")