Skip to content

Commit

Permalink
Check output type in read_block
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Dec 10, 2023
1 parent 30fea92 commit 0527371
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- `RasterBand::read_block` now checks that the requested type matches the band type.

- <https://github.com/georust/gdal/pull/489>

- Added `Geometry::difference`.

- <https://github.com/georust/gdal/pull/487>
Expand Down
6 changes: 6 additions & 0 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ impl<'a> RasterBand<'a> {
/// # Notes
/// The Matrix shape is (rows, cols) and raster shape is (cols in x-axis, rows in y-axis).
pub fn read_block<T: Copy + GdalType>(&self, block_index: (usize, usize)) -> Result<Array2<T>> {
if T::gdal_ordinal() != self.band_type() as u32 {
return Err(GdalError::BadArgument(
"result array type must match band data type".to_string(),
));
}

let size = self.block_size();
let pixels = size.0 * size.1;
let mut data: Vec<T> = Vec::with_capacity(pixels);
Expand Down

0 comments on commit 0527371

Please sign in to comment.