opengeos / whiteboxR

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

Bug: Found and resolved a bug in "wbt_resample()" #112

Closed Pentaonia closed 1 year ago

Pentaonia commented 1 year ago

When you want to resample on basis of an other raster, it says that it does not find the base raster path. There was a missing "wbt_file_path()" arround the "base". I corrected the function:

wbt_resample <- function (inputs, output, cell_size = NULL, base = NULL, method = "cc", 
    wd = NULL, verbose_mode = FALSE, compress_rasters = FALSE, 
    command_only = FALSE) {

    wbt_init()
    args <- ""
    args <- paste(args, paste0("--inputs=", wbt_file_path(inputs)))
    args <- paste(args, paste0("--output=", wbt_file_path(output)))
    if (!is.null(cell_size)) {
        args <- paste(args, paste0("--cell_size=", cell_size))
    }
    if (!is.null(base)) {
        args <- paste(args, paste0("--base=", wbt_file_path(base))) #### <- there was it missing
    }
    if (!is.null(method)) {
        args <- paste(args, paste0("--method=", method))
    }
    if (!missing(wd)) {
        args <- paste(args, paste0("--wd=", wbt_file_path(wd)))
    }
    if (!missing(compress_rasters)) {
        args <- paste(args, paste0("--compress_rasters=", compress_rasters))
    }
    tool_name <- "resample"
    wbt_run_tool(tool_name, args, verbose_mode, command_only)
}

Hope that helps and you can implement that.

All the best Louis

brownag commented 1 year ago

Thanks for pointing this out! This is an oversight I made such that the optional path provided by base doesn't get the same treatment other input/output file paths get.

I have corrected this in #113; this affected quite a few other functions that take a base argument!

In the future there will be a significant refactor of the generating code such that the file path arguments are all consistently identified, but this should work for now. Please let me know if you encounter other cases like this, I was surprised to see I had missed this one.