From e910ccbab7bd461b12fc6b3c43c317804f773791 Mon Sep 17 00:00:00 2001 From: David Marteau Date: Thu, 4 Feb 2021 11:38:36 +0100 Subject: [PATCH] Implement wrapper for OGR_L_TestCapability --- CHANGES.md | 2 ++ src/vector/layer.rs | 52 ++++++++++++++++++++++++++++++++++ src/vector/mod.rs | 2 +- src/vector/vector_tests/mod.rs | 15 +++++++++- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e24c393b..ce43f715 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Changes ## Unreleased +* Implement wrapper for `OGR_L_TestCapability` + * * **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and add support for extended open flags. diff --git a/src/vector/layer.rs b/src/vector/layer.rs index ad32664d..58ce0349 100644 --- a/src/vector/layer.rs +++ b/src/vector/layer.rs @@ -13,6 +13,51 @@ use std::{convert::TryInto, ffi::CString, marker::PhantomData}; use crate::errors::*; +/// Layer capabilities, map GDAL defines +#[allow(non_upper_case_globals)] +#[allow(non_snake_case)] +pub mod LayerCaps { + + pub type Type = &'static str; + + /// Layer capability for random read + pub const OLCRandomRead: Type = "RandomRead"; + /// Layer capability for sequential write + pub const OLCSequentialWrite: Type = "SequentialWrite"; + /// Layer capability for random write + pub const OLCRandomWrite: Type = "RandomWrite"; + /// Layer capability for fast spatial filter + pub const OLCFastSpatialFilter: Type = "FastSpatialFilter"; + /// Layer capability for fast feature count retrieval + pub const OLCFastFeatureCount: Type = "FastFeatureCount"; + /// Layer capability for fast extent retrieval + pub const OLCFastGetExtent: Type = "FastGetExtent"; + /// Layer capability for field creation + pub const OLCCreateField: Type = "CreateField"; + /// Layer capability for field deletion + pub const OLCDeleteField: Type = "DeleteField"; + /// Layer capability for field reordering + pub const OLCReorderFields: Type = "ReorderFields"; + /// Layer capability for field alteration + pub const OLCAlterFieldDefn: Type = "AlterFieldDefn"; + /// Layer capability for transactions + pub const OLCTransactions: Type = "Transactions"; + /// Layer capability for feature deletiond + pub const OLCDeleteFeature: Type = "DeleteFeature"; + /// Layer capability for setting next feature index + pub const OLCFastSetNextByIndex: Type = "FastSetNextByIndex"; + /// Layer capability for strings returned with UTF-8 encoding + pub const OLCStringsAsUTF8: Type = "StringsAsUTF8"; + /// Layer capability for field ignoring + pub const OLCIgnoreFields: Type = "IgnoreFields"; + /// Layer capability for geometry field creation + pub const OLCCreateGeomField: Type = "CreateGeomField"; + /// Layer capability for curve geometries support + pub const OLCCurveGeometries: Type = "CurveGeometries"; + /// Layer capability for measured geometries support + pub const OLCMeasuredGeometries: Type = "MeasuredGeometries"; +} + /// Layer in a vector dataset /// /// ``` @@ -101,6 +146,13 @@ impl<'a> Layer<'a> { _string(rv) } + pub fn test_capability(&self, capability: LayerCaps::Type) -> Result { + let rv = unsafe { + gdal_sys::OGR_L_TestCapability(self.c_layer, CString::new(capability)?.as_ptr()) == 1 + }; + Ok(rv) + } + pub fn defn(&self) -> &Defn { &self.defn } diff --git a/src/vector/mod.rs b/src/vector/mod.rs index 4c6b9e90..651b2f6c 100644 --- a/src/vector/mod.rs +++ b/src/vector/mod.rs @@ -27,7 +27,7 @@ pub use defn::{Defn, Field, FieldIterator}; pub use feature::{Feature, FieldValue, FieldValueIterator}; pub use gdal_sys::{OGRFieldType, OGRwkbGeometryType}; pub use geometry::Geometry; -pub use layer::{FeatureIterator, FieldDefn, Layer}; +pub use layer::{FeatureIterator, FieldDefn, Layer, LayerCaps}; pub use ops::GeometryIntersection; use crate::errors::Result; diff --git a/src/vector/vector_tests/mod.rs b/src/vector/vector_tests/mod.rs index 07f35fd0..3bfccbfa 100644 --- a/src/vector/vector_tests/mod.rs +++ b/src/vector/vector_tests/mod.rs @@ -1,5 +1,6 @@ use super::{ - Feature, FeatureIterator, FieldValue, Geometry, Layer, OGRFieldType, OGRwkbGeometryType, + Feature, FeatureIterator, FieldValue, Geometry, Layer, LayerCaps::*, OGRFieldType, + OGRwkbGeometryType, }; use crate::spatial_ref::SpatialRef; use crate::{assert_almost_eq, Dataset, Driver}; @@ -63,6 +64,18 @@ fn test_layer_spatial_ref() { assert_eq!(srs.auth_code().unwrap(), 4326); } +#[test] +fn test_layer_capabilities() { + let mut ds = Dataset::open(fixture!("roads.geojson")).unwrap(); + let layer = ds.layer(0).unwrap(); + + assert_eq!(layer.test_capability(OLCFastSpatialFilter).unwrap(), false); + assert_eq!(layer.test_capability(OLCFastFeatureCount).unwrap(), true); + assert_eq!(layer.test_capability(OLCFastGetExtent).unwrap(), false); + assert_eq!(layer.test_capability(OLCRandomRead).unwrap(), true); + assert_eq!(layer.test_capability(OLCStringsAsUTF8).unwrap(), true); +} + fn ds_with_layer(ds_name: &str, layer_name: &str, f: F) where F: Fn(Layer),