opengeos / whiteboxR

WhiteboxTools R Frontend
https://whiteboxR.gishub.org
Other
172 stars 30 forks source link

Remove heuristics for finding whitebox; not generic! #41

Closed brownag closed 3 years ago

brownag commented 3 years ago

Resolves #40; the former "find whitebox" method was something I had tinkered with and was concerned at the time that it might not do what the user wants.

Thanks to @bkielstr tested it and had various issues on windows and macos, thanks for reporting it! I didn't anticipate those specific problems, I was more concerned about it accidentally finding the wrong binary or one that didnt have permissions to execute!

Testing the latest using a snippet from the readme of https://github.com/bkielstr/hydroweight on my work computer (limited to WBT 1.4.0 for now, need newer version approved)

## Load libraries

Sys.setenv(R_WHITEBOX_EXE_PATH = 'C:/Program Files/UniversityofGeulphWhiteboxTools1.4.0_WKS/WBT/whitebox_tools.exe')

library(raster)
library(whitebox)
library(hydroweight)

## Import toy_dem from whitebox package
toy_file <- system.file("extdata", "DEM.tif", package = "whitebox")
toy_dem <- raster(x = toy_file, values = TRUE)
crs(toy_dem) <- "+init=epsg:3161"

## Generate hydroweight_dir as a temporary directory
hydroweight_dir <- tempdir()

## Write toy_dem to hydroweight_dir
writeRaster(
  x = toy_dem, filename = file.path(hydroweight_dir, "toy_dem.tif"),
  overwrite = TRUE
)

## Breach depressions to ensure continuous flow
wbt_breach_depressions(
  dem = file.path(hydroweight_dir, "toy_dem.tif"),
  output = file.path(hydroweight_dir, "toy_dem_breached.tif")
)
#> [1] "breach_depressions - Elapsed Time (excluding I/O): 0.10s"