From 3c0844d561512784153baad10f5134f2c375930f Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 12 Dec 2023 14:34:13 +0900 Subject: [PATCH] Use osm-reader callbacks --- backend/Cargo.lock | 2 +- backend/src/scrape.rs | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 70aa8f8..4307516 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -464,7 +464,7 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "osm-reader" version = "0.1.0" -source = "git+https://github.com/a-b-street/osm-reader#40f27e3d08b2c4a9258ed67b38a036c98c3eb18a" +source = "git+https://github.com/a-b-street/osm-reader#d6db3cd499eb238150ce2ed06aa7e88ce2447e13" dependencies = [ "anyhow", "osmpbf", diff --git a/backend/src/scrape.rs b/backend/src/scrape.rs index d4f721c..f5baf18 100644 --- a/backend/src/scrape.rs +++ b/backend/src/scrape.rs @@ -17,24 +17,22 @@ struct Way { pub fn scrape_osm(input_bytes: &[u8]) -> Result { 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);