Skip to content

Commit

Permalink
Make raster index usize
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Sep 6, 2023
1 parent d93ab7f commit be85fa5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 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

- **Breaking**: `Dataset::raster_count` now returns an `usize` and `Dataset::rasterband` now takes `usize` instead of `isize`

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

## 0.16

- **Breaking**: `Dataset::close` now consumes `self`
Expand Down
6 changes: 3 additions & 3 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl Dataset {
///
/// Applies to raster datasets, and fetches the
/// rasterband at the given _1-based_ index.
pub fn rasterband(&self, band_index: isize) -> Result<RasterBand> {
pub fn rasterband(&self, band_index: usize) -> Result<RasterBand> {
unsafe {
let c_band = gdal_sys::GDALGetRasterBand(self.c_dataset, band_index as c_int);
if c_band.is_null() {
Expand Down Expand Up @@ -667,8 +667,8 @@ impl Dataset {
}

/// Fetch the number of raster bands on this dataset.
pub fn raster_count(&self) -> isize {
(unsafe { gdal_sys::GDALGetRasterCount(self.c_dataset) }) as isize
pub fn raster_count(&self) -> usize {
(unsafe { gdal_sys::GDALGetRasterCount(self.c_dataset) }) as usize
}

/// Returns the raster dimensions: (width, height).
Expand Down
5 changes: 3 additions & 2 deletions src/raster/rasterize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
/// may be of any GDAL supported datatype.
pub fn rasterize(
dataset: &mut Dataset,
bands: &[isize],
bands: &[usize],
geometries: &[Geometry],
burn_values: &[f64],
options: Option<RasterizeOptions>,
Expand All @@ -178,8 +178,9 @@ pub fn rasterize(
geometries.len()
)));
}
let raster_count = dataset.raster_count();
for band in bands {
let is_good = *band > 0 && *band <= dataset.raster_count();
let is_good = *band > 0 && *band <= raster_count;
if !is_good {
return Err(GdalError::BadArgument(format!(
"Band index {} is out of bounds",
Expand Down

0 comments on commit be85fa5

Please sign in to comment.