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 normalizePath() calls to spatial utils #389

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- `get_biodiversity_intactness_index()`, `get_iucn()`, and `get_key_biodiversity_areas()`
now use `spds_exists()` to check if input files exist
- `spds_exist()` and `make_footprints()` now use `normalizePath()` allowing better
handling of relative file paths

## Internal

Expand Down
4 changes: 4 additions & 0 deletions R/spatial-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#'
spds_exists <- function(path, oo = character(0), what = c("vector", "raster")) {
what <- match.arg(what)
path <- normalizePath(path, mustWork = FALSE)
util <- switch(what,
vector = "ogrinfo",
raster = "gdalinfo"
Expand Down Expand Up @@ -138,6 +139,7 @@ make_footprints <- function(srcs = NULL,

if (inherits(srcs, "character")) {
what <- match.arg(what)
srcs <- normalizePath(srcs, mustWork = FALSE)
srcs <- switch(what,
vector = purrr::map2(srcs, oo, function(src, opt) .vector_footprint(src, opt)),
raster = purrr::map2(srcs, oo, function(src, opt) .raster_footprint(src, opt)),
Expand Down Expand Up @@ -390,7 +392,9 @@ prep_resources <- function(x, avail_resources = NULL, resources = NULL, mode = c
what = c("vector", "raster")) {
what <- match.arg(what)
stopifnot(is.character(source) && length(source) == 1)
source <- normalizePath(source, mustWork = FALSE)
stopifnot(is.character(destination) && length(destination) == 1)
destination <- normalizePath(destination, mustWork = FALSE)
stopifnot(is.null(opts) || is.character(opts))
if (is.null(opts)) opts <- character(0)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-get_resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ test_that("test make_footprints works", {
file.copy(resource_dir, temp_loc, recursive = TRUE)
outdir <- file.path(tempdir(), "mapme.biodiversity", "res")

tifs <- list.files(file.path(outdir, "worldpop"),
tifs <- normalizePath(list.files(file.path(outdir, "worldpop"),
pattern = ".tif$",
recursive = TRUE, full.names = TRUE
)
), mustWork = FALSE)

fps <- make_footprints(tifs, what = "raster")
expect_true(inherits(fps, "sf"))
Expand Down
Loading