Skip to content

Commit

Permalink
Merge branch 'master' into fix/269
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim authored Jun 13, 2022
2 parents d6fdd6a + fb6e260 commit ee3a1cf
Show file tree
Hide file tree
Showing 16 changed files with 1,103 additions and 29 deletions.
14 changes: 13 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

- https://github.com/georust/gdal/pull/267

- **Breaking**: Rename `Driver::get` to `Driver::get_by_name`, add `Driver::get(usize)` and `Driver::count`

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

- Add `programs::raster::build_vrt`
- Add `GeoTransformEx` extension trait with `apply` and `invert`

Expand All @@ -35,6 +39,14 @@

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

- Add support for MDArray API

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

- Add `gdal::srs::CoordTransform::transform_bounds` as wrapper for `OCTTransformBounds` for GDAL 3.4

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

## 0.12

- Bump Rust edition to 2021
Expand Down Expand Up @@ -92,7 +104,7 @@
- <https://github.com/georust/gdal/pull/193>

```rust
let driver = Driver::get("GTiff").unwrap();
let driver = Driver::get_by_name("GTiff").unwrap();
let options = &[
RasterCreationOption {
key: "COMPRESS",
Expand Down
2 changes: 1 addition & 1 deletion examples/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
use gdal::{Dataset, Metadata};
use std::path::Path;

let driver = gdal::Driver::get("mem").unwrap();
let driver = gdal::Driver::get_by_name("mem").unwrap();
println!("driver description: {:?}", driver.description());

let path = Path::new("./fixtures/tinymarble.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/read_write_ogr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn run() -> Result<()> {
// Create a new dataset:
let path = std::env::temp_dir().join("abcde.shp");
let _ = fs::remove_file(&path);
let drv = Driver::get("ESRI Shapefile")?;
let drv = Driver::get_by_name("ESRI Shapefile")?;
let mut ds = drv.create_vector_only(path.to_str().unwrap())?;
let lyr = ds.create_layer(Default::default())?;

Expand Down
2 changes: 1 addition & 1 deletion examples/read_write_ogr_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn run() -> gdal::errors::Result<()> {
// Create a new dataset:
let path = std::env::temp_dir().join("later.geojson");
let _ = std::fs::remove_file(&path);
let drv = Driver::get("GeoJSON")?;
let drv = Driver::get_by_name("GeoJSON")?;
let mut ds = drv.create_vector_only(path.to_str().unwrap())?;
let lyr = ds.create_layer(Default::default())?;

Expand Down
4 changes: 2 additions & 2 deletions examples/write_ogr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fs;
fn example_1() -> Result<()> {
let path = std::env::temp_dir().join("output1.geojson");
let _ = fs::remove_file(&path);
let drv = Driver::get("GeoJSON")?;
let drv = Driver::get_by_name("GeoJSON")?;
let mut ds = drv.create_vector_only(path.to_str().unwrap())?;

let lyr = ds.create_layer(Default::default())?;
Expand Down Expand Up @@ -52,7 +52,7 @@ fn example_1() -> Result<()> {
fn example_2() -> Result<()> {
let path = std::env::temp_dir().join("output2.geojson");
let _ = fs::remove_file(&path);
let driver = Driver::get("GeoJSON")?;
let driver = Driver::get_by_name("GeoJSON")?;
let mut ds = driver.create_vector_only(path.to_str().unwrap())?;
let mut layer = ds.create_layer(Default::default())?;

Expand Down
Binary file added fixtures/alldatatypes.nc
Binary file not shown.
Binary file added fixtures/byte_no_cf.nc
Binary file not shown.
Binary file added fixtures/cf_nasa_4326.nc
Binary file not shown.
27 changes: 24 additions & 3 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ use crate::{
gdal_major_object::MajorObject, raster::RasterBand, spatial_ref::SpatialRef, vector::Layer,
Driver, Metadata,
};

use gdal_sys::OGRGeometryH;
use gdal_sys::{
self, CPLErr, GDALAccess, GDALDatasetH, GDALMajorObjectH, OGRErr, OGRLayerH, OGRwkbGeometryType,
};
use libc::{c_double, c_int, c_uint};

#[cfg(all(major_ge_3, minor_ge_1))]
use crate::raster::Group;

use bitflags::bitflags;

/// A 2-D affine transform mapping pixel coordiates to world
Expand Down Expand Up @@ -415,6 +419,23 @@ impl Dataset {
}
}

/// Opens the root group of a multi-dim GDAL raster
///
/// # Note
/// You must have opened the dataset with the `GdalOpenFlags::GDAL_OF_MULTIDIM_RASTER`
/// flag in order for it to work.
///
#[cfg(all(major_ge_3, minor_ge_1))]
pub fn root_group(&self) -> Result<Group> {
unsafe {
let c_group = gdal_sys::GDALDatasetGetRootGroup(self.c_dataset());
if c_group.is_null() {
return Err(_last_null_pointer_err("GDALDatasetGetRootGroup"));
}
Ok(Group::from_c_group(self, c_group))
}
}

/// Builds overviews for the current `Dataset`. See [`GDALBuildOverviews`].
///
/// # Arguments
Expand Down Expand Up @@ -531,7 +552,7 @@ impl Dataset {
///
/// ```
/// # use gdal::Driver;
/// # let driver = Driver::get("GPKG").unwrap();
/// # let driver = Driver::get_by_name("GPKG").unwrap();
/// # let mut dataset = driver.create_vector_only("/vsimem/example.gpkg").unwrap();
/// let blank_layer = dataset.create_layer(Default::default()).unwrap();
/// ```
Expand All @@ -541,7 +562,7 @@ impl Dataset {
/// ```
/// # use gdal::{Driver, LayerOptions};
/// # use gdal::spatial_ref::SpatialRef;
/// # let driver = Driver::get("GPKG").unwrap();
/// # let driver = Driver::get_by_name("GPKG").unwrap();
/// # let mut dataset = driver.create_vector_only("/vsimem/example.gpkg").unwrap();
/// let roads = dataset.create_layer(LayerOptions {
/// name: "roads",
Expand Down Expand Up @@ -699,7 +720,7 @@ impl Dataset {
/// }
/// #
/// # fn main() -> gdal::errors::Result<()> {
/// # let driver = gdal::Driver::get("SQLite")?;
/// # let driver = gdal::Driver::get_by_name("SQLite")?;
/// # let mut dataset = driver.create_vector_only(":memory:")?;
/// # create_point_grid(&mut dataset)?;
/// # assert_eq!(dataset.layer(0)?.features().count(), 10000);
Expand Down
21 changes: 20 additions & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub struct Driver {
}

impl Driver {
pub fn get(name: &str) -> Result<Driver> {
/// Returns the driver with the given short name.
pub fn get_by_name(name: &str) -> Result<Driver> {
_register_drivers();
let c_name = CString::new(name)?;
let c_driver = unsafe { gdal_sys::GDALGetDriverByName(c_name.as_ptr()) };
Expand All @@ -40,6 +41,24 @@ impl Driver {
Ok(Driver { c_driver })
}

/// Returns the driver with the given index, which must be less than the value returned by
/// `Driver::count()`.
pub fn get(index: usize) -> Result<Driver> {
_register_drivers();
let c_driver = unsafe { gdal_sys::GDALGetDriver(index.try_into().unwrap()) };
if c_driver.is_null() {
return Err(_last_null_pointer_err("GDALGetDriver"));
}
Ok(Driver { c_driver })
}

/// Returns the number of registered drivers.
pub fn count() -> usize {
_register_drivers();
let count = unsafe { gdal_sys::GDALGetDriverCount() };
count.try_into().unwrap()
}

/// Creates a new Driver object by wrapping a C pointer
///
/// # Safety
Expand Down
Loading

0 comments on commit ee3a1cf

Please sign in to comment.