Skip to content

Commit

Permalink
Add delete layer method and tests in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Atreyagaurav committed Nov 1, 2024
1 parent 5d886ab commit 16f9360
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/vector/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 16f9360

Please sign in to comment.