diff --git a/src/raster/rasterband.rs b/src/raster/rasterband.rs index 693aefa9..43ccdaa5 100644 --- a/src/raster/rasterband.rs +++ b/src/raster/rasterband.rs @@ -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> { + (1..=self.raster_count()).map(|idx| self.rasterband(idx)) + } + /// Builds overviews for the current `Dataset`. See [`GDALBuildOverviews`]. /// /// # Arguments diff --git a/src/raster/tests.rs b/src/raster/tests.rs index a9313fbc..0f5898a4 100644 --- a/src/raster/tests.rs +++ b/src/raster/tests.rs @@ -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();