Networks/Import/OpenStreetMap

"OpenStreetMap is a free editable map of the whole world. It is made by people like you." (from http://www.openstreetmap.org). This page discusses the conversion of files with data from OpenStreetMap to a SUMO network file.

There are several ways how to download the data from OpenStreetMap to a file. Please read the page Networks/Import/OpenStreetMapDownload to learn about these ways. For more information about the file format visit the page OpenStreetMap file.

=Importing the Road Network=

NETCONVERT can import OSM-files natively. The according option is named or  for short.

The following call to NETCONVERT imports the road network stored in "berlin.osm.xml" and stores the SUMO-network generated from this data into "berlin.net.xml":

netconvert --osm-files berlin.osm.xml -o berlin.net.xml

OSM-data has always WGS84 geo coordinates which will be automatically UTM transformed by netconvert (since sumo 0.11.1). Thus you need explicit projection parameters only if you need a different projection. Refer to the NETCONVERT documentation for other conversion options.

=Importing additional Polygons (Buidlings, Water, etc.)= OSM-data not only contains the road network but also a wide range of additional polygons such as buildings and rivers. These polygons can be imported using POLYCONVERT and then added to a -configuration.

To interpret the OSM-data an additional typemap-file is required:

                <polygonType id="landuse.industrial" name="industrial" color=".82,.82,.80" layer="-11"/> <polygonType id="man_made" name="building" color="1.0,.90,.90" layer="2"/> <polygonType id="building" name="building" color="1.0,.90,.90" layer="2"/> <polygonType id="amenity" name="amenity" color=".93,.78,.78" layer="2"/> <polygonType id="amenity.parking" name="parking" color=".72,.72,.70" layer="-2"/> <polygonType id="military" name="military" color=".60,.60,.36" layer="-10"/> <polygonType id="landuse.military" name="military" color=".60,.60,.36" layer="-10"/> <polygonType id="landuse.farm" name="farm" color=".95,.95,.8" layer="-11"/> <polygonType id="landuse.greenfield" name="farm" color=".95,.95,.8" layer="-11"/> <polygonType id="landuse.village_green" name="farm" color=".95,.95,.8" layer="-11"/> <polygonType id="power" name="power" color=".1,.1,.3" layer="5"/> <polygonType id="natural.land" name="land" color=".98,.87,.46" layer="-9"/> <polygonType id="boundary.administrative" name="boundary.administrative" color=".5,.0,.2" layer="-12" fill="false"/> <polygonType id="aeroway" name="aeroway" color=".5,.5,.5" layer="1"/> <polygonType id="aerialway" name="aerialway" color=".2,.2,.2" layer="1"/> <polygonType id="historic" name="historic" color=".5,1,.5" layer="2"/> </polygonTypes>

Using the typemap file typemap.xml the following call to POLYCONVERT imports polygons from OSM-data and produces a Sumo-polygon file. polyconvert --net-file berlin.net.xml --osm-files berlin.osm --type-file typemap.xml -o berlin.poly.xml

The created polygon file berlin.poly.xml can then be added to a  configuration:

<net-file value="berlin.net.xml"/> <additional-files value="berlin.poly.xml"/>

=Import Scripts= The help script osmGet.py allows downloading a large area. The resulting file called "<PREFIX>.osm.xml" can then be imported using the script osmBuild.Py. Both scripts are located in /tools/import/osm.

The call is: osmGet.py --bbox <BOUNDING_BOX> --prefix <NAME> osmBuild.py --osm-file <NAME>.osm.xml [--vehicle-classes (all|road|passenger)] [--type-file <TYEPMAP_FILE>] [--netconvert-options <OPT1,OPT2,OPT3>] [--polyconvert-options <OPT1,OPT2,OPT3>]

If "road" is given as parameter, only roads usable by road vehicles are extracted, if "passenger" is given, only those accessible by passenger vehicles.

When using the option an additional output file with polygons of rivers and buildings as well as Points of Interest (POIs) will be generated. This can be loaded in SUMO-GUI for additional visualization. An example type-file file can be found at /tools/import/osm/typemap_example.xml.

Additional options for NETCONVERT and POLYCONVERT can be supplied using the options and

Note that the scripts also support a secondary syntax for loading even large areas by splitting them into multiple tiles and download requests. In this case the calls look like this: osmGet.py --bbox <BOUNDING_BOX> --prefix <NAME> --oldapi --tiles <INT> osmBuild.py --oldapi-prefix <NAME --tiles <INT> [--vehicle-classes (all|road|passenger),ramps,tls] [--type-file <TYEPMAP_FILE>] The number of tiles given in both calls must match.

=Further Notes=

Junctions
In OpenStreetMap roads forming a single street and separated by, for example, a lawn or tram line, are represented by two edges that are parallel to each other. When crossing with another street, they form two junctions instead of one. To merge such junctions into a single junction, one can define which nodes to merge. See Networks/Building Networks from own XML-descriptions and NETCONVERT documentation for usage details.

Joining traffic lights
OSM does not have the possibility to assign several nodes to a single traffic light. This means that near-by nodes, normally controlled by one traffic light system are controlled by two after the network is imported. It is obvious that traffic collapses in such areas if both traffic lights are not synchronized. Better representation of the reality can be achieved by giving the option to NETCONVERT. NETCONVERT then assigns near-by nodes to the same traffic light.

Overriding the traffic light information
If the traffic light information embedded in the OSM file does not fit your needs, you can strip it with option in NETCONVERT and then provide your own definition in a separate *.nod.xml file in a second run of NETCONVERT: netconvert --osm-files berlin.osm.xml --output-file berlin-without-tls.net.xml \ --osm.discard-tls netconvert --sumo-net-file berlin-without-tls.net.xml --node-files tls-controlled-nodes.nod.xml \ --output-file berlin-with-tls.net.xml
 * 1) 1. Import the OSM file to SUMO, discarding TLS information.
 * 1) 2. Set traffic light information.

where tls-controlled-nodes.nod.xml overwrites the type of node to "traffic_light". If the node already exists (which is usually the case) you don't have to provide any information other than the node's ID and new node type.

Highway On- and Off-Ramps
OSM networks often lack additional lanes for highway on- and off-ramps. They can be guessed via NETCONVERT using the option.

JOSM
From George Dita, on 01.07.2009 JOSM can be used to edit OSM-data (i.e. for trimming a rectangular map and deleting unwated features). After you delete the part that does not interest you have to alter the file using xmlstarlet which actually deletes the nodes.

xmlstarlet can be used like this:

xmlstarlet ed -d "/osm/*[@action='delete']" < input.osm > output.osm

OSMOSIS
From Christian Klotz, on 01.07.2009, tip by Christoph Sommmer

The java tool osmosis (http://wiki.openstreetmap.org/index.php/Osmosis) can be used to filter out unwanted features from an OSM-file. The following command keeps motorways and motorway links while filtering out everything else:

java -jar osmosis.jar --read-xml file="orginal.osm.xml" --way-key-value \ keyValueList="highway.motorway,highway.motorway_link" \ --used-node --write-xml file="filtered.osm.xml"

=NETCONVERT Details=

Road Types
When importing road networks, NETCONVERT searches for the street type, encoded in OSM as a key/value-pair where the key is either "highway" or "railway". Only if such a key occures in the edge definition, the edge is imported (see also below). The edge's type name is built from the found key/value pair by building a name as: <KEY>.<VALUE>. Using this type name, the edge's attributes are determined using a predefined map of type names to type definitions. It is possible to override the default types with own type definitions. This is documented in the article about the SUMO edge type file.

The following table lists the internal default values.

Explicite Road Attributes
In the case an edge contains the definition about the number of lanes (key="lanes") or the allowed speed (key="maxspeed"), this information is used instead of the according type's value. Also, the per-edge information whether the edge is a one-way edge is read (key="oneway"). In the case the edge belongs to a roundabout (key="junction" and value="roundabout"), it is also set as being a one-way edge.

Dismissing unwanted traffic modes
In most cases, tracks and edges which not may be crossed by motorised traffic are not interesting for road traffic research. It is possible to exclude these edges from being imported using the NETCONVERT-option.

For removing all edges which can not be used by passenger vehicles the call must be extended by: --remove-edges.by-vclass hov,taxi,bus,delivery,transport,lightrail,cityrail, \ rail_slow,rail_fast,motorcycle,bicycle,pedestrian

For removing all edges which can not be used by road vehicles the call must be extended by: --remove-edges.by-vclass rail_slow,rail_fast,bicycle,pedestrian

Relationship between OSM ids and SUMO-ids
For the most part, the relationship between OSM and .net.xml is simple:
 * OSM node id "1234" translates into junction id "1234".
 * OSM way id "5677" translatess into multiple edge ids "5678#0", "5678#1", "5678#2", "-5678#0", "-5678#1", "-5678#2"

OSM ways are mostly bi-directional and cross multiple intersections. In .net.xml they are split at each intersection with a running index #n and the edges with prefix '-' are those in the opposite direction.

However, some OSM elements may not appear in the created network because they are joined with other elements or converted to (unnamed) geometry points along an edge.

=Missing Descriptions=
 * TLS computation
 * computation of lane-2-lane connections
 * what is exactly imported (how edge attributes are determined)
 * other traffic modes
 * Network quality

=References=
 * http://www.openstreetmap.org/ - the home site
 * http://www.openstreetmap.de/ - the German home site
 * http://wiki.openstreetmap.org/index.php/Map_Features - information about database attributes