Skip to content

Commit

Permalink
Use osm-reader callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Dec 12, 2023
1 parent 7d34bc1 commit 3c0844d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 14 additions & 16 deletions backend/src/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@ struct Way {
pub fn scrape_osm(input_bytes: &[u8]) -> Result<MapModel> {
let mut node_mapping = HashMap::new();
let mut highways = Vec::new();
for elem in osm_reader::parse(input_bytes)? {
match elem {
Element::Node { id, lon, lat, .. } => {
let pt = Coord { x: lon, y: lat };
node_mapping.insert(id, pt);
}
Element::Way { id, node_ids, tags } => {
if tags.contains_key("highway") {
highways.push(Way {
id,
node_ids,
tags: tags.into(),
});
}
osm_reader::parse(input_bytes, |elem| match elem {
Element::Node { id, lon, lat, .. } => {
let pt = Coord { x: lon, y: lat };
node_mapping.insert(id, pt);
}
Element::Way { id, node_ids, tags } => {
if tags.contains_key("highway") {
highways.push(Way {
id,
node_ids,
tags: tags.into(),
});
}
Element::Relation { .. } => {}
}
}
Element::Relation { .. } => {}
})?;

let (mut roads, mut intersections) = split_edges(&node_mapping, highways);

Expand Down

0 comments on commit 3c0844d

Please sign in to comment.