Skip to content

Commit

Permalink
Merge #250
Browse files Browse the repository at this point in the history
250: Add geometry_type_to_name function r=lnicola a=ttencate

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---



Co-authored-by: Thomas ten Cate <ttencate@gmail.com>
  • Loading branch information
bors[bot] and ttencate committed Jan 29, 2022
2 parents 59d8c0e + 7ba3376 commit 4c0ff09
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -7,6 +7,10 @@

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

- Add `gdal::vector::geometry_type_to_name`

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

## 0.12

- Bump Rust edition to 2021
Expand Down
21 changes: 19 additions & 2 deletions src/vector/geometry.rs
@@ -1,7 +1,7 @@
use std::cell::RefCell;
use std::ffi::CString;
use std::fmt::{self, Debug};
use std::ptr::null_mut;
use std::ptr::{null, null_mut};

use libc::{c_char, c_double, c_int, c_void};

Expand Down Expand Up @@ -437,11 +437,18 @@ impl PartialEq for Geometry {

impl Eq for Geometry {}

pub fn geometry_type_to_name(ty: OGRwkbGeometryType::Type) -> String {
let rv = unsafe { gdal_sys::OGRGeometryTypeToName(ty) };
// If the type is invalid, OGRGeometryTypeToName returns a valid string anyway.
assert!(rv != null());
_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 +547,14 @@ 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),
"Line String"
);
// We don't care what it returns when passed an invalid value, just that it doesn't crash.
geometry_type_to_name(4372521);
}
}
2 changes: 1 addition & 1 deletion src/vector/mod.rs
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 4c0ff09

Please sign in to comment.