{"id":115,"date":"2023-08-03T20:46:19","date_gmt":"2023-08-03T20:46:19","guid":{"rendered":"https:\/\/editor.mediahack.co.za\/databites\/?p=115"},"modified":"2025-11-17T17:41:36","modified_gmt":"2025-11-17T17:41:36","slug":"extract-open-street-map-vector-data-in-qgis","status":"publish","type":"post","link":"https:\/\/outliereditor.co.za\/index.php\/2023\/08\/03\/extract-open-street-map-vector-data-in-qgis\/","title":{"rendered":"Working with Open Street Map vector data in QGIS"},"content":{"rendered":"\n<p>When we teach data journalism most people are eager to make a map but they&#8217;re usually unsure of where to get data for a map. And while there are many good sources for map data, if you&#8217;re looking for something, like a particular town or neighbourhood, that&#8217;s not always so easy. <\/p>\n\n\n\n<p>One solution is to use QGIS and Open Street Map to create your own map data.<\/p>\n\n\n\n<p>We recently did this for a project looking at the spread of cholera near Pretoria in South Africa.<\/p>\n\n\n\n<p>There are lots of maps of South Africa available but most are at a national or provincial level and don&#8217;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. <\/p>\n\n\n\n<p>An excellent source of free highly-detailed map data is the <a href=\"https:\/\/www.openstreetmap.org\/#map=6\/-28.676\/24.677\" target=\"_blank\" rel=\"noreferrer noopener\">Open Street Map<\/a> (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: <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Install the QuickOSM plugin<\/h1>\n\n\n\n<p>Open QGIS and select the \u201cPlugins\u201d menu item and then \u201cManage and Install Plugins\u201d.<\/p>\n\n\n\n<p>On the screen that appears click the \u201cNot Installed\u201d option and search for \u201cQuickOSM\u201d. Click on that and then on \u201cInstall Plugin\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q1-1024x583.png\" alt=\"\" class=\"wp-image-116\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Install the QuickMapServices plugin<\/h2>\n\n\n\n<p>While you&#8217;re in the plugins menu search for the &#8220;QuickMapServices&#8221; plugin and install that as well. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q2-1024x585.png\" alt=\"\" class=\"wp-image-117\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Add a basemap<\/h2>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>Click <strong>Project \u2192 New<\/strong> in the main menu to start a new project. Then select <strong>Web<\/strong> in the menu followed by <strong>QuickMapServices \u2192 OSM \u2192 OSM Standard<\/strong>. This will add the standard OSM map to the main editing window.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q3-1024x445.png\" alt=\"\" class=\"wp-image-118\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Find your area of interest<\/h2>\n\n\n\n<p>Zoom in on the area you&#8217;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&#8217;re familiar with at first to get a feel for the information available. <\/p>\n\n\n\n<p>Here we zoomed in on an area between Pretoria and Hammanskraal. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q4-1024x751.png\" alt=\"\" class=\"wp-image-119\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Select the data you want<\/h2>\n\n\n\n<p>Once you&#8217;ve framed the area you&#8217;re interested in in the main editing window, you can get the vector data. <\/p>\n\n\n\n<p>Click on <strong>Vector<\/strong> in the main menu and then on <strong>QuickOSM\u2192QuickOSM<\/strong>. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q5-1024x573.png\" alt=\"\" class=\"wp-image-120\"\/><\/figure>\n\n\n\n<p>This will bring up the QuickOSM interface. Depending on the version of QGIS and QuickOSM you have the interface may look slightly different. <\/p>\n\n\n\n<p>The main things you need to look out for are the key, value and are values. <\/p>\n\n\n\n<p>OSM labels all features with a top-level &#8220;&#8216;key&#8221; value like highway (for all road features) or &#8220;waterway&#8221; for water features. You need to select a key in all cases. <\/p>\n\n\n\n<p>There is a secondary level called &#8220;values&#8221; which lists sub-features, for example residential roads or paths. You don&#8217;t need to select &#8220;values&#8221; if you want all features in a specific key. <\/p>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>Here we select &#8220;highway&#8221; as the key and &#8220;residential&#8221; as the value, for all the residential roads in the given area. <\/p>\n\n\n\n<p>For the area, we select &#8220;canvas extent&#8221; which is the are we have already framed in the main editing window: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q8-1024x560.png\" alt=\"\" class=\"wp-image-122\"\/><\/figure>\n\n\n\n<p>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. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q7-1024x790.png\" alt=\"\" class=\"wp-image-123\"\/><\/figure>\n\n\n\n<p>Untick the OSM Standard layer to show just the OSM data. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q9-1024x746.png\" alt=\"\" class=\"wp-image-124\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Tip: Change the vector colours<\/h2>\n\n\n\n<p>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&#8217;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: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/08\/q11-1024x879.png\" alt=\"\" class=\"wp-image-126\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Exporting the data<\/h2>\n\n\n\n<p>When you&#8217;re done you probably want to export the map data, as a shapefile or as GeoJSON. <\/p>\n\n\n\n<p>You can export the individual layers of your map by right-clicking on a layer and selecting Export\u2192Save Features As and then saving as GeoJSON or ESRI Shapefile (the most likely options).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Export multiple layers<\/h2>\n\n\n\n<p>I you created multiple layers that you now want to export as one file you&#8217;ll need to merge the layers. <\/p>\n\n\n\n<p>To do this, select <strong>Processing\u2192Toolbox<\/strong> in the main menu. In the toolbox that appears to the right, search for \u201cmerge\u201d and then select &#8220;Merge Vector Layers\u201d. You\u2019ll need to select the layers you want to merge and run. <\/p>\n\n\n\n<p>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 \u201cExport\u2192Save Features\u201d.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we teach data journalism most people are eager to make a map but they&#8217;re usually unsure of where to get data for a map. And while there are many good sources for map data, if you&#8217;re looking for something, like a particular town or neighbourhood, that&#8217;s not always so easy. One solution is to use QGIS and Open Street Map to create your own map data.<\/p>\n","protected":false},"author":1,"featured_media":86690,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[447,448,1387],"tags":[449,451,452],"newsletter-post":[],"site":[],"class_list":["post-115","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databites","category-how-to","category-the-outlier","tag-how-to","tag-maps","tag-qgis"],"acf":{"big_number":"","big_number_caption":"","big_number_link":"","big_number_background":"","big_number_text_colour":"#000000","big_number_icon":false,"big_number_wide":"yes","featured_chart":false,"flourish_chart_id":"","flourish_sub_title":"","flourish_chart_width":"medium","is_newsletter_post":"No","post_style":"bc","show_on_front":"Yes","link_through":"Yes","chart_url":"","background_colour":"#0089AA","text_colour":"#FFFFFF"},"_links":{"self":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":2,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":89508,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/115\/revisions\/89508"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/media\/86690"}],"wp:attachment":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=115"},{"taxonomy":"newsletter-post","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/newsletter-post?post=115"},{"taxonomy":"site","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/site?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}