Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GDAL min version requirement for writing .shz #97

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions R/tar-terra-vect.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ create_format_terra_vect_shz <- function() {

check_pkg_installed("terra")
#difficult to test
if (terra::gdal(lib = "gdal") < "3.1") {
rlang::abort("Writing a .shz file requires GDAL version 3.1 or greater")
}
check_gdal_shz(min_version = "3.1")

targets::tar_format(
read = function(path) terra::vect(paste0("/vsizip/{", path, "}")),
Expand Down
20 changes: 20 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ check_pkg_installed <- function(pkg, call = rlang::caller_env()) {
}
}

check_gdal_version <- function(min_version = "3.1") {
terra_gdal <- numeric_version(terra::gdal(lib = "gdal"))
version <- numeric_version(min_version)
terra_gdal < min_version
Aariq marked this conversation as resolved.
Show resolved Hide resolved
Aariq marked this conversation as resolved.
Show resolved Hide resolved
}

check_gdal_shz <- function(min_version = "3.1",
call = rlang::caller_env()){
if (check_gdal_version(min_version)) {
cli::cli_abort(
message = c(
"Must have {.pkg GDAL} version {.val {min_version}} or greater",
"i" = "To write a {.val .shz} file requires GDAL version \\
{.val {min_version}} or greater"
),
call = call
)
}
}

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)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/check-gdal-shz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# GDAL version checked checked

Code
check_gdal_shz()
Condition
Error:
! Must have GDAL version "3.1" or greater
i To write a ".shz" file requires GDAL version "3.1" or greater

9 changes: 9 additions & 0 deletions tests/testthat/test-check-gdal-shz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test_that("GDAL version checked checked", {
local_mocked_bindings(
check_gdal_version = function(...) TRUE
Aariq marked this conversation as resolved.
Show resolved Hide resolved
)
expect_snapshot(
error = TRUE,
check_gdal_shz()
)
})
Loading