Skip to content

Commit

Permalink
Add Rasterband::fill
Browse files Browse the repository at this point in the history
Signed-off-by: netthier <lp@senselabs.de>
  • Loading branch information
netthier committed Apr 18, 2024
1 parent 54fbdfd commit 89d23c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Added `Rasterband::fill`
- <https://github.com/georust/gdal/pull/528>

- Added `Dataset::rasterbands`.
- <https://github.com/georust/gdal/pull/523>

Expand Down
10 changes: 10 additions & 0 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,16 @@ impl<'a> RasterBand<'a> {
Ok(())
}
}

/// Fill this band with a constant value.
pub fn fill(&mut self, real_value: f64, imaginary_value: Option<f64>) -> Result<()> {
let rv = unsafe { gdal_sys::GDALFillRaster(self.c_rasterband, real_value, imaginary_value.unwrap_or(0.0)) };
if rv != CPLErr::CE_None {
return Err(_last_cpl_err(rv));
}
Ok(())
}

/// Returns the color interpretation of this band.
pub fn color_interpretation(&self) -> ColorInterpretation {
let interp_index = unsafe { gdal_sys::GDALGetRasterColorInterpretation(self.c_rasterband) };
Expand Down
10 changes: 10 additions & 0 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ fn test_set_no_data_value() {
assert_eq!(rasterband.no_data_value(), None);
}

#[test]
fn test_fill() {
let driver = DriverManager::get_driver_by_name("MEM").unwrap();
let dataset = driver.create("", 5, 5, 1).unwrap();
let mut rasterband = dataset.rasterband(1).unwrap();
assert!(rasterband.fill(5.4, None).is_ok());
let contents = rasterband.read_as::<u8>((0, 0), (5, 5), (5, 5), None).unwrap();
assert!(contents.data().iter().all(|&v| v == 5));
}

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

0 comments on commit 89d23c5

Please sign in to comment.