-
Notifications
You must be signed in to change notification settings - Fork 30
/
mod.rs
43 lines (37 loc) · 1.21 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! geo-types conversions.
pub(crate) mod geo_types_reader;
pub(crate) mod geo_types_writer;
pub use geo_types_reader::*;
pub use geo_types_writer::*;
pub(crate) mod conversion {
use super::geo_types_writer::*;
use crate::error::{GeozeroError, Result};
use crate::GeozeroGeometry;
/// Convert to geo-types Geometry.
pub trait ToGeo {
/// Convert to geo-types Geometry.
fn to_geo(&self) -> Result<geo_types::Geometry<f64>>;
}
impl<T: GeozeroGeometry> ToGeo for T {
fn to_geo(&self) -> Result<geo_types::Geometry<f64>> {
let mut geo = GeoWriter::new();
self.process_geom(&mut geo)?;
geo.geom
.ok_or(GeozeroError::Geometry("Missing Geometry".to_string()))
}
}
}
#[cfg(feature = "with-wkb")]
mod wkb {
use super::geo_types_writer::*;
use crate::error::Result;
use crate::wkb::{FromWkb, WkbDialect};
use std::io::Read;
impl FromWkb for geo_types::Geometry<f64> {
fn from_wkb<R: Read>(rdr: &mut R, dialect: WkbDialect) -> Result<Self> {
let mut geo = GeoWriter::new();
crate::wkb::process_wkb_type_geom(rdr, &mut geo, dialect)?;
Ok(geo.geom)
}
}
}