Tutorial 1: Adding OpenStreetMap data to QGIS

Site: IHE DELFT OPEN COURSEWARE
Course: FAO CB4WA: Introduction to Spatial Data Infrastructures
Book: Tutorial 1: Adding OpenStreetMap data to QGIS
Printed by: Guest user
Date: Monday, 5 December 2022, 5:48 AM

1. Introduction

Learning objectives

OpenStreetMap (OSM) is a collaborative project to create a free editable map of the world. OSM is considered a prominent example of volunteered geographic information (VGI) or crowdsourcing. There are several ways to use the data:

  • Through the interactive map on the OpenStreetMap website (http://www.openstreetmap.org)
  • In QGIS you can add OSM basemaps via the QuickMapServices plugin
  • In QGIS you can download OSM data directly over the Internet. There are several ways to do this. In this section we’ll use the QuickOSM plugin which uses the Overpass API.

In this tutorial we are going to download OSM vector data for the area of your interest.

Software

QGIS has many different versions and the updates go fast.
In this course we use QGIS 3.16 LTR. LTR means Long Term Release, which means that it is stable and bugs are fixed over a longer time than other versions. There are newer versions, which are great to test new features. However, these versions also might have new bugs and are therefore not recommended for operational use or courses.

Watch this video how to download and install QGIS. It also gives an overview of the interface.
You can download QGIS for free from http://www.qgis.org




2. Locating the study area

First we need to locate the study area. We can use a world map, the GeoCoding plugin and online maps. In this section we'll try all.

1. Start QGIS Desktop.

2. In the coordinate field at the bottom of the window type world and press Enter.


Now you'll see a world map.

3. Zoom in to the country of your interest using  from the toolbar.

To find the location of your study area more precisely you can use the GeoCoding plugin.

4.  In the main menu go to: Plugins | Manage and Install Plugins.


5. Search for GeoCoding.


6. Click Install Plugin,

7. Click Close to close the dialogue. 

8. In the toolbar look for the GeoCoding plugin icon  and click it.

9. Type the address of the place that you're looking for. Addresses can be even street names and house numbers. Then click OK.


Sometimes you will get another window when it found multiple results.


Then choose the one you think resembles your search and click OK.

The GeoCoding plugin will add a point at that location.

To get more context it is useful to add online layers using the QuickMapServices plugin.

10. Install the QuickMapServices plugin through the main menu: Plugins | Manage and Install Plugins.


11. After installing the QuickMapServices plugin choose in the main menu: Web | QuickMapServices | Settings.

12. Choose the tab More services and click Get contributed pack. Then click Save.


13. Now you can choose for example OpenStreetMap or Google Satellite as background map,

  • OpenStreetMap: Web | QuickMapServices | OSM | OSM Standard
  • Google Satellite: Web | QuickMapServices | Google | Google Satellite

Note that these online layers are rendered pictures and not data that we can use in analysis. 

14. Uncheck the World Map layer so you can see the online layer and zoom in further to your study area.

3. Downloading OpenStreetMap data

If you have loaded OSM Standard from the QuickMapServices plugin, all the features that you see on the map can be downloaded with the QuickOSM plugin. We're going to install useful features for our study area.

1. Install the QuickOSM plugin through the main menu: Plugins | Manage and Install Plugins . Search for QuickOSM.

2. Open the QuickOSM dialogue by choosing Vector | QuickOSM | QuickOSM from the main menu.



We’re first going to download the rivers. The OSM data attributes consist of keys and values. To learn more about it, click here.

3. Choose waterway as Key, river as Value. Choose the Canvas extent as the extent. Note that you can also select the extent of of a layer. Scroll down and click the arrow before Advanced and make sure only NodeWayRelation, and Lines are checked (you need to select the geometry that you would like to download). The dialogue should now look like figure the figure below. Click Run Query.



You can increase the Timeout value if you have a slow Internet connection.

The new layer will be added as a temporary scratch layer as indicated by the Temporary Scratch Layer icon in the indicator space to the right of the layer in the Layers Panel.  If you hover over the icon it will warn you that you will lose the layer when you close the project. You need to save it first! We'll do that later after we have downloaded all layers that we need.


4. Make layer permanent

In the previous chapter you've learned that the downloaded layer is a temporary scratch layer.

We can make the layer permanent in the following way:

1. Click the chip icon  next to the waterway_river layer.

2. In the Save Scratch Layer dialogue choose from the dropdown menu ESRI Shapefile as output format. Use the  button to browse to the folder where you want to store the layer and give it a name. Click OK to save the layer.


Now your layer is stored.

Alternatively you could have exported the file. Then you can control the output projection. You can do this by clicking right and choose Export | Save Features As...

It's important to regularly save your project to avoid data loss when your computer crashes.

3. In the main menu choose Project | Save As...

4. Save the project to the same folder as your file. You can give it any name with the QGZ file extension.

Once in a while click  to save the project.

5. Style rivers

Let's style the river

1. Select the waterway_river layer from the Layers panel and click  to open the Layer Styling panel. 

2. Select Simple line. Click the Color bar to open the Select line color panel.

3. Change the Color to an RGB value of 31|120|180.


4. Click the Go back  button to return to the main symbology panel.

5. Increase the Stroke width to 0.86 mm.


6. To label the rivers switch to the Labels tab  in the Layer Styling panel.

7. Label Rivers with just the Name field: choose Single labels and for value choose name.


8. Switch to the Label placement  tab and choose a Placement style of Curved.

To make them more readable against the topo map you will apply a buffer.

9. Switch to the Label buffer tab  and check Draw text buffer option.

You will set the color to the background of the OpenStreetMap.

10. Click the drop down arrow for the Color setting and choose Pick color. With the eye dropper cursor click on a place to select that gray OpenStreetMap background color.

11. Finally return to the Text  and set the label Color to an RGB value of 31|38|180, the Font to Calibri, the Size to 11 and the Style to italic.




Styles are stored in the project. If we want to share the styles, we can also store them in a separate file.

12. Click right on waterway_river in the Layers panel.

13. Choose Properties... from the menu.

14. In the Layer Properties dialogue go to the Symbology tab:


15. At the bottom, click the Style button and choose Save Style...


16. Save the layer in the SLD format, which is an open standard for sharing styles. Use the browse button to save it in the same folder as the shapefile and click OK.


17. Close the Layer Properties dialogue.

6. Add more data from OpenStreetMap

Now we can add more features from OpenStreetMap in a similar way.

Here we'll add mines, but feel free to add other relevant features for your study area.

1. Let’s add the mines in a similar way as we have added the rivers. Use key=landuse and value=quarry. Don’t forget to select Multipolygons instead of Lines.

2. Style the polygons with a gray fill and black stroke using an italic font.

3. Label the polygons with the Name attribute. Switch to the label Formatting tab  and enter a space as the Wrap on character. Then set the Alignment to Center. Switch to the label Rendering tab and click Only draw labels which fit completely within feature.

4. Now add a few other interesting features (points, lines, and polygons):

  • Dams: Key=waterwayvalue=dam
  • Lakes: Key=natural,value=water
  • Springs: Key=naturalvalue=spring
5. Make the layers permanent so they are stored as shapefiles on your hard disk.

7. Style lakes, dams and springs

Now style the layers. Begin with the lakes. 

You will use a shapeburst fill which will allow you to color the lakes from light blue to dark blue.

1. Set the target layer in the Layer Styling Panel to natural_water.

2. Select the Simple fill styling component. Change the Symbol layer type to Shapeburst fill. Keep the default Gradient colors setting of Two color. Set the first color to an RGB value of 185|239|255. Set the second color to an RGB value of 31|133|180.

3. Set the Shading style to Set distance with a value of 6. Increase the Blur strength to 12.

Finally you will add a simple line to represent the coastline of each lake.

4. Click the Add symbol layer  button. Change the new Simple fill renderer to a Symbol layer type of Outline simple line with Color of 31|133|180.

5. Label the lakes with the the name. Set the label Color and RGB value of 225|255|255 (light blue), the Font to Calibri, the Size to 10 and the Style to bold italic.

6. Switch to the Label placement tab and change the Placement to Horizontal (slow). Then switch to the label Formatting tab and enter a space as the Wrap on character. Set the Alignment to Center.

7. Switch to the label Rendering tab and click Only draw labels which fit completely within feature.



Next you will work with the dam lines (waterway_dam). 

8. Give them a Color of black and a Stroke width of 0.86 mm.

9. Click the Add symbol layer button. Select the Simple line component and choose a Symbol layer type of Marker line. Select the Simple marker component and choose the vertical line symbol from the choices displayed below. Increase the Stroke width to 0.2 mm and the Size to 3 mm. Your dams symbol preview should now look like this .



10. Finally you will style the spring points. Make the layer the target layer in the Layer Styling Panel. Select the Simple fill component. Choose a Symbol layer type of SVG Marker. Select the symbol folder and find the blue-marker.svg  . Increase the Size (Width and Height) to 6 mm each.


11. Save the styles in an SLD file as you've learned before.

8. Conclusion

In this tutorial you have learned to:

  1. Download OpenStreetMap data for your study area
  2. Make layers permanent
  3. Style vector data
  4. Save styles in SLD files

You can watch the following videos to learn more about the procedures:

Adding hydrological data from OpenStreetMap to QGIS with the QuickOSM plugin


Adding cities and towns from OpenStreetMap to QGIS


Adding Open Data to your QGIS 3 project