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 all commits
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Created utility function `set_window()` mostly for internal use within `tar_terra_tiles()`.
* Removes the `iteration` argument from all `tar_*()` functions. `iteration` now hard-coded as `"list"` since it is the only option that works (for now at least).
* Added the `description` argument to all `tar_*()` functions which is passed to `tar_target()`.
* Requires GDAL 3.1 or greater to use "ESRI Shapefile" driver in `tar_terra_vect()` (#71, #97)

# geotargets 0.1.0 (14 May 2024)

Expand Down
2 changes: 2 additions & 0 deletions R/tar-terra-vect.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ create_format_terra_vect <- function() {
create_format_terra_vect_shz <- function() {

check_pkg_installed("terra")
#difficult to test
check_gdal_shz(min_version = "3.1")

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

gdal_version <- function() {
numeric_version(terra::gdal(lib = "gdal"))
}

check_gdal_shz <- function(min_version = "3.1",
call = rlang::caller_env()){
if (gdal_version() < numeric_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(
gdal_version = function(...) "3.0.0"
)
expect_snapshot(
error = TRUE,
check_gdal_shz()
)
})
Loading