Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reclass: 'max' and 'nodata' as valid values #315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions whitebox-tools-app/src/tools/gis_analysis/reclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use std::thread;
///
/// Here, 0.0 is assigned to input grid cell values of 1.0 and 1.0 is output for all input cells with a value of 2.0. Users
/// may add the text strings *min* and *max* in the class definitions to stand in for the raster's minimum and maximum values.
/// Using *max* in a class triplet will change this class from *To Just Less Than* to *To Less Or Equal Than*.
/// For example:
///
/// > --reclass_vals='0.0;min;1.0;1.0;1.0;max'
Expand Down Expand Up @@ -249,18 +250,29 @@ impl WhiteboxTool for Reclass {
}
}
}

let reclass_vals: Vec<f64> = v
.iter()
.map(|s| {
.enumerate()
.map(|(idx, s)| {
if s.to_lowercase().contains("min") {
min_val
} else if s.to_lowercase().contains("max") {
max_val
// Trick in order to consider the max value as included
// in the last class instead of excluded like with the other classes
if !assign_mode && idx % 3 != 0 {
max_val + 1f64
} else {
max_val
}
} else if s.to_lowercase().contains("nodata") {
nodata
} else {
s.trim().parse().unwrap()
}
})
.collect();

if reclass_vals.len() % 3 != 0 && !assign_mode {
return Err(Error::new(ErrorKind::InvalidInput,
"The reclass values string must include triplet values (new value; from value; to less than), e.g. '0.0;0.0;1.0;1.0;1.0;2.0'"));
Expand Down