Skip to content

Commit

Permalink
Merge #271
Browse files Browse the repository at this point in the history
271: Add wrapper for `GDALGetRasterUnitType` r=lnicola a=ChristianBeilschmidt

- [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.
---

I've added a wrapper for `GDALGetRasterUnitType` into rasterband. Since I had no test file that has a unit, I added a test file from the original GDAL repo:  https://github.com/OSGeo/gdal/blob/96096ae1e61b1b7afdc686ab9a00ca4fee772ba6/autotest/gdrivers/data/usgsdem/114p01_0100_deme_truncated.dem

Co-authored-by: Christian Beilschmidt <christian.beilschmidt@geoengine.de>
  • Loading branch information
bors[bot] and ChristianBeilschmidt committed May 12, 2022
2 parents 8cb6e92 + f747c81 commit d8aa19a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -19,6 +19,10 @@

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

- Add `gdal::raster::rasterband::RasterBand::unit` as wrapper for `GDALGetRasterUnitType`

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

## 0.12

- Bump Rust edition to 2021
Expand Down
1 change: 1 addition & 0 deletions fixtures/114p01_0100_deme_truncated.dem
@@ -0,0 +1 @@
114p01DEMe Base Mapping and Geomatic Services - B.C. Gov. - Victoria -13615 0.0000 59 0 0.00009 BC 1 1 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 3 2 4 -4.905000e+05 2.124000e+05 -4.905000e+05 2.133000e+05 -4.896000e+05 2.133000e+05 -4.896000e+05 2.124000e+05 -3.276700e+04 -3.276700e+04 0.0 07.500000e-017.500000e-011.000000e+00 1 1 1 4 1 1 1201 1 -4.905000000000000e+05 2.124000000000000e+05 0.000000000000000e+00 -3.276700000000000e+04 -3.276700000000000e+04-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767 -32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767-32767
12 changes: 12 additions & 0 deletions src/raster/rasterband.rs
Expand Up @@ -476,6 +476,18 @@ impl<'a> RasterBand<'a> {
Ok(RasterBand::from_c_rasterband(self.dataset, overview))
}
}

/// Return the unit of the rasterband.
/// If there is no unit, the empty string is returned.
pub fn unit(&self) -> String {
let str_ptr = unsafe { gdal_sys::GDALGetRasterUnitType(self.c_rasterband) };

if str_ptr.is_null() {
return String::new();
}

_string(str_ptr)
}
}

impl<'a> MajorObject for RasterBand<'a> {
Expand Down
13 changes: 13 additions & 0 deletions src/raster/tests.rs
Expand Up @@ -693,3 +693,16 @@ fn test_rasterize() {
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,]
);
}

#[test]
fn test_rasterband_unit() {
let dataset = Dataset::open(fixture!("tinymarble.tif")).unwrap();
let rasterband = dataset.rasterband(1).unwrap();

assert!(rasterband.unit().is_empty());

let dataset = Dataset::open(fixture!("114p01_0100_deme_truncated.dem")).unwrap();
let rasterband = dataset.rasterband(1).unwrap();

assert_eq!(rasterband.unit(), "m".to_string());
}

0 comments on commit d8aa19a

Please sign in to comment.