jblindsay / whitebox-tools

An advanced geospatial data analysis platform
https://www.whiteboxgeo.com/
MIT License
967 stars 161 forks source link

min/max statistics not computed at readout for all raster formats #422

Open jfbourdon opened 4 months ago

jfbourdon commented 4 months ago

Somes hydrology tools automatically evaluate an appropriate flat increment value based on the maximal value stored in the input DEM (see BreachDepressionsLeastCost, BreachDepressions, FillBurn, FillDepressionsPlanchonAndDardoux, FillDepressionsWandAndLiu, FillDepressions, FlowAccumFullWorkflow, UpslopeDepressionStorage). The issue is that this statistic isn't calculate at readout for all file formats but only for Surfer 7, Surfer ASCII, Idrisi, ESRI BIL, Arc Binary and Whitebox (so missing for GeoTiff, Arc ASCII, GRASS and SAGA).

This means that for the later formats, a line like (input.configs.maximum as i32).to_string().len() will output 11 and thus generate a flat increment value of 200 (for a 1 unit cell size) instead of a much smaller and appropriate value.

https://github.com/jblindsay/whitebox-tools/blob/ccca69ab9fbadd26229a62e540033541e4768fd5/whitebox-tools-app/src/tools/hydro_analysis/breach_depressions.rs#L316-L322

I see two options to fix this:

  1. In each of the aforementioned tools, compute the maximal value instead of relying on what is stored inside the raster config object.
  2. Make computing (and ideally not reading from metadata) min/max statistics for all raster formats. This option has a higher cost, but as other tools might also need those statistics, it avoids having to add lines of code to multiple tools and ensure an application wide fix.