Skip to content

Commit 2024aee

Browse files
bors[bot]msalib
andauthored
Merge #212
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]>
2 parents 30bc96f + 62046a6 commit 2024aee

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ let mut dataset = driver
196196

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

199+
- Add `set_description` to the `Metadata` trait
200+
201+
- <https://github.com/georust/gdal/pull/212>
202+
203+
199204
## 0.7.1
200205

201206
- fix docs.rs build for gdal-sys

src/metadata.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,14 @@ pub trait Metadata: MajorObject {
9393
}
9494
Ok(())
9595
}
96+
97+
fn set_description(&mut self, description: &str) -> Result<()> {
98+
// For Datasets this sets the dataset name; normally
99+
// application code should not set the "description" for
100+
// GDALDatasets. For RasterBands it is actually a description
101+
// (if supported) or "".
102+
let c_description = CString::new(description.to_owned())?;
103+
unsafe { gdal_sys::GDALSetDescription(self.gdal_object_ptr(), c_description.as_ptr()) };
104+
Ok(())
105+
}
96106
}

src/raster/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ fn test_set_metadata_item() {
219219
assert_eq!(Some(value.to_owned()), result);
220220
}
221221

222+
#[test]
223+
fn test_set_description() {
224+
let driver = Driver::get("MEM").unwrap();
225+
let dataset = driver.create("", 1, 1, 1).unwrap();
226+
let mut band = dataset.rasterband(1).unwrap();
227+
228+
let description = "A merry and cheerful band description";
229+
assert_eq!(band.description().unwrap(), "");
230+
231+
band.set_description(description).unwrap();
232+
assert_eq!(band.description().unwrap(), description);
233+
}
234+
222235
#[test]
223236
fn test_create() {
224237
let driver = Driver::get("MEM").unwrap();

0 commit comments

Comments
 (0)