Networks/Import/OpenStreetMap

generated on 2015-03-31 10:30:54.984202 from the wiki page for Networks/Import/OpenStreetMap for SUMO 0.23.0

"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.

Note:
Several aspects of the imported network may have to be modified to suit your needs. Some of the relevant NETCONVERT options are described below. For more flexible alterations see Tutorials/ScenarioGuide#Modifying_the_Network.
}

Importing additional Polygons (Buildings, 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="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"/>
    
        <polygonType id="power" name="power" color=".10,.10,.30" layer="-1" discard="true"/>                         
        <polygonType id="highway" name="highway" color=".10,.10,.10" layer="-1" discard="true"/>                                       
        <polygonType id="boundary" name="boundary" color="1.0,.33,.33" layer="0" fill="false" discard="true"/>                            
        <polygonType id="admin_level" name="admin_level" color="1.0,.33,.33" layer="0" fill="false" discard="true"/>  
 </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.

Recommended NETCONVERT Options

These options are used by default in the script osmBuild.py:

 --geometry.remove,--remove-edges.isolated,--roundabouts.guess,--ramps.guess,--junctions.join,--osm.railway.oneway-default,--tls.guess-signals,--tls.discard-simple,--tls.join

The rationale for these options is explained below.

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.

The NETCONVERT option --junctions.join applies a heuristic to join these junction clusters automatically and is used by default when using the osmBuild.py script described above. However, some junction clusters are too complex for the heuristic and should be checked manually (as indicated by the warning messages). Also, sometimes the heuristic wrongly joins some junctions. These can be excluded by giving them as a list to the option --junctions.join-exclude <ID>[,<ID>]*.

When leaving junctions unjoined, there is a high risk of getting low throughput, jams and even deadlocks due to the short intermediate edges and the difficulty in computing proper traffic light plans for the junction clusters.

Traffic Lights

Interpreting traffic light information in OSM

NETCONVERT prefers each intersection to be represented by a single node with a single traffic light controller. To achieve the former, see #Junctions. To achieve the latter some extra options are recommended. OSM often uses nodes ahead of an intersection to represent the position of traffic light signals. The actual intersection itself is then not marked as controlled. To interpret these structures the option --tls.guess-signals and --tls.guess-signals.dist <FLOAT> may be used. To cover the cases where this heuristic fails, the options below may be used to computed a joint tls plan for multiple nodes.

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.

Roundabouts

To ensure correct right-of-way at roundabouts, the option --roundabouts.guess should be added. This option is set automatically when using the osmBuild.py script.

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_IGNORING) x
highway.motorway_link 3 80 km/h 12 all (SVC_IGNORING) x
highway.trunk 2 100 km/h 11 all (SVC_IGNORING)
highway.trunk_link 1 80 km/h 10 all (SVC_IGNORING)
highway.primary 2 100 km/h 9 all (SVC_IGNORING)
highway.primary_link 1 80 km/h 8 all (SVC_IGNORING)
highway.secondary 2 100 km/h 7 all (SVC_IGNORING)
highway.secondary_link 1 80 km/h 6 all (SVC_IGNORING)
highway.tertiary 1 80 km/h 6 all (SVC_IGNORING)
highway.tertiary_link 1 80 km/h 5 all (SVC_IGNORING)
highway.unclassified 1 80 km/h 5 all (SVC_IGNORING)
highway.residential 1 50 km/h 4 all (SVC_IGNORING)
highway.living_street 1 10 km/h 3 all (SVC_IGNORING)
highway.service 1 20 km/h 2 SVC_DELIVERY
highway.track 1 20 km/h 1 all (SVC_IGNORING)
highway.services 1 20 km/h 1 all (SVC_IGNORING)
highway.unsurfaced 1 30 km/h 1 all (SVC_IGNORING)
highway.pedestrian 1 30 km/h 1 SVC_PEDESTRIAN
highway.path 1 10 km/h 1 SVC_PEDESTRIAN
highway.footway 1 30 km/h 1 SVC_PEDESTRIAN
highway.pedestrian 1 30 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 300 km/h 1 SVC_RAIL
railway.tram 1 100 km/h 1 SVC_TRAM
railway.light_rail 1 100 km/h 1 SVC_RAIL_URBAN
railway.subway 1 100 km/h 1 SVC_RAIL_URBAN
railway.preserved 1 100 km/h 1 SVC_RAIL

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

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.

Warnings during Import

Several types of warnings and errors with different levels of severity may be issued during OSM import.

Message Explanation Recommended Action
Warning: Discarding unusable type "...." (first occurence for edge "....") Unknown edge types are ignored during import. Ignore or provide an Edge-type file which contains that type.
Warning: Ignoring restriction relation ... Some data is missing within the OSM file. Ignore, because this relation most likely falls outside the boundaries of the road network.
Warning: Direction of restriction relation could not be determined Some data is missing within the OSM file. Ignore, because this relation most likely falls outside the boundaries of the road network.

Additional warnings are described here.

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 27 March 2015, at 09:05.