Skip to content

Commit

Permalink
Implement wrapper for OGR_L_TestCapability
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarteau committed Feb 4, 2021
1 parent e29d401 commit e910ccb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changes

## Unreleased
* Implement wrapper for `OGR_L_TestCapability`
* <https://github.com/georust/gdal/pull/160>
* **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and
add support for extended open flags.

Expand Down
52 changes: 52 additions & 0 deletions src/vector/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
/// ```
Expand Down Expand Up @@ -101,6 +146,13 @@ impl<'a> Layer<'a> {
_string(rv)
}

pub fn test_capability(&self, capability: LayerCaps::Type) -> Result<bool> {
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
}
Expand Down
2 changes: 1 addition & 1 deletion src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion src/vector/vector_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<F>(ds_name: &str, layer_name: &str, f: F)
where
F: Fn(Layer),
Expand Down

0 comments on commit e910ccb

Please sign in to comment.