Skip to content

Commit

Permalink
Plumb through a way to modify the graph before building routers
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jan 11, 2025
1 parent f33a47d commit 40bb502
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl MapModel {
let mut graph = Graph::new(
input_bytes,
&mut amenities,
Box::new(|_| Ok(())),
vec![
graph::muv_profiles::muv_car_profile(),
graph::muv_profiles::muv_bicycle_profile(),
Expand Down
6 changes: 5 additions & 1 deletion graph/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ impl Graph {
///
/// - `input_bytes`: Bytes of an osm.pbf or osm.xml file
/// - `osm_reader`: A callback for every OSM element read, to extract non-graph data
/// - `post_process_graph`: A callback to remove edges and intersections after initially
/// importing.
/// - `profiles`: A list of named profiles. Each one assigns an access direction and cost,
/// given OSM tags and a Euclidean center-line. If every profile assigns `Direction::None`,
/// then the Road is completely excluded from the graph.
pub fn new<R: utils::osm2graph::OsmReader>(
input_bytes: &[u8],
osm_reader: &mut R,
post_process_graph: Box<dyn Fn(&mut utils::osm2graph::Graph) -> Result<()>>,
profiles: Vec<(
String,
Box<dyn Fn(&Tags, &LineString) -> (Direction, Duration)>,
Expand All @@ -28,7 +31,7 @@ impl Graph {
) -> Result<Graph> {
timer.step("parse OSM and split graph");

let graph = utils::osm2graph::Graph::new(
let mut graph = utils::osm2graph::Graph::new(
input_bytes,
|tags| {
if !tags.has("highway") || tags.is("highway", "proposed") || tags.is("area", "yes")
Expand All @@ -45,6 +48,7 @@ impl Graph {
},
osm_reader,
)?;
post_process_graph(&mut graph)?;

timer.step("calculate road attributes");
// Copy all the fields
Expand Down

0 comments on commit 40bb502

Please sign in to comment.