Skip to content

Commit

Permalink
Merge #212
Browse files Browse the repository at this point in the history
212: Add set description r=msalib a=msalib

- [X] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [X] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---
This is a really simple change that allows users to set descriptions on major GDAL objects; that's mostly useful for RasterBands. If you prefer I could just make this a method on `RasterBand` only instead of more generally making it part of the `Metadata` trait.


Co-authored-by: Michael Salib <[email protected]>
  • Loading branch information
bors[bot] and msalib authored Sep 1, 2021
2 parents 30bc96f + 62046a6 commit 2024aee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ let mut dataset = driver

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

- Add `set_description` to the `Metadata` trait

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


## 0.7.1

- fix docs.rs build for gdal-sys
Expand Down
10 changes: 10 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ pub trait Metadata: MajorObject {
}
Ok(())
}

fn set_description(&mut self, description: &str) -> Result<()> {
// For Datasets this sets the dataset name; normally
// application code should not set the "description" for
// GDALDatasets. For RasterBands it is actually a description
// (if supported) or "".
let c_description = CString::new(description.to_owned())?;
unsafe { gdal_sys::GDALSetDescription(self.gdal_object_ptr(), c_description.as_ptr()) };
Ok(())
}
}
13 changes: 13 additions & 0 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ fn test_set_metadata_item() {
assert_eq!(Some(value.to_owned()), result);
}

#[test]
fn test_set_description() {
let driver = Driver::get("MEM").unwrap();
let dataset = driver.create("", 1, 1, 1).unwrap();
let mut band = dataset.rasterband(1).unwrap();

let description = "A merry and cheerful band description";
assert_eq!(band.description().unwrap(), "");

band.set_description(description).unwrap();
assert_eq!(band.description().unwrap(), description);
}

#[test]
fn test_create() {
let driver = Driver::get("MEM").unwrap();
Expand Down

0 comments on commit 2024aee

Please sign in to comment.