Preparation of OSM data#

Section author: Xingmin Wang <xingminw@umich.edu>, Zachary Jerome <zjerome@umich.edu>

Step 1: Download OSM data#

You can use the following two methods to download the OpenStreetMap data. The second one is recommended among these two:

1. OpenStreetMapOfficial: choose Export -> OverpassAPI (otherwise the size of the bounding box size is limited).

OpenStreetMap Official

By this way, you will get the complete OSM data (xml), then you can use osm_filter.osm_way_filter() to get the layer you need.

2. Overpass API (recommended): directly use overpass API to download the layer you need. The sample query code is attached in the Appendix A: Query code.

Overpass API

In this way, you will directly get the layer you need. Finally, you need to save your raw osm data in a file name as "***.osm".

Note

OSM supports two different formats: json and xml. Our MTLDP can only deal with xml format. Please save the raw data as xml format in the osm file. If you use overpass API to download the OSM data, OSM data format is specified in this line: <osm-script output="xml" timeout="25">. You can choose either "xml" or "json".

Step 2: Edit OSM data through JOSM#

After you download the raw OSM data, you need to manually edit it according to your own applications. You are recommended to use JOSM by which you can edit the network including adding/deleting ways/nodes and editting their tags. Manual edit is important since raw OSM data can barely fullfill all your requirements since there are noises and errors in the original data. For example, there will be many ways without lane number information.

The following steps are commmonly

2.1 Make sure it is rectangular (mandatory)#

As shown in the following figure, also selected from a rectangular area, the downloaded data is not strictly within a rectangular area. You MUST make sure the map data is in a rectangular area by deleting the road segment outside it.

Rectagular area

2.2 Topology cleaning (optional)#

Junction topology check. You need to make sure each intersection only has one intersection point (especially signalized intersections). Sometimes you will see this:

Junction topology before

which is common when the intersecting roads are large enough to warrant a separate link for each direction. To merge all four of these intersections, selecting all of them using the control key and then click the ‘m’ key. If you receive an error message double check to make sure all of the tags are the same. The only tag you need for a signalized intersection is: Key: highway, Value: traffic_signals. After that you may have to move the intersection to the center and adjust some of the links to match the roadway. The intersection above now looks like this:

Junction topology after

2.3 Check and update tags#

This part is not complete yet.

The following are commonly recognized tags that you need to check and update:

Layer

Tag name

Comments

way way way node

lanes lanes:forward turn:lanes:forward stopline:forward

Total number of lanes Number of lanes of the forward direction Usage of the lanes of the forward direction (“left||“, “left||right“) Stop line of the vehicle (mobility purpose)

Please also refer to Appendix B: Recognized OSM tags for more details.

Step 3: Parse OSM data and visualization#

The downloaded OpenStreetMap xml file can be parsed using the mtldp.mtlmap.build_network_from_xml():

1import mtldp.mtlmap as mtlmap
2network = mtlmap.build_network_from_xml("*.osm")

This will return you a well-structured class mtldp.meta.TrafficNetwork.Network.

Step 4: Overwrite attributes (optional)#

Movement index correction#

Appendix A: Query code#

Here is an example of the query code using the OverpassAPI.

 1<!--
 2This has been generated by the overpass-turbo wizard.
 3The original search was:
 4“highway=* and highway!=footway and highway!=pedestrian and -highway!=path”
 5-->
 6<osm-script output="xml" timeout="25"><!-- fixed by auto repair -->
 7    <!-- gather results -->
 8    <union>
 9        <!-- query part for: “highway=* and highway!=footway and highway!=pedestrian and "-highway"!=path” -->
10        <query type="node">
11            <has-kv k="highway"/>
12            <has-kv k="highway" modv="not" v="footway"/>
13            <has-kv k="highway" modv="not" v="pedestrian"/>
14            <has-kv k="highway" modv="not" v="path"/>
15            <has-kv k="highway" modv="not" v="steps"/>
16            <has-kv k="highway" modv="not" v="service"/>
17            <has-kv k="highway" modv="not" v="stop"/>
18            <has-kv k="highway" modv="not" v="crossing"/>
19            <has-kv k="highway" modv="not" v="bus_stop"/>
20            <has-kv k="highway" modv="not" v="elevator"/>
21            <has-kv k="highway" modv="not" v="emergency_access_point"/>
22            <has-kv k="highway" modv="not" v="give_way"/>
23            <has-kv k="highway" modv="not" v="mini_roundabout"/>
24            <has-kv k="highway" modv="not" v="passing_place"/>
25            <has-kv k="highway" modv="not" v="rest_area"/>
26            <has-kv k="highway" modv="not" v="speed_camera"/>
27            <has-kv k="highway" modv="not" v="street_lamp"/>
28            <has-kv k="highway" modv="not" v="turning_circle"/>
29            <has-kv k="highway" modv="not" v="turning_loop"/>
30            <has-kv k="highway" modv="not" v="toll_gantry"/>
31
32            <bbox-query {{bbox}}/>
33        </query>
34        <query type="way">
35            <has-kv k="highway"/>
36            <has-kv k="highway" modv="not" v="footway"/>
37            <has-kv k="highway" modv="not" v="pedestrian"/>
38            <has-kv k="highway" modv="not" v="path"/>
39            <has-kv k="highway" modv="not" v="steps"/>
40            <has-kv k="highway" modv="not" v="service"/>
41
42
43            <bbox-query {{bbox}}/>
44        </query>
45        <query type="relation">
46            <has-kv k="highway"/>
47            <has-kv k="highway" modv="not" v="footway"/>
48            <has-kv k="highway" modv="not" v="pedestrian"/>
49            <has-kv k="highway" modv="not" v="path"/>
50            <has-kv k="highway" modv="not" v="steps"/>
51            <has-kv k="highway" modv="not" v="service"/>
52
53
54            <bbox-query {{bbox}}/>
55        </query>
56    </union>
57    <!-- print results -->
58    <print mode="meta"/><!-- fixed by auto repair -->
59    <recurse type="down"/>
60    <print mode="meta" order="quadtile"/><!-- fixed by auto repair -->
61</osm-script>

Appendix B: Recognized OSM tags#

B.1 Lane assignment#

To do: we need to revisit the code to check what format can be recognized