From aae69d0cb75de0b521f75b8adb8585a7eafe4b0c Mon Sep 17 00:00:00 2001 From: jfbourdon Date: Sun, 8 Jan 2023 01:21:09 -0500 Subject: [PATCH 1/2] correctly store nb bands of GTiff --- whitebox-raster/src/geotiff/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/whitebox-raster/src/geotiff/mod.rs b/whitebox-raster/src/geotiff/mod.rs index d3ed21fc..96a8772b 100755 --- a/whitebox-raster/src/geotiff/mod.rs +++ b/whitebox-raster/src/geotiff/mod.rs @@ -485,10 +485,17 @@ pub fn read_geotiff<'a>( } }; - // let num_samples = match ifd_map.get(&277) { - // Some(ifd) => ifd.interpret_as_u16()[0], - // _ => 0, - // }; + match ifd_map.get(&277) { + Some(ifd) => { + configs.bands = ifd.interpret_as_u16()[0] as u8; // warning: a GeoTIFF can contain more than 256 bands + } + _ => { + return Err(Error::new( + ErrorKind::InvalidData, + "The raster SamplesPerPixel value was not read correctly", + )) + } + }; match ifd_map.get(&280) { Some(ifd) => { From 883485d473bd7cac1a014cbc9fe13b634ef6b420 Mon Sep 17 00:00:00 2001 From: jfbourdon Date: Sun, 8 Jan 2023 01:22:00 -0500 Subject: [PATCH 2/2] new checks input raster --- .../src/tools/image_analysis/mosaic.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/whitebox-tools-app/src/tools/image_analysis/mosaic.rs b/whitebox-tools-app/src/tools/image_analysis/mosaic.rs index dba38370..ae6388bb 100755 --- a/whitebox-tools-app/src/tools/image_analysis/mosaic.rs +++ b/whitebox-tools-app/src/tools/image_analysis/mosaic.rs @@ -20,7 +20,7 @@ use std::sync::mpsc; use std::sync::Arc; use std::thread; -/// This tool will create an image mosaic from one or more input image files using +/// This tool will create an image mosaic from two or more single band input image files using /// one of three resampling methods including, nearest neighbour, bilinear interpolation, /// and cubic convolution. The order of the input source image files is important. Grid /// cells in the output image will be assigned the corresponding value determined from the @@ -320,6 +320,16 @@ impl WhiteboxTool for Mosaic { if res.is_ok() { inputs.push(res.unwrap()); //Raster::new(&input_file, "r")?).expect(&format!("Error reading file: {}", value))); nodata_vals.push(inputs[i].configs.nodata); + + if inputs[i].configs.data_type != inputs[0].configs.data_type { + return Err(Error::new(ErrorKind::InvalidInput, + "There is something incorrect about the input files. All inputs must be of the same data type.")); + } + + if inputs[i].configs.bands > 1 { + return Err(Error::new(ErrorKind::InvalidInput, + "There is something incorrect about the input files. All inputs must be single band.")); + } if i == 0 { if inputs[i].configs.north < inputs[i].configs.south {