Extracting Road Networks From OpenStreetMap
OpenStreetMap is a very good crowdsourcing map application. It has a cool feature which tag the road in the map by its type. That feature enable us to identify the type of road such as main road, pedestrian road, living street, etc. Besides that, we can also use that feature to extract only the road part from the map. This can be useful when we want to build a routing system which need the road part only.
For extracting the road networks from OpenStreetMap, we need an application called Osmosis. It is a Java application so we can run it at any operating system such as Linux, Windows, or Mac OS. But we need to install Java Runtime Environment (JRE) first.
For installing the Osmosis, please read the articles from the following links. They have a very clear step by step instructions.
- For Linux: http://wiki.openstreetmap.org/wiki/Osmosis/Installation#Linux
- For Windows: http://wiki.openstreetmap.org/wiki/Osmosis/Quick_Install_(Windows)
- For Mac OS: http://wiki.openstreetmap.org/wiki/Osmosis/Installation#OS_X
Before we use Osmosis, we have to prepare the map area which we will extract its road networks. Go to the OpenStreetMap website then made some search in it. After that click the green Export button then click the blue Export button as shown in the following picture. Then save the exported file to the desired directory. The file itself will have .osm extension.
When we have the map data and Osmosis application installed, we can start to extract the road networks.
- Open command prompt or your console program.
- Go to the directory where you save your .osm file.
- Type the following command to extract all road networks.
osmosis --read-xml map.osm --tf accept-ways highway=* --used-node --write-xml highways.osm
- If you want to extract the trunk road only, use the following command.
osmosis --read-xml map.osm --tf accept-ways highway=trunk --used-node --write-xml highways.osm
- You can also extract multiple types of road by separating them using comma. The following command will extract the trunk, motorway, and pedestrian networks.
osmosis --read-xml map.osm --tf accept-ways highway=trunk,motorway,pedestrian --used-node --write-xml highways.osm
- The complete list about the available options for road's type can be read from http://wiki.openstreetmap.org/wiki/Key:highway.
We have successfully extracted the road networks. Now, how to visualized it? There is another application we need for that purpose. Its name is Java OpenStreetMap Editor or JOSM Editor. It is also a Java program so it can be run in Linux, Windows, or Mac OS if we have JRE installed. Please download the JOSM Editor from https://josm.openstreetmap.de/josm-tested.jar.
To run JOSM Editor, we can double click the .jar file or use the following command.
java -jar josm-tested.jar
After the JOSM Editor started, open the .osm file, which is the result of road networks extraction, by clicking File - Open. The picture below is the example of road networks extraction around the Monumen Nasional in Jakarta.