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

Mosaic: adds band and datatype checks #313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 11 additions & 4 deletions whitebox-raster/src/geotiff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 11 additions & 1 deletion whitebox-tools-app/src/tools/image_analysis/mosaic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down