Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 23, 2018
1 parent f99f180 commit 4e7532a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ use {Coordinate, CoordinateType, Line, Point};
/// }
/// ```
///
// TODO: don't expose this within the module
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LineString<T>(pub Vec<Coordinate<T>>)
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/from_postgis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ impl<'a, T> FromPostgis<&'a T> for Point<f64> where T: postgis::Point {
}
impl<'a, T> FromPostgis<&'a T> for LineString<f64> where T: postgis::LineString<'a> {
fn from_postgis(ls: &'a T) -> Self {
let ret = ls.points()
let ret: Vec<Point<f64>> = ls.points()
.map(|x| Point::from_postgis(x))
.collect();
LineString(ret)
LineString::from(ret)
}
}
impl<'a, T> FromPostgis<&'a T> for Option<Polygon<f64>> where T: postgis::Polygon<'a> {
Expand Down
14 changes: 10 additions & 4 deletions geo/src/algorithm/to_postgis.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ::{MultiPoint, Line, Point, LineString, MultiLineString, MultiPolygon, Polygon, Geometry, GeometryCollection};
use ::{Coordinate, MultiPoint, Line, Point, LineString, MultiLineString, MultiPolygon, Polygon, Geometry, GeometryCollection};
use postgis::ewkb;

/// Converts geometry to a PostGIS type.
Expand All @@ -16,6 +16,12 @@ pub trait ToPostgis<T> {
}
}

impl ToPostgis<ewkb::Point> for Coordinate<f64> {
fn to_postgis_with_srid(&self, srid: Option<i32>) -> ewkb::Point {
ewkb::Point::new(self.x, self.y, srid)
}
}

impl ToPostgis<ewkb::Point> for Point<f64> {
fn to_postgis_with_srid(&self, srid: Option<i32>) -> ewkb::Point {
ewkb::Point::new(self.x(), self.y(), srid)
Expand All @@ -24,8 +30,8 @@ impl ToPostgis<ewkb::Point> for Point<f64> {
impl ToPostgis<ewkb::LineString> for Line<f64> {
fn to_postgis_with_srid(&self, srid: Option<i32>) -> ewkb::LineString {
let points = vec![
self.start.to_postgis_with_srid(srid),
self.end.to_postgis_with_srid(srid)
self.start_point().to_postgis_with_srid(srid),
self.end_point().to_postgis_with_srid(srid)
];
ewkb::LineString { points, srid }
}
Expand All @@ -34,7 +40,7 @@ impl ToPostgis<ewkb::Polygon> for Polygon<f64> {
fn to_postgis_with_srid(&self, srid: Option<i32>) -> ewkb::Polygon {
let rings = ::std::iter::once(&self.exterior)
.chain(self.interiors.iter())
.map(|x| x.to_postgis_with_srid(srid))
.map(|x| (*x).to_postgis_with_srid(srid))
.collect();
ewkb::Polygon { rings, srid }
}
Expand Down

0 comments on commit 4e7532a

Please sign in to comment.