How to Download OpenStreetMap (OSM) Data in QGIS

Geospatial or GIS data is one of main components in working with any related GIS tasks. Sometimes it could be somewhat problematic when working in a project where the data is not available especially for base dataset like street, building, height, etc.  Fortunately, we are living in a connected and a collaborated world where any body could contribute in a geospatial project to provide, edit and share GIS data to the world for free which is usually called open data.

OpenStreetMap (OSM) is a successful example of an open data project which is driven by mapper community around the world to maintain data about road, building, public transport, railway and much more. Operated by OpenStreetMap Foundation on behalf of the community with million users, OSM data is free to use for any purpose as long as the credit is given to OpenStreetMap and its contributors.

How to get or download OpenStreetMap (OSM) data? There are many ways to download OSM data such as directly exporting from OSM website, using command line tool like curl or wget, using third party mirror server namely Planet OSM, Geofabrik, etc. In this tutorial we will learn how to download OSM data using QGIS.

OSM Data Downloader QGIS Plugin

To download OSM data in QGIS can be done using plugin. If you open Plugins installation windows like figure 1 and search for OSM, you will find two plugins: OSMDownloader and QuickOSM, that can be used to search, find and download OSM data. If you don't have the plugin in your QGIS installation, push Install button to install it. What is the difference between those two plugins? You'll find the answer in next section of this tutorial. 
OSM Plugin Installation
Figure 1. OSM Plugin Installation

Download OSM Data with OSMDownloader Plugin

Firstly, let's try to download OSM data using OSMDownloader Plugin. Open QGIS, and add the OSM basemap to the map canvas. You can add a basemap easily using Tile+ plugin. Zoom in to your interested area, for example in figure 2, I zoomed into University of British Columbia in Vancouver, Canada.
OSMDownloader  Zoom in Area
Figure 2. Zoom into interested downloaded area

Select OSMDownloader's icon. Then select area where the data will be downloaded in a rectangle shape.  The OSMDownloader window will appear as in figure 3. From the window can be seen the extent coordinate of the downloaded area. In the Save Location option, specify where to store the data and check the Load layer after download option if you want to add the data to the QGIS map canvas.

OSMDownloader extent area
Figure 3. OSMDownloader extent area
 
When it done, the downloaded data will be added to the QGIS map canvas as in figure 4. The downloaded data is saved into vector data in an osm file extension which is a XML file.
Downloaded OSM data
Figure 4. Downloaded OSM data

Download OSM Data with QuickOSM Plugin

Now let's download the OSM data using the QuickOSM plugin. After selecting the plugin's icon, the QuickOSM plugin window will appear as in figure 5. In the window you'll see two main parts. The left one is the plugin main menu and the other side is the options related to the selected menu. The first one is Quick query menu, consists of several options/parameters namely: Key, Value and location extent(In, Around, Canvas extent, Layer Extent and Not Spatial) . What are they? Key is used to describe a topic, category, or type of feature. Meanwhile Value provides detail for the key-specified feature. If you want to download a feature with a specific key and value then define both key and value. On the other hand, if you want to download a feature with a key and with any values, then select a key and leave the value to be empty/blank. Find out more about the key and values at OSM Wiki Map Features.

The key for Highway has values motorway, trunk, primary, secondary, tertiary, unclassified and many more. By using the Key and Value, it allows us to choose specific feature to be downloaded. For example we want  to download only the residential road in University of Columbia. Therefore the Key=highway and Value=residential or in direct relationship Key=Value(highway=residential). Then in the location extent select In and type University of British Columbia, Vancouver. The In and Around location extent works based on OSM geocoding service (Find out more about geocoding in QGIS). For that make sure the location name or address return the correct result. Otherwise use other location extents like Canvas Extent or Layer Extent.
QuickOSM Window Plugin
Figure 5. QuickOSM Window Plugin

If you scroll down to the bottom, you'll find Advanced option. Here we can select what elements to be downloaded (Node, Way or Relation) and also feature/geometry type (Points, Lines, Multilinestrings, Multipolygons). In this case I would like to download way element with only Lines and Multilinestrings. Therefore I checked those three and unchecked the others as seen in figure 6. Another important option is Directory. It defines the location of downloaded data. If this option leave empty, the downloaded data will be stored in a temporary file and will be gone if QGIS is closed. So if you want to keep the downloaded data, specify a folder where the data will be stored in a GeoJSON file.
QuickOSM Advanced Option
Figure 6. QuickOSM Advanced Option

Next we can proceed to show the query or run it with the respective Show query and Run query button. Figure 7 shows the query for the OSM requested data and figure 8 shows the downloaded data in red lines.
OSM Query
Figure 7. OSM Query

Residential road downloaded data (red lines)
Figure 8. Residential road downloaded data (red lines)

OpenStreetMap Query/Overpass API

In the previous example, we had downloaded residential road in University of Columbia extent. What if we want to download OSM data with a key but more than one values or multiple keys with multiple values? Let's say we want download residential and pedestrian road. In the Quick query menu, It won't be possible to do that, because we can only select a single value and a single key from the drop down list. What is the solution? The solution is using Query.

The OSM query is in XML structure as shown in figure 4. We can write or edit a query in the Query menu. I suggest to use the Quick query first to get a template of a query and then modify it as our intention. The XML syntax below is the modification of the query in figure 4. I added new query in line 9-12 to download highway with pedestrian value. The result of this modified query can be seen in the figure 9.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<osm-script output="xml" timeout="25">
    <id-query {{geocodeArea:University of British Columbia, Vancouver}} into="area_0"/>
    <union>
        <query type="way">
            <has-kv k="highway" v="residential"/>
            <area-query from="area_0"/>
        </query>

       <query type="way">
            <has-kv k="highway" v="pedestrian"/>
            <area-query from="area_0"/>
        </query>

    </union>
    <union>
        <item/>
        <recurse type="down"/>
    </union>
    <print mode="body"/>
</osm-script>

OSM Query Result
Figure 9. OSM Query result

Overpass API/Query is an advanced topic and it is out scope of this tutorial. If you want to explore more about it please visit Overpass API Language Guide

OSMDownloader VS QuickOSM

By reading the tutorial from the beginning I'm sure you can spot the difference between those two plugins. But before ending this tutorial, let me summarize the difference between OSMDownloader and QuickOSM plugin.
  • OSMDownloader plugin is a simple plugin to download OSM data in a specified rectangle extent. The output is an osm file extension which store all OSM elements and geometry features.
  • On the other hand, QuickOSM plugin is more advanced OSM data downloader which enable user to download specific features based on key and value tags in various area extents. The output is a geojson file. Moreover it also provide Query tools that enable user to write more complex overpass API/Query.  
That's all the tutorial how to download OpenStreetMap data in QGIS using OSMDownloader plugin and QuickOSM Plugin. Hopefully this tutorial is useful for you and please free to share with others if you think it will give benefit for them. Thanks for reading!

Related Posts

Disqus Comments