Skip to content

Commit 0173cf0

Browse files
bors[bot]geohardtkeChristianBeilschmidt
authored
Merge #273
273: MDArray r=jdroenner 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 rebased and extended the following PR since it seems to be inactive: #233 I tried to solve my own suggestions. However, please take a look at everything. Moreover, I ran the tests with `RUSTFLAGS="-Z sanitizer=leak" cargo +nightly-2022-04-12-x86_64-unknown-linux-gnu test --all-features -- raster::mdarray::tests` to check for memory leaks. All new NetCDF files are taken from GDAL's repo at OSGeo. Co-authored-by: Leonardo Hardtke <[email protected]> Co-authored-by: Christian Beilschmidt <[email protected]>
2 parents b700dc0 + 41228ff commit 0173cf0

File tree

7 files changed

+933
-0
lines changed

7 files changed

+933
-0
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
- <https://github.com/georust/gdal/pull/246>
3333

34+
- Add support for MDArray API
35+
36+
- <https://github.com/georust/gdal/pull/273>
37+
3438
## 0.12
3539

3640
- Bump Rust edition to 2021

fixtures/alldatatypes.nc

34.1 KB
Binary file not shown.

fixtures/byte_no_cf.nc

1.39 KB
Binary file not shown.

fixtures/cf_nasa_4326.nc

18.4 KB
Binary file not shown.

src/dataset.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ use crate::{
1717
gdal_major_object::MajorObject, raster::RasterBand, spatial_ref::SpatialRef, vector::Layer,
1818
Driver, Metadata,
1919
};
20+
2021
use gdal_sys::OGRGeometryH;
2122
use gdal_sys::{
2223
self, CPLErr, GDALAccess, GDALDatasetH, GDALMajorObjectH, OGRErr, OGRLayerH, OGRwkbGeometryType,
2324
};
2425
use libc::{c_double, c_int, c_uint};
2526

27+
#[cfg(all(major_ge_3, minor_ge_1))]
28+
use crate::raster::Group;
29+
2630
use bitflags::bitflags;
2731

2832
/// A 2-D affine transform mapping pixel coordiates to world
@@ -415,6 +419,23 @@ impl Dataset {
415419
}
416420
}
417421

422+
/// Opens the root group of a multi-dim GDAL raster
423+
///
424+
/// # Note
425+
/// You must have opened the dataset with the `GdalOpenFlags::GDAL_OF_MULTIDIM_RASTER`
426+
/// flag in order for it to work.
427+
///
428+
#[cfg(all(major_ge_3, minor_ge_1))]
429+
pub fn root_group(&self) -> Result<Group> {
430+
unsafe {
431+
let c_group = gdal_sys::GDALDatasetGetRootGroup(self.c_dataset());
432+
if c_group.is_null() {
433+
return Err(_last_null_pointer_err("GDALDatasetGetRootGroup"));
434+
}
435+
Ok(Group::from_c_group(self, c_group))
436+
}
437+
}
438+
418439
/// Builds overviews for the current `Dataset`. See [`GDALBuildOverviews`].
419440
///
420441
/// # Arguments

0 commit comments

Comments
 (0)