opengeos / whiteboxR

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

Add error message for file type? #80

Closed jwrozelle closed 2 years ago

jwrozelle commented 2 years ago

So, this is probably because I'm monumentally dumb, but - spent a long time trying to figure out why the raster function wasn't working.

It was because I was using a .img file, rather than a geotiff.

Just a potential thought to add an error message about file type. I could do this and submit a pull request, if helpful.

jblindsay commented 2 years ago

I'm afraid that WBT doesn't support the .img file format. Here is the list of supported raster formats. One of the issues with everyone interacting with WBT using the various frontends, is that it is not always the case that people are aware that the back-end has it's own whole, well-documented user manual (nearly 1000 pages at this point).

jwrozelle commented 2 years ago

What I meant to suggest is to potentially add a helpful error message for dummies like me, rather than reporting an error :), The 101 error was too vague to help me correct my code, and I spent ages trying to figure out what was going wrong. I did figure it out, but, only after a couple of days of installing and re-installing and wondering if I should use something different

jblindsay commented 2 years ago

I can't say what it looks like on the R side, but on the back-end WhiteboxTools side, when you try to read a raster that is not of the supported formats, you should receive and error that states, "Unrecognized raster type". What error did you receive?

brownag commented 2 years ago

It recently came to my attention in another issue (https://github.com/giswqs/whiteboxR/issues/70) that there are are some issues with displaying the "thread main panicked" error messages on Windows. I hadn't noticed that some of error output was being omitted. I have revised the way the system() call error handling works so the tool outputs are printed in addition to the other diagnostics related to the executable, command string etc. This means its a bit more verbose on error but it should show any relevant output printed by the tool now.

Sorry about the confusion that this has clearly caused. Improved error handling was just pushed to the main branch. Can you please test out the latest GitHub version (remotes::install_github('giswqs/whiteboxR')) and see if it gives you a more clear message? I now get (on Windows):

> wbt_slope("D:/elev.img", "D:/slope.tif")

Error running WhiteboxTools (slope)
  whitebox.exe_path: "C:\Program Files\UniversityofGeulphWhiteboxTools1.4.0_WKS\WBT\whitebox_tools.exe"; File exists? TRUE
  Arguments: --run=slope  --dem="D:/elev.img" --output="D:/slope.tif" --units=degrees -v

System command had status 101
********************
* Welcome to Slope *
********************
Reading data...
thread 'main' panicked at 'Unrecognized raster type', src\main.rs:72:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
slope - Elapsed Time: NA [did not run]

One of the issues with everyone interacting with WBT using the various frontends, is that it is not always the case that people are aware that the back-end has it's own whole, well-documented user manual (nearly 1000 pages at this point).

Agreed, I am going to look into beefing up links to the official manual from the R documentation -- which is a bit sparse by comparison.

brownag commented 2 years ago

Another workaround that might be useful to know: you can run any tool with the command_only=TRUE argument to get the command string that would be run by system() in lieu of running it. If you then run that generated command in your terminal it will generally give you the verbose output (as -v flag is included). This is particularly helpful for debugging issues with formatting of command/flags--which we have squashed many related issues in past couple months.

jwrozelle commented 2 years ago

Apologies! Didn't check this for a bit.

@brownag, that's helpful to know!

@jblindsay, if helpful, I can rerun and paste the output.