Working with Open Street Map vector data in QGIS
When we teach data journalism most people are eager to make a map but they’re usually unsure of where to get data for a map. And while there are many good sources for map data, if you’re looking for something, like a particular town or neighbourhood, that’s not always so easy. One solution is to […]
When we teach data journalism most people are eager to make a map but they’re usually unsure of where to get data for a map. And while there are many good sources for map data, if you’re looking for something, like a particular town or neighbourhood, that’s not always so easy.
One solution is to use QGIS and Open Street Map to create your own map data.
We recently did this for a project looking at the spread of cholera near Pretoria in South Africa.
There are lots of maps of South Africa available but most are at a national or provincial level and don’t really show the details of an area. For our purposes, we wanted a map with more detail and which showed the location of major settlements north of Pretoria.
An excellent source of free highly-detailed map data is the Open Street Map (OSM) project but exporting data can be tricky and confusing. An easier way to download OSM data is to use QGIS with a couple of plugins:
Install the QuickOSM plugin
Open QGIS and select the “Plugins” menu item and then “Manage and Install Plugins”.
On the screen that appears click the “Not Installed” option and search for “QuickOSM”. Click on that and then on “Install Plugin”.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q1-1024x583.png)
Install the QuickMapServices plugin
While you’re in the plugins menu search for the “QuickMapServices” plugin and install that as well.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q2-1024x585.png)
Add a basemap
There are various ways to get OSM data into QGIS but the easiest is to add a map to the main editing window and then select the area you want data for.
Click Project → New in the main menu to start a new project. Then select Web in the menu followed by QuickMapServices → OSM → OSM Standard. This will add the standard OSM map to the main editing window.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q3-1024x445.png)
Find your area of interest
Zoom in on the area you’re interested in. To start with zoom in pretty close. The level of detail in OSM is impressive but can also lock up your computer if you try to get too much information at once. Try with a suburb you’re familiar with at first to get a feel for the information available.
Here we zoomed in on an area between Pretoria and Hammanskraal.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q4-1024x751.png)
Select the data you want
Once you’ve framed the area you’re interested in in the main editing window, you can get the vector data.
Click on Vector in the main menu and then on QuickOSM→QuickOSM.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q5-1024x573.png)
This will bring up the QuickOSM interface. Depending on the version of QGIS and QuickOSM you have the interface may look slightly different.
The main things you need to look out for are the key, value and are values.
OSM labels all features with a top-level “‘key” value like highway (for all road features) or “waterway” for water features. You need to select a key in all cases.
There is a secondary level called “values” which lists sub-features, for example residential roads or paths. You don’t need to select “values” if you want all features in a specific key.
Then there is the area you want. You either need to provide a specific area using coordinates or, in this case, just supply the map area we already framed.
Here we select “highway” as the key and “residential” as the value, for all the residential roads in the given area.
For the area, we select “canvas extent” which is the are we have already framed in the main editing window:
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q8-1024x560.png)
With these selected, we can run the query. Depending on how much detail you have selected this can take a while to complete. When it is ready you can close the QuickOSM window. You should have something like this. The brown areas in the map are the vector details from OSM. You can tick and untick the layers in the left-hand panel to switch between layers.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q7-1024x790.png)
Untick the OSM Standard layer to show just the OSM data.
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q9-1024x746.png)
Tip: Change the vector colours
QGIS automatically chooses a colour for the lines in layers. Sometimes this makes it difficult to distinguish between items. For example, if I add a layer for rivers, it would help if they were blue. Once you’ve added a layer with the rivers (using the QuickOSM technique above) you can right-click on the layer with the rivers and change the colour in the styles menu:
![](https://editor.mediahack.co.za/databites/wp-content/uploads/sites/3/2023/08/q11-1024x879.png)
Exporting the data
When you’re done you probably want to export the map data, as a shapefile or as GeoJSON.
You can export the individual layers of your map by right-clicking on a layer and selecting Export→Save Features As and then saving as GeoJSON or ESRI Shapefile (the most likely options).
Export multiple layers
I you created multiple layers that you now want to export as one file you’ll need to merge the layers.
To do this, select Processing→Toolbox in the main menu. In the toolbox that appears to the right, search for “merge” and then select “Merge Vector Layers”. You’ll need to select the layers you want to merge and run.
This will create a new layer in your layers panel. You can export this like any other layer by right-clicking on it and selecting “Export→Save Features”.