From 5722c67011a9e73f4a585604bdaa2c3d651d72e1 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 1 Aug 2022 14:43:20 +0100 Subject: [PATCH] Add methods to get geojson from a point --- geom/src/gps.rs | 4 ++++ geom/src/pt.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/geom/src/gps.rs b/geom/src/gps.rs index 272ecbfc0b..93b915fda3 100644 --- a/geom/src/gps.rs +++ b/geom/src/gps.rs @@ -181,6 +181,10 @@ impl LonLat { } Ok(polygons) } + + pub fn to_geojson(self) -> geojson::Geometry { + geojson::Geometry::new(geojson::Value::Point(vec![self.x(), self.y()])) + } } impl fmt::Display for LonLat { diff --git a/geom/src/pt.rs b/geom/src/pt.rs index 9cb311597c..056c328045 100644 --- a/geom/src/pt.rs +++ b/geom/src/pt.rs @@ -142,6 +142,14 @@ impl Pt2D { .map(|pt| pt.into()) .collect() } + + pub fn to_geojson(self, gps: Option<&GPSBounds>) -> geojson::Geometry { + if let Some(gps) = gps { + self.to_gps(gps).to_geojson() + } else { + geojson::Geometry::new(geojson::Value::Point(vec![self.x(), self.y()])) + } + } } impl fmt::Display for Pt2D {