Skip to content

Commit

Permalink
Add delete layer method and tests in doc (#583)
Browse files Browse the repository at this point in the history
Add `Dataset::delete_layer`
  • Loading branch information
Atreyagaurav authored Nov 3, 2024
1 parent 5d886ab commit 0644110
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
strategy:
matrix:
version:
- latest # 3.10.0
- 3.9.3
- 3.8.5
- 3.7.3
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Added

- Add `Dataset::delete_layer` ([#583](https://github.com/georust/gdal/pull/583))
- Add a `bundled` feature for `gdal-sys` for building and statically linking a minimal bundled version of GDAL ([#517](https://github.com/georust/gdal/pull/517))
- Add pre-built bindings for GDAL 3.10 ([#573](https://github.com/georust/gdal/pull/573))
- Add methods `alternative_name`, `is_nullable`, `is_unique`, `default_value` to `Field` ([#561](https://github.com/georust/gdal/pull/561))
Expand Down
24 changes: 24 additions & 0 deletions src/vector/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,30 @@ impl Dataset {
};
Ok(self.child_layer(c_layer))
}

/// Deletes the layer at given index
///
/// ```
/// # use gdal::DriverManager;
/// # let driver = DriverManager::get_driver_by_name("GPKG").unwrap();
/// # let mut dataset = driver.create_vector_only("/vsimem/example.gpkg").unwrap();
/// let blank_layer = dataset.create_layer(Default::default()).unwrap();
/// assert!(dataset.delete_layer(1).is_err());
/// dataset.delete_layer(0).unwrap();
/// assert_eq!(dataset.layers().count(), 0);
/// ```
pub fn delete_layer(&mut self, idx: usize) -> Result<()> {
let idx = c_int::try_from(idx)?;
let err = unsafe { gdal_sys::GDALDatasetDeleteLayer(self.c_dataset(), idx) };
if err != OGRErr::OGRERR_NONE {
Err(GdalError::OgrError {
err,
method_name: "GDALDatasetDeleteLayer",
})
} else {
Ok(())
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit 0644110

Please sign in to comment.