Skip to content

Commit

Permalink
Add geometry_type_to_name function
Browse files Browse the repository at this point in the history
  • Loading branch information
ttencate committed Jan 27, 2022
1 parent 2414de2 commit 667cc7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Add `gdal::vector::geometry_type_to_name`

- <https://github.com/georust/gdal/pull/250>

## 0.12

- Bump Rust edition to 2021
Expand Down
18 changes: 17 additions & 1 deletion src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,19 @@ impl PartialEq for Geometry {

impl Eq for Geometry {}

pub fn geometry_type_to_name(ty: OGRwkbGeometryType::Type) -> Result<String> {
let rv = unsafe { gdal_sys::OGRGeometryTypeToName(ty) };
if rv.is_null() {
return Err(_last_null_pointer_err("OGRGeometryTypeToName"));
};
Ok(_string(rv))
}

#[cfg(test)]
mod tests {
use crate::spatial_ref::SpatialRef;

use super::Geometry;
use super::{geometry_type_to_name, Geometry};

#[test]
#[allow(clippy::float_cmp)]
Expand Down Expand Up @@ -540,4 +548,12 @@ mod tests {
);
assert!(buffered.area() > 10.0);
}

#[test]
pub fn test_geometry_type_to_name() {
assert_eq!(
geometry_type_to_name(::gdal_sys::OGRwkbGeometryType::wkbLineString).unwrap(),
"Line String"
);
}
}
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 mod sql;
pub use defn::{Defn, Field, FieldIterator};
pub use feature::{Feature, FieldValue, FieldValueIterator};
pub use gdal_sys::{OGRFieldType, OGRwkbGeometryType};
pub use geometry::Geometry;
pub use geometry::{geometry_type_to_name, Geometry};
pub use layer::{FeatureIterator, FieldDefn, Layer, LayerCaps};
pub use ops::GeometryIntersection;

Expand Down

0 comments on commit 667cc7b

Please sign in to comment.