Skip to content

Commit

Permalink
Unsquish
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Jan 10, 2025
1 parent 7bbccb7 commit 2d28cc8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
29 changes: 19 additions & 10 deletions src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ impl Geometry {
let mut y: c_double = 0.;
let mut z: c_double = 0.;
let mut m: c_double = 0.;
unsafe { gdal_sys::OGR_G_GetPointZM(self.c_geometry(), index, &mut x, &mut y, &mut z, &mut m) };
unsafe {
gdal_sys::OGR_G_GetPointZM(self.c_geometry(), index, &mut x, &mut y, &mut z, &mut m)
};
(x, y, z, m)
}

/// Appends all points of a line string to `out_points`.
/// Appends all points of a line string to `out_points`.
///
/// Only wkbPoint[X], wkbLineString[X] or wkbCircularString[X] may alter `out_points`. Other geometry types will silently do nothing, see
/// [`OGR_G_GetPointCount`](https://gdal.org/en/stable/api/vector_c_api.html#_CPPv419OGR_G_GetPointCount12OGRGeometryH)
Expand All @@ -229,7 +231,7 @@ impl Geometry {
length as usize
}

/// Appends all points of a line string to `out_points`.
/// Appends all points of a line string to `out_points`.
///
/// Only wkbPoint[X], wkbLineString[X] or wkbCircularString[X] may alter `out_points`. Other geometry types will silently do nothing, see
/// [`OGR_G_GetPointCount`](https://gdal.org/en/stable/api/vector_c_api.html#_CPPv419OGR_G_GetPointCount12OGRGeometryH)
Expand Down Expand Up @@ -444,13 +446,12 @@ pub fn geometry_type_to_name(ty: OGRwkbGeometryType::Type) -> String {
_string(rv).unwrap_or_default()
}


/// Returns the 2D geometry type corresponding to the passed geometry type.
/// Returns the 2D geometry type corresponding to the passed geometry type.
pub fn geometry_type_flatten(ty: OGRwkbGeometryType::Type) -> OGRwkbGeometryType::Type {
unsafe { gdal_sys::OGR_GT_Flatten(ty) }
}

/// Returns the 3D geometry type corresponding to the passed geometry type.
/// Returns the 3D geometry type corresponding to the passed geometry type.
pub fn geometry_type_set_z(ty: OGRwkbGeometryType::Type) -> OGRwkbGeometryType::Type {
unsafe { gdal_sys::OGR_GT_SetZ(ty) }
}
Expand All @@ -461,11 +462,15 @@ pub fn geometry_type_set_m(ty: OGRwkbGeometryType::Type) -> OGRwkbGeometryType::
}

/// Returns a XY, XYZ, XYM or XYZM geometry type depending on parameter.
pub fn geometry_type_set_modifier(ty: OGRwkbGeometryType::Type, set_z: bool, set_m: bool) -> OGRwkbGeometryType::Type {
pub fn geometry_type_set_modifier(
ty: OGRwkbGeometryType::Type,
set_z: bool,
set_m: bool,
) -> OGRwkbGeometryType::Type {
unsafe { gdal_sys::OGR_GT_SetModifier(ty, set_z as i32, set_m as i32) }
}

/// Returns `true` if the geometry type is a 3D geometry type.
/// Returns `true` if the geometry type is a 3D geometry type.
pub fn geometry_type_has_z(ty: OGRwkbGeometryType::Type) -> bool {
unsafe { gdal_sys::OGR_GT_HasZ(ty) != 0 }
}
Expand Down Expand Up @@ -614,9 +619,13 @@ mod tests {
point.set_point_zm(0, (4.0, 2.0, 1.0, 1.0));
geom.add_geometry(point).unwrap();
assert!(!geom.is_empty());
let expected = Geometry::from_wkt("MULTIPOINT ZM ((1.0 2.0 3.0 0.0), (4.0 2.0 1.0 1.0))").unwrap();
let expected =
Geometry::from_wkt("MULTIPOINT ZM ((1.0 2.0 3.0 0.0), (4.0 2.0 1.0 1.0))").unwrap();
assert_eq!(geom, expected);
assert_eq!(geometry_type_has_m(geom.geometry_type()), geometry_type_has_m(expected.geometry_type()))
assert_eq!(
geometry_type_has_m(geom.geometry_type()),
geometry_type_has_m(expected.geometry_type())
)
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub use feature::{
};
pub use gdal_sys::{OGRFieldType, OGRwkbGeometryType};
pub use geometry::{
geometry_type_to_name, geometry_type_flatten, geometry_type_set_z, geometry_type_set_m,
geometry_type_set_modifier, geometry_type_has_z, geometry_type_has_m, Geometry
geometry_type_flatten, geometry_type_has_m, geometry_type_has_z, geometry_type_set_m,
geometry_type_set_modifier, geometry_type_set_z, geometry_type_to_name, Geometry,
};
pub use layer::{FieldDefn, Layer, LayerAccess, LayerCaps, LayerIterator, OwnedLayer};
pub use options::LayerOptions;
Expand Down
7 changes: 4 additions & 3 deletions src/vector/ops/conversions/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Geometry {
let wkb_size = unsafe { gdal_sys::OGR_G_WkbSize(self.c_geometry()) as usize };
// We default to little-endian for now. A WKB string explicitly indicates the byte
// order, so this is not a problem for interoperability.
//
//
// Consider using `Vec::MaybeUninit` in future.
let byte_order = gdal_sys::OGRwkbByteOrder::wkbNDR;
let mut wkb = vec![0; wkb_size];
Expand All @@ -145,8 +145,9 @@ impl Geometry {
// Consider using `Vec::MaybeUninit` in future.
let byte_order = gdal_sys::OGRwkbByteOrder::wkbNDR;
let mut wkb = vec![0; wkb_size];
let rv =
unsafe { gdal_sys::OGR_G_ExportToIsoWkb(self.c_geometry(), byte_order, wkb.as_mut_ptr()) };
let rv = unsafe {
gdal_sys::OGR_G_ExportToIsoWkb(self.c_geometry(), byte_order, wkb.as_mut_ptr())
};
if rv != gdal_sys::OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
Expand Down
3 changes: 2 additions & 1 deletion src/vector/ops/conversions/gdal_to_geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl TryFrom<&Geometry> for geo_types::Geometry<f64> {
OGRwkbGeometryType::wkbLineString => {
let mut gdal_coords: Vec<(f64, f64, f64)> = Vec::new();
geo.get_point_vec(&mut gdal_coords);
let coords = gdal_coords.into_iter()
let coords = gdal_coords
.into_iter()
.map(|(x, y, _)| geo_types::Coord { x, y })
.collect();
Ok(geo_types::Geometry::LineString(geo_types::LineString(
Expand Down

0 comments on commit 2d28cc8

Please sign in to comment.