From dd9d1d47c0286ebab97df03b40e8f8e2869ccc4e Mon Sep 17 00:00:00 2001 From: rfitzger Date: Thu, 14 Dec 2023 16:56:11 -0700 Subject: [PATCH] create tree multipoint --- .../output/default/traversal/traversal_ops.rs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/rust/routee-compass/src/plugin/output/default/traversal/traversal_ops.rs b/rust/routee-compass/src/plugin/output/default/traversal/traversal_ops.rs index dc77f9ae..1289bdcb 100644 --- a/rust/routee-compass/src/plugin/output/default/traversal/traversal_ops.rs +++ b/rust/routee-compass/src/plugin/output/default/traversal/traversal_ops.rs @@ -1,5 +1,6 @@ use crate::plugin::plugin_error::PluginError; -use geo::{LineString, MultiLineString}; +use geo::{LineString, MultiLineString, Point}; +use geo_types::MultiPoint; use geojson::feature::Id; use geojson::{Feature, FeatureCollection}; use routee_compass_core::algorithm::search::edge_traversal::EdgeTraversal; @@ -142,3 +143,36 @@ pub fn create_tree_multilinestring( let geometry = MultiLineString::new(tree_linestrings); Ok(geometry) } + +pub fn create_tree_multipoint( + tree: &HashMap, + geoms: &[LineString], +) -> Result { + let edge_ids = tree + .values() + .map(|traversal| traversal.edge_traversal.edge_id) + .collect::>(); + + let tree_destinations = edge_ids + .iter() + .map(|eid| { + let geom = geoms + .get(eid.0) + .ok_or(PluginError::EdgeGeometryMissing(*eid)) + .map(|l| { + l.points().last().ok_or(PluginError::InputError(format!( + "linestring is invalid for edge_id {}", + eid + ))) + }); + match geom { + // rough "result flatten" + Ok(Ok(p)) => Ok(p), + Ok(Err(e)) => Err(e), + Err(e) => Err(e), + } + }) + .collect::, PluginError>>()?; + let geometry = MultiPoint::new(tree_destinations); + Ok(geometry) +}