This PR implements several new places where path expansion and file-path-helpers via wbt_file_path() can be applied
First example is reproducing the issue from #55. Now works because of the shell quoting done automatically by wbt_file_path().
Also the wd argument of all wbt_* tools now performs path expansion. Other methods of setting wd already supported this.
library(whitebox)
library(terra)
library(elevatr)
wbt_verbose(TRUE)
if (!dir.exists("~/wbtwdtest"))
dir.create("~/wbtwdtest")
setwd("~/wbtwdtest")
wbt_wd("")
#> Reset WhiteboxTools working directory to current R working directory: /home/andrew/wbtwdtestUnset WhiteboxTools working directory flag `whitebox.wd` / `--wd`
dir.create("Input")
dir.create("Output")
# sample tile locations
xy <- data.frame(x = -seq(119, 120, 0.5), y = 37)
# download tiles
dat <- lapply(1:nrow(xy), function(i) {
# need two points/tile to use get_elev_raster()
# add +0.0001 to x coord to duplicate
setNames(terra::rast(elevatr::get_elev_raster(rbind(xy[i,], transform(xy[i,], x = x + 0.0001)),
prj = "EPSG:4326", z = 10)),
nm = "Elevation")
})
# write sample tiles to file in Input folder
tiles <- lapply(seq_along(dat), function(i) {
writeRaster(dat[[i]], sprintf("Input/test%s.tif", i), overwrite = TRUE)
})
# now this works! (all relative paths with semicolon separator)
wbt_mosaic(output = "Output/foo.tif", inputs = "Input/test1.tif;Input/test2.tif;Input/test3.tif")
#> mosaic - Elapsed Time (including I/O): 0.97s
An added benefit is path expansion inside semicolon separated lists:
library(whitebox)
library(terra)
library(elevatr)
wbt_verbose(TRUE)
if (!dir.exists("~/wbtwdtest"))
dir.create("~/wbtwdtest")
dir.create("~/wbtwdtest/Input")
dir.create("~/wbtwdtest/Output")
# sample tile locations
xy <- data.frame(x = -seq(119, 120, 0.5), y = 37)
# download tiles
dat <- lapply(1:nrow(xy), function(i) {
# need two points/tile to use get_elev_raster()
# add +0.0001 to x coord to duplicate
setNames(terra::rast(elevatr::get_elev_raster(rbind(xy[i,], transform(xy[i,], x = x + 0.0001)),
prj = "EPSG:4326", z = 10)),
nm = "Elevation")
})
# write sample tiles to file in Input folder
tiles <- lapply(seq_along(dat), function(i) {
writeRaster(dat[[i]], sprintf("~/wbtwdtest/Input/test%s.tif", i), overwrite = TRUE)
})
# path expansion in semicolon separated list!
wbt_mosaic(output = "~/wbtwdtest/Output/foo.tif", inputs = "~/wbtwdtest/Input/test1.tif;~/wbtwdtest/Input/test2.tif;~/wbtwdtest/Input/test3.tif")
#> mosaic - Elapsed Time (including I/O): 0.83s
This PR implements several new places where path expansion and file-path-helpers via
wbt_file_path()
can be appliedwbt_file_path()
.wd
argument of allwbt_*
tools now performs path expansion. Other methods of settingwd
already supported this.