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.

Contents

Importing the Road Network

NETCONVERT can import OSM-files natively. The according option is named --osm-files <FILE>[,<FILE>]* or --osm <FILE>[,<FILE>]* 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 sumo-gui-configuration.

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

 <polygonTypes>
 	<polygonType id="waterway" name="water" color=".71,.82,.82" layer="-10"/>
 	<polygonType id="natural.water" name="water" color=".71,.82,.82" layer="-10"/>
 	<polygonType id="natural.wetland" name="water" color=".71,.82,.82" layer="-10"/>
 	<polygonType id="sport" name="sport" color=".31,.90,.49" layer="2"/>
 	<polygonType id="landuse.forest" name="forest" color="0.55,.77,.42" layer="-11"/>
 	<polygonType id="natural.wood" name="forest" color="0.55,.77,.42" layer="-11"/>
 	<polygonType id="natural" name="natural" color="0.55,.77,.42" layer="2"/>
 	<polygonType id="landuse.park" name="park" color=".81,.96,.79" layer="-11"/>
 	<polygonType id="leisure" name="leisure" color=".81,.96,.79" layer="0"/>
 	<polygonType id="leisure.park" name="tourism" color=".81,.96,.79" layer="-10"/>
 	<polygonType id="tourism" name="tourism" color=".81,.96,.79" layer="2"/>
 	<polygonType id="landuse" name="landuse" color=".76,.76,.51" layer="-4"/>
 	<polygonType id="landuse.residential" name="residential" color=".92,.92,.89" layer="-11"/>
 	<polygonType id="landuse.commercial" name="commercial" color=".82,.82,.80" layer="-11"/>
 	<polygonType id="shop" name="shop" color=".93,.78,1.0" layer="2"/>
 	<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 sumo-gui configuration:

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

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 <SUMO_HOME>/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 --type-file 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 <SUMO_HOME>/tools/import/osm/typemap_example.xml.

Additional options for NETCONVERT and POLYCONVERT can be supplied using the options --netconvert-options and -polyconvert-options

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#Joining Nodes and NETCONVERT documentation for usage details.

Traffic Lights

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 --try-join-tls 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 --osm.discard-tls option in NETCONVERT and then provide your own definition in a separate *.nod.xml file in a second run of NETCONVERT:

# 1. Import the OSM file to SUMO, discarding TLS information.
netconvert --osm-files berlin.osm.xml --output-file berlin-without-tls.net.xml \
   --osm.discard-tls

# 2. Set traffic light information.
netconvert --sumo-net-file berlin-without-tls.net.xml --node-files tls-controlled-nodes.nod.xml \
   --output-file berlin-with-tls.net.xml

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 --guess-ramps option.

Editing OSM networks

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
Caution:
Up to version 4279 of JOSM, nodes and ways created or modified by JOSM are assigned a negative ID. With each run of JOSM, these IDs are recalculated. Please do not rely on them in your SUMO files. If you decide not to upload your changes to OpenStreetMap, you can remove the minuses in the IDs, assure that IDs are unique and then safely refer to them in SUMO files.

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.

Caution:
The values were set-up ad-hoc and are not yet verified. It would be a great help if someone would revisit and improve them. Please let us know.


Type Name #lanes speed priority allowed vehicle classes one-way is default
highway.motorway 3 160 km/h 13 all (SVC_UNKNOWN) x
highway.motorway_link 3 80 km/h 12 all (SVC_UNKNOWN) x
highway.trunk 2 100 km/h 11 all (SVC_UNKNOWN)
highway.trunk_link 1 80 km/h 10 all (SVC_UNKNOWN)
highway.primary 2 100 km/h 9 all (SVC_UNKNOWN)
highway.primary_link 1 80 km/h 8 all (SVC_UNKNOWN)
highway.secondary 2 100 km/h 7 all (SVC_UNKNOWN)
highway.tertiary 1 80 km/h 6 all (SVC_UNKNOWN)
highway.unclassified 1 80 km/h 5 all (SVC_UNKNOWN)
highway.residential 1 50 km/h 4 all (SVC_UNKNOWN)
highway.living_street 1 10 km/h 3 all (SVC_UNKNOWN)
highway.service 1 20 km/h 2 SVC_DELIVERY
highway.track 1 20 km/h 1 all (SVC_UNKNOWN)
highway.pedestrian 1 30 km/h 1 SVC_PEDESTRIAN
highway.services 1 30 km/h 1 all (SVC_UNKNOWN)
highway.unsurfaced 1 30 km/h 1 all (SVC_UNKNOWN)
highway.footway 1 30 km/h 1 SVC_PEDESTRIAN
highway.pedestrian 1 30 km/h 1 SVC_PEDESTRIAN
highway.path 1 10 km/h 1 SVC_PEDESTRIAN
highway.bridleway 1 10 km/h 1 SVC_PEDESTRIAN
highway.cycleway 1 20 km/h 1 SVC_BICYCLE
highway.footway 1 10 km/h 1 SVC_PEDESTRIAN
highway.step 1 5 km/h 1 SVC_PEDESTRIAN
highway.steps 1 5 km/h 1 SVC_PEDESTRIAN
highway.stairs 1 5 km/h 1 SVC_PEDESTRIAN
highway.bus_guideway 1 30 km/h 1 SVC_BUS
railway.rail 1 30 km/h 1 SVC_RAIL_FAST
railway.tram 1 30 km/h 1 SVC_CITYRAIL
railway.light_rail 1 30 km/h 1 SVC_LIGHTRAIL
railway.subway 1 30 km/h 1 SVC_CITYRAIL
railway.preserved 1 30 km/h 1 SVC_LIGHTRAIL
railway.monorail 1 30 km/h 1 SVC_LIGHTRAIL

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 --remove-edges.by-vclass <STRING>[,<STRING>]*.

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


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


This page was last modified on 22 March 2013, at 13:14.