-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf73645
commit a613a30
Showing
13 changed files
with
121 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,65 @@ | ||
use std::io::Cursor; | ||
|
||
use arrow_array::OffsetSizeTrait; | ||
use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; | ||
use num_enum::{IntoPrimitive, TryFromPrimitive}; | ||
|
||
use crate::error::{GeoArrowError, Result}; | ||
use crate::scalar::WKB; | ||
|
||
/// The various WKB types supported by this crate | ||
#[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)] | ||
#[repr(u32)] | ||
pub enum WKBType { | ||
/// A WKB Point | ||
Point = 1, | ||
/// A WKB LineString | ||
LineString = 2, | ||
/// A WKB Polygon | ||
Polygon = 3, | ||
/// A WKB MultiPoint | ||
MultiPoint = 4, | ||
/// A WKB MultiLineString | ||
MultiLineString = 5, | ||
/// A WKB MultiPolygon | ||
MultiPolygon = 6, | ||
/// A WKB GeometryCollection | ||
GeometryCollection = 7, | ||
/// A WKB PointZ | ||
PointZ = 1001, | ||
/// A WKB LineStringZ | ||
LineStringZ = 1002, | ||
/// A WKB PolygonZ | ||
PolygonZ = 1003, | ||
/// A WKB MultiPointZ | ||
MultiPointZ = 1004, | ||
/// A WKB MultiLineStringZ | ||
MultiLineStringZ = 1005, | ||
/// A WKB MultiPolygonZ | ||
MultiPolygonZ = 1006, | ||
/// A WKB GeometryCollectionZ | ||
GeometryCollectionZ = 1007, | ||
} | ||
|
||
impl WKBType { | ||
/// Construct from a byte slice representing a WKB geometry | ||
pub fn from_buffer(buf: &[u8]) -> Result<Self> { | ||
let mut reader = Cursor::new(buf); | ||
let byte_order = reader.read_u8().unwrap(); | ||
let geometry_type = match byte_order { | ||
0 => reader.read_u32::<BigEndian>().unwrap(), | ||
1 => reader.read_u32::<LittleEndian>().unwrap(), | ||
_ => panic!("Unexpected byte order."), | ||
}; | ||
Self::try_from_primitive(geometry_type) | ||
.map_err(|err| GeoArrowError::General(err.to_string())) | ||
} | ||
} | ||
|
||
impl<'a, O: OffsetSizeTrait> TryFrom<WKB<'a, O>> for WKBType { | ||
type Error = GeoArrowError; | ||
|
||
fn try_from(value: WKB<'a, O>) -> std::result::Result<Self, Self::Error> { | ||
Self::from_buffer(value.as_ref()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.