Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rasterband::set_no_data accepting Option<f64>. #308

Merged
merged 3 commits into from Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Expand Up @@ -10,6 +10,11 @@

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

- Added ability to delete no-data when `None` is passed to `RasterBand::set_no_data(&mut self, no_data: Option<f64>))`

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


## 0.13

- Add prebuild bindings for GDAL 3.5
Expand Down
21 changes: 18 additions & 3 deletions src/raster/rasterband.rs
Expand Up @@ -431,12 +431,27 @@ impl<'a> RasterBand<'a> {
}

/// Set the no data value of this band.
///
/// See [`set_no_data`](Self::set_no_data) for similar function
/// where _no-data_ can also be deleted.
pub fn set_no_data_value(&mut self, no_data: f64) -> Result<()> {
let rv = unsafe { gdal_sys::GDALSetRasterNoDataValue(self.c_rasterband, no_data) };
self.set_no_data(Some(no_data))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If backward compatibility weren't an option, I would have changed this signature of this to accept Option<f64> over creating a new method and delegating to it. Should we consider a breaking change here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to change the API, we're only on 0.13.


/// Set the no data state of this band.
/// If `no_data` is `None`, any existing no-data value is deleted.
pub fn set_no_data(&mut self, no_data: Option<f64>) -> Result<()> {
let rv = if let Some(no_data) = no_data {
unsafe { gdal_sys::GDALSetRasterNoDataValue(self.c_rasterband, no_data) }
} else {
unsafe { gdal_sys::GDALDeleteRasterNoDataValue(self.c_rasterband) }
};

if rv != CPLErr::CE_None {
return Err(_last_cpl_err(rv));
Err(_last_cpl_err(rv))
} else {
Ok(())
}
Ok(())
}

/// Returns the color interpretation of this band.
Expand Down
2 changes: 2 additions & 0 deletions src/raster/tests.rs
Expand Up @@ -559,6 +559,8 @@ fn test_set_no_data_value() {
assert_eq!(rasterband.no_data_value(), None);
assert!(rasterband.set_no_data_value(1.23).is_ok());
assert_eq!(rasterband.no_data_value(), Some(1.23));
assert!(rasterband.set_no_data(None).is_ok());
assert_eq!(rasterband.no_data_value(), None);
}

#[test]
Expand Down