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 2.7+/Python 3.6+/PyPy
- future package
- to install run
pip install -r requirements.txt
- to install run
- An OSM XML file
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 compoonents. 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> <forward> <backward>
...
# Road Graph File v.0.3
# 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
...
1529 3222 102.344801043 residential 30 True False
3222 1629 7.19105938956 residential 30 True False
1629 1526 8.828179648 residential 30 True False
2306 2319 37.3600477398 track 5 True True
...
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...
Temporal Map Labeling: A New Unified Framework with Experiments