3

I am trying to create a railway router using pgRouting with OSM data.

My aim is to do it on the planet scale but I've been having some issues so I am trying to solve these issues on a smaller data set first.

I've downloaded the data from overpass-turbo with this query:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“railway=rail”
*/
[out:xml][timeout:25];
// gather results
(
  way["railway"="rail"]({{bbox}});
  <;
  >;
);
// print results
out body;

Then I import the data into postGIS using osm2pgrouting, which runs without errors.

osm2pgrouting --dbname pgr_routing --file test-rail.osm --username pgr_routing --tags --attributes --clean -p 5438 --password hunter2 --conf mapconfig.xml

And my mapconfig.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <tag_name name="railway" id="1">
    <tag_value name="rail" id="100"/>
    <tag_value name="subway" id="101"/>
    <tag_value name="light_rail" id="102"/>
    <tag_value name="tram" id="103"/>
    <tag_value name="narrow_gauge" id="104"/>
    <tag_value name="monorail" id="105"/>
  </tag_name>
</configuration>

However, in postGIS, there are many missing segments. My best guess is that my mapconfig.xml file is wrong but I'm not sure.

Here's an example of missing segments from pgAdmin interface: enter image description here

This is how it looks like on overpass-turbo interface: enter image description here

What am I doing wrong?

1 Answer 1

3
+50

That config file looks fine to me.

I'd say this is simply an export issue: i.e. overpass-turbo does not keep references between nodes and ways recursively by default - you'd need to explicitly tell it to like so:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“railway=*”
*/
[out:xml][timeout:25];
// gather results
(
  // query part for: “railway=*”
  way["railway"]({{bbox}});
  <;    // recusive up
  >;    // recusive down
);
// print results
out body;
>;
out skel qt;

I suggest to try on a small, verified OSM extract (from e.g. GeoFabrik) instead.


However:

Make sure you understand (and are prepared for) that osm2pgrouting

  1. expects the uncompressed XML format to work on - there's precise numbers on the OSM Wiki somewhere I believe, but expect europe-latest.osm.pbf alone (25GB) to decompress into ~700GB of OSM XML data
  2. needs to parse at least all nodes into memory (unfortunately a necessary step when working with OSM data) - and will rather ungracefully error out printing Killed when running OOM (the 277MB centro-latest.osm.pbf - 6.2GB decompresed OSM XML - does not fit into 16GB of RAM)

Two things you could do:

  • use an OSM tool of your choice (I prefer osmium) to remove all end every bit of irrelevant nodes|ways|relations and unused meta data/tags from the export prior to running any means of import
  • use a different tool and import pipeline - I am using a custom rewrite of a very fast and dead simple little tool called osm4routing2, and while I cannot open source mine, I would always use that tool over any other out there; it creates an edge and nodes file based topology, and you'd simply COPY both CSVs into PostgreSQL. However, you'd need to change the hard-coded tag extraction for this to work on railways.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.