Skip to content

Commit

Permalink
Add Dataset::rasterbands
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Feb 26, 2024
1 parent 3c5eb45 commit de86d77
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ impl Dataset {
}
}

/// Get the bands of a dataset.
///
/// Returns an iterator over the [`RasterBands`]s in the current [`Dataset`].
///
/// # Example
///
/// ```rust, no_run
/// use gdal::Dataset;
/// # fn main() -> gdal::errors::Result<()> {
/// let ds = Dataset::open("fixtures/tinymarble.tif")?;
/// assert_eq!(ds.rasterbands().count(), 3);
/// # Ok(())
/// # }
/// ```
pub fn rasterbands(&self) -> impl Iterator<Item = Result<RasterBand>> {
(1..=self.raster_count()).map(|idx| self.rasterband(idx))
}

/// Builds overviews for the current `Dataset`. See [`GDALBuildOverviews`].
///
/// # Arguments
Expand Down
6 changes: 6 additions & 0 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ fn test_read_raster() {
assert_eq!(buf.data(), vec!(7, 7, 7, 10, 8, 12));
}

#[test]
fn test_read_rasterbands() {
let dataset = Dataset::open(fixture("tinymarble.tif")).unwrap();
assert_eq!(dataset.rasterbands().count(), 3);
}

#[test]
fn test_read_raster_with_default_resample() {
let dataset = Dataset::open(fixture("tinymarble.tif")).unwrap();
Expand Down

0 comments on commit de86d77

Please sign in to comment.