Skip to content

Commit

Permalink
Implement Geometry::flatten_to_2d
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Aug 6, 2023
1 parent 8ab1545 commit 7a6285b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ impl Geometry {
}
}

/// Converts geometry to strictly 2D.
///
/// See: [`OGR_G_FlattenTo2D`](https://gdal.org/api/vector_c_api.html#_CPPv417OGR_G_FlattenTo2D12OGRGeometryH)
pub fn flatten_to_2d(&mut self) {
unsafe { gdal_sys::OGR_G_FlattenTo2D(self.c_geometry()) };
}

/// Get the spatial reference system for this geometry.
///
/// Returns `Some(SpatialRef)`, or `None` if one isn't defined.
Expand Down Expand Up @@ -439,6 +446,13 @@ mod tests {
assert!(!geom.is_empty());
}

#[test]
pub fn test_flatten_to_2d() {
let mut geom = Geometry::from_wkt("POINT (0 1 2)").unwrap();
geom.flatten_to_2d();
assert_eq!(geom.wkt().unwrap(), "POINT (0 1)");
}

#[test]
pub fn test_create_multipoint_2d() {
let mut geom = Geometry::empty(wkbMultiPoint).unwrap();
Expand Down

0 comments on commit 7a6285b

Please sign in to comment.