Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions editoast/osm_to_railjson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Example for Germany:

1. Download OSM's German data (~4Gb `germany-latest.osm.pbf`) from
https://download.geofabrik.de/europe/germany.html

This is not mandatory, but we strongly recommend using [osmium](https://osmcode.org/osmium-tool/) to filter the osm.pbf file with only the data needed by osm_to_railjson.
```sh
osmium tags-filter <path/to/germany-latest.osm.pbf> nwr/railway nwr/train -o <path/to/germany-latest.osm.pbf>
```
It can divide by 3 the time taken by osm_to_railjson.
2. Launch conversion (release build of editoast and conversion can be long):
```sh
cd ../../editoast
Expand Down
8 changes: 7 additions & 1 deletion editoast/osm_to_railjson/src/osm_to_railjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub fn parse_osm(
.reject("gauge", "600")
.reject("roller_coaster", "*")
.reject("construction", "*")
.reject("usage", "science")
.reject("usage", "tourism")
.read_tag("maxspeed")
.read_tag("maxspeed:forward")
.read_tag("maxspeed:backward")
Expand All @@ -69,7 +71,11 @@ pub fn parse_osm(
}

let nodes_tracks = NodeToTrack::from_edges(&edges);
let signals = signals(&osm_pbf_in, &nodes_tracks, &adjacencies);
let signals = if generate_signals {
vec![]
} else {
signals(&osm_pbf_in, &nodes_tracks, &adjacencies)
};
let mut railjson = RailJson {
extended_switch_types: vec![],
detectors: signals.iter().map(detector).collect(),
Expand Down
19 changes: 10 additions & 9 deletions editoast/osm_to_railjson/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,17 @@ pub fn electrifications(edge: &Edge) -> Option<Electrification> {
})
}

fn map_node_id_to_node(
fn map_node_id_to_trigram(
pbf: &mut OsmPbfReader<std::fs::File>,
) -> HashMap<osm4routing::osmpbfreader::NodeId, osm4routing::osmpbfreader::Node> {
) -> HashMap<osm4routing::osmpbfreader::NodeId, String> {
pbf.iter()
.flatten()
.filter_map(|obj| match obj {
osm4routing::osmpbfreader::OsmObj::Node(node) => Some((node.id, node)),
osm4routing::osmpbfreader::OsmObj::Node(node) => node
.tags
.get("railway:ref")
.filter(|trigram| trigram.len() <= 3)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.dbinfrago.com/web/schienennetz/betrieb/allgemeine-betriebsinformationen/betriebsstellen-12592996

In Germany they can have up to 5 characters (and in France 1 or 2...).
If this filter is needed, I would say to filter at 5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this filter because editoast give me and error when I have a trigram longer then 3 characters. I don't know where but I think there is a 3 characters limitation somewhere else in the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it seems the search_operational_point table has a trigram field of type varying(3) but it's most likely a bug in editoast

  2026-04-13T08:23:43.542183Z ERROR editoast::error: [editoast:ModelError] an error occurred while querying the database: value too long for type character varying(3): disabled backtrace

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Openned #16212 but i don't know how this will play out with the OP model refacto

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #16215 to fix editoast

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ! but ths problem still remains, sometimes there is a number where the trigram should be.
Would filtering by alphabetic character to the job ?
Is there trigram with number in them ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm if it doesn't break editoast too much i'd say let invalid OSM data resurface to the users so that they (and us) can see what needs to be fixed in OSM more easily? but probably someone else has another opinion

.map(|tag| (node.id, tag.to_string())),
_ => None,
})
.collect()
Expand All @@ -467,7 +471,7 @@ pub fn operational_points(
) -> Vec<OperationalPoint> {
let file = std::fs::File::open(osm_pbf_in).unwrap();
let mut pbf: OsmPbfReader<std::fs::File> = osm4routing::osmpbfreader::OsmPbfReader::new(file);
let node_id_to_node = map_node_id_to_node(&mut pbf);
let node_id_to_trigram = map_node_id_to_trigram(&mut pbf);
pbf.rewind().expect("Could not rewind file.");
pbf.iter()
.flatten()
Expand Down Expand Up @@ -504,11 +508,8 @@ pub fn operational_points(
_ => None,
})
.find_map(|node_id| {
node_id_to_node.get(&node_id).and_then(|node| {
node.tags
.get("railway:ref")
.map(ToString::to_string)
})
node_id_to_trigram.get(&node_id)
.cloned()
})
.unwrap_or_default();
// Parts can be empty when the stop_area references stops that are not railway (e.g. bus station)
Expand Down
Loading