Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create tree multipoint #82

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -142,3 +143,36 @@ pub fn create_tree_multilinestring(
let geometry = MultiLineString::new(tree_linestrings);
Ok(geometry)
}

pub fn create_tree_multipoint(
tree: &HashMap<VertexId, SearchTreeBranch>,
geoms: &[LineString<f64>],
) -> Result<MultiPoint, PluginError> {
let edge_ids = tree
.values()
.map(|traversal| traversal.edge_traversal.edge_id)
.collect::<Vec<_>>();

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::<Result<Vec<Point>, PluginError>>()?;
let geometry = MultiPoint::new(tree_destinations);
Ok(geometry)
}