Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geometry_type_to_name function #250

Merged
merged 1 commit into from Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
19 changes: 18 additions & 1 deletion src/vector/geometry.rs
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) };
ttencate marked this conversation as resolved.
Show resolved Hide resolved
// If the type is invalid, OGRGeometryTypeToName returns a valid string anyway.
assert!(!rv.is_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