Skip to content

Commit 863b5db

Browse files
committed
osm_to_railjson: add filter for trigram map
Stop mapping every node, and map only those that have a "railway:ref" tag, and filter out those whose trigram is longer than 3 characters. Signed-off-by: Simon <sim.gaubert.sg@gmail.com>
1 parent 3bba060 commit 863b5db

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

editoast/osm_to_railjson/src/utils.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,17 @@ pub fn electrifications(edge: &Edge) -> Option<Electrification> {
449449
})
450450
}
451451

452-
fn map_node_id_to_node(
452+
fn map_node_id_to_trigram(
453453
pbf: &mut OsmPbfReader<std::fs::File>,
454-
) -> HashMap<osm4routing::osmpbfreader::NodeId, osm4routing::osmpbfreader::Node> {
454+
) -> HashMap<osm4routing::osmpbfreader::NodeId, String> {
455455
pbf.iter()
456456
.flatten()
457457
.filter_map(|obj| match obj {
458-
osm4routing::osmpbfreader::OsmObj::Node(node) => Some((node.id, node)),
458+
osm4routing::osmpbfreader::OsmObj::Node(node) => node
459+
.tags
460+
.get("railway:ref")
461+
.filter(|trigram| trigram.len() <= 3)
462+
.map(|tag| (node.id, tag.to_string())),
459463
_ => None,
460464
})
461465
.collect()
@@ -467,7 +471,7 @@ pub fn operational_points(
467471
) -> Vec<OperationalPoint> {
468472
let file = std::fs::File::open(osm_pbf_in).unwrap();
469473
let mut pbf: OsmPbfReader<std::fs::File> = osm4routing::osmpbfreader::OsmPbfReader::new(file);
470-
let node_id_to_node = map_node_id_to_node(&mut pbf);
474+
let node_id_to_trigram = map_node_id_to_trigram(&mut pbf);
471475
pbf.rewind().expect("Could not rewind file.");
472476
pbf.iter()
473477
.flatten()
@@ -504,11 +508,8 @@ pub fn operational_points(
504508
_ => None,
505509
})
506510
.find_map(|node_id| {
507-
node_id_to_node.get(&node_id).and_then(|node| {
508-
node.tags
509-
.get("railway:ref")
510-
.map(ToString::to_string)
511-
})
511+
node_id_to_trigram.get(&node_id)
512+
.cloned()
512513
})
513514
.unwrap_or_default();
514515
// Parts can be empty when the stop_area references stops that are not railway (e.g. bus station)

0 commit comments

Comments
 (0)