Skip to content

Commit

Permalink
add function to get gdal available driver list - specifying either "v…
Browse files Browse the repository at this point in the history
…ector" or "raster" (currently). This removes a little bit of copied complexity in a few places in the pkg
  • Loading branch information
njtierney committed Mar 22, 2024
1 parent 5c9e677 commit db7bf61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
8 changes: 2 additions & 6 deletions R/tar-terra-rast.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ tar_terra_rast <- function(name,
tidy_eval = tidy_eval
)

# get list of drivers available for writing depending on what the user's GDAL supports
drv <- terra::gdal(drivers = TRUE)
drv <- drv[drv$type == "raster" & grepl("write", drv$can), ]
drv <- get_gdal_available_driver_list("raster")

# if not specified by user, pull the corresponding geotargets option
filetype <- filetype %||% geotargets_option_get("gdal.raster.driver")
Expand Down Expand Up @@ -106,9 +104,7 @@ create_format_terra_raster <- function(filetype, gdal, ...) {

check_pkg_installed("terra")

# get list of drivers available for writing depending on what the user's GDAL supports
drv <- terra::gdal(drivers = TRUE)
drv <- drv[drv$type == "raster" & grepl("write", drv$can), ]
drv <- get_gdal_available_driver_list("raster")

filetype <- filetype %||% geotargets_option_get("gdal.raster.driver")
filetype <- rlang::arg_match0(filetype, drv$name)
Expand Down
8 changes: 2 additions & 6 deletions R/tar-terra-vect.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ tar_terra_vect <- function(name,
tidy_eval = tidy_eval
)

# get list of drivers available for writing depending on what the user's GDAL supports
drv <- terra::gdal(drivers = TRUE)
drv <- drv[drv$type == "vector" & grepl("write", drv$can), ]
drv <- get_gdal_available_driver_list("vector")

# if not specified by user, pull the corresponding geotargets option
filetype <- filetype %||% geotargets_option_get("gdal.vector.driver")
Expand Down Expand Up @@ -124,9 +122,7 @@ create_format_terra_vect <- function(filetype, options, ...) {

check_pkg_installed("terra")

# get list of drivers available for writing depending on what the user's GDAL supports
drv <- terra::gdal(drivers = TRUE)
drv <- drv[drv$type == "vector" & grepl("write", drv$can), ]
drv <- get_gdal_available_driver_list("vector")

if (is.null(filetype)) {
filetype <- "GeoJSON"
Expand Down
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ check_pkg_installed <- function(pkg, call = rlang::caller_env()) {
)
}
}

get_gdal_available_driver_list <- function(driver_type){
# get list of drivers available for writing depending on what the user's GDAL supports
drv <- terra::gdal(drivers = TRUE)
drv <- drv[drv$type == driver_type & grepl("write", drv$can), ]
drv
}

0 comments on commit db7bf61

Please sign in to comment.