OSMtoRoadGraph aims to provide a simple tool to allow extraction of the road network of OpenStreetMap files. It differentiates between three transportation networks: car, bicycle, and walking. The output data depends on the chosen parameters (which street highway types to consider, speed, ...).
OpenStreetMap provides free cartographic data to anyone. Data can be added and edited by anyone. However, using the road network contained in the OSM files is not straightforward. This tool aims to reduce the overhead of writing a parser for OSM files.
With this tool the data is being converted into easily parsable plaintext files that can be used by any application for further processing. For each transportation network type two output files are generated. One file contains the nodes (with coordinates), and the network edges, with length, direction and maximum speed (according to chosen network type). The second file contains street names that could be extracted for all edges contained in the first file.
- Python 3.6+/PyPy
- An OSM XML file
Recently, breaking changes have been applied. If you require older versions please see the releases.
Usage: run.py [options]
Options:
-h, --help show this help message and exit
-f FILENAME, --file=FILENAME
-n NETWORK_TYPE, --networkType=NETWORK_TYPE (p)edestrian, (b)icycle, (c)ar, [default: pedestrian]
-l, --nolcc
-c, --contract
-f
points to the input filename; the output files will be created in the same folder and using the name of the input file as prefix and adding information as suffix.
-n
sets the network type. This influences the maximum speed saved for the edges. If you care only about connectivity set it to pedestrian.
-l
if you set this option the graph will be output as a whole but may contain unconnected components. By default the largest connected component is determined and the rest is dropped.
-c
if you specify this option additional to the original graph, a second pair of filenames will be created containing the result of contracting all degree 2 nodes.
python run.py -f data/karlsruhe_small.osm -n p -v
The output will consist of two plaintext files. One file ending in .pypgr
, pybgr
, or pycgr
depending on the network type selected; the other file will have the same ending with a _names
as additional suffix. The first file contains the graph structure as well as additional information about the edge (length, max speed according to highway type, if it is a one-way street or not). The file ending with _names
includes the street names for the edges.
The structure of the road network output file is the following:
<HEADER LINES STARTING WITH A DASH(#) CHARACTER>
<number of nodes>
<number of edges>
<id> <lat> <lon>
...
<s> <t> <length> <street_type> <max_speed> <bidirectional>
...
bidirectional
value is 0
if it is a unidirectional road (from s
to t
), and otherwise it is 1
.
# Road Graph File v.0.4
# number of nodes
# number of edges
# node_properties
# ...
# edge_properties
# ...
4108
4688
0 49.0163448 8.4019855
1 49.0157261 8.405539
2 49.0160334 8.4050578
...
531 519 93.87198088764158 service 10 0
524 528 71.98129087573543 service 10 1
528 532 22.134814663337743 service 10 1
532 530 12.012991347084839 service 10 1
530 531 12.76035560927566 service 10 1
531 529 14.981628728184265 service 10 1
529 501 77.18577344768484 service 10 1
501 502 10.882105497189313 service 10 1
75 405 14.312976598760008 residential 30 1
405 206 44.642284586584886 residential 30 1
...
Hölderlinstraße
Hölderlinstraße
Hölderlinstraße
Kronenstraße
Kronenstraße
Kronenstraße
Zähringerstraße
Zähringerstraße
Each line consists of a street name. The number in which a line is corresponds to the edges index. In this example this means, that Hölderlinstraße is the street name of edges 0, 1, 2. The absence of a name in line 4 indicates that edge 3 has no street name. Edges 4, 5, 6 have street name Kronenstraße, and so on...
The application comes with a set of standard configuration to parse only
some OSM ways that have the tag highway=x
where x
is a highway type [notable excepting is the pedestrian_indoors
, see below for an explanation].
You can change the behavior of this program by changing the values (removing unwanted, and adding missing values) in the configuration.py
.
In this file you can also modify the speed limit that will be written to the output file.
By default elements tagged by the Simple Indoor Tagging approach are being ignored.
To enable to also to extract these paths replace in configuration.py
the line
accepted_highways['pedestrian'] = set(["primary", "secondary", "tertiary", "unclassified", "residential", "service", "primary_link", "secondary_link", "tertiary_link", "living_street", "pedestrian", "track", "road", "footway", "steps", "path"])
with
accepted_highways['pedestrian'] = set(["primary", "secondary", "tertiary", "unclassified", "residential", "service", "primary_link", "secondary_link", "tertiary_link", "living_street", "pedestrian", "track", "road", "footway", "steps", "path", "pedestrian_indoor"])
Note that the change is only the addition of pedestrian_indoor
in this list.
Temporal Map Labeling: A New Unified Framework with Experiments