From 16f936045b1a3ae3b044371fd40d41f8924a907a Mon Sep 17 00:00:00 2001 From: Gaurav Date: Fri, 1 Nov 2024 14:45:51 -0400 Subject: [PATCH] Add delete layer method and tests in doc --- src/vector/layer.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/vector/layer.rs b/src/vector/layer.rs index 3f64a7fa..e8f520cc 100644 --- a/src/vector/layer.rs +++ b/src/vector/layer.rs @@ -728,6 +728,29 @@ 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(); + /// ``` + 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 != gdal_sys::OGRErr::OGRERR_NONE { + Err(GdalError::OgrError { + err, + method_name: "GDALDatasetDeleteLayer", + }) + } else { + Ok(()) + } + } } #[cfg(test)]