From 28a724fe648e7ebf6c860c7fe0fd4a32dc1ef51d Mon Sep 17 00:00:00 2001 From: jfbourdon Date: Tue, 10 Jan 2023 13:25:05 -0500 Subject: [PATCH 1/2] max and nodata edit --- whitebox-tools-app/src/tools/gis_analysis/reclass.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/whitebox-tools-app/src/tools/gis_analysis/reclass.rs b/whitebox-tools-app/src/tools/gis_analysis/reclass.rs index ddb7d00b7..4a8a6da2e 100755 --- a/whitebox-tools-app/src/tools/gis_analysis/reclass.rs +++ b/whitebox-tools-app/src/tools/gis_analysis/reclass.rs @@ -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' @@ -255,7 +256,9 @@ impl WhiteboxTool for Reclass { if s.to_lowercase().contains("min") { min_val } else if s.to_lowercase().contains("max") { - max_val + max_val + 0.1f64 + } else if s.to_lowercase().contains("nodata") { + nodata } else { s.trim().parse().unwrap() } From 96d61af519e776ca173912cd58273c6aa4415f14 Mon Sep 17 00:00:00 2001 From: jfbourdon Date: Thu, 12 Jan 2023 14:23:25 -0500 Subject: [PATCH 2/2] fix issue when assigning max --- .../src/tools/gis_analysis/reclass.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/whitebox-tools-app/src/tools/gis_analysis/reclass.rs b/whitebox-tools-app/src/tools/gis_analysis/reclass.rs index 4a8a6da2e..f3ff6d211 100755 --- a/whitebox-tools-app/src/tools/gis_analysis/reclass.rs +++ b/whitebox-tools-app/src/tools/gis_analysis/reclass.rs @@ -250,13 +250,21 @@ impl WhiteboxTool for Reclass { } } } + let reclass_vals: Vec = 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 + 0.1f64 + // 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 { @@ -264,6 +272,7 @@ impl WhiteboxTool for Reclass { } }) .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'"));