{"id":33,"date":"2023-03-20T08:39:20","date_gmt":"2023-03-20T08:39:20","guid":{"rendered":"https:\/\/editor.mediahack.co.za\/databites\/?p=33"},"modified":"2025-11-17T17:42:02","modified_gmt":"2025-11-17T17:42:02","slug":"33","status":"publish","type":"post","link":"https:\/\/outliereditor.co.za\/index.php\/2023\/03\/20\/33\/","title":{"rendered":"Creating a grid overlay for a map using QGIS"},"content":{"rendered":"\n<p>There are a number of reasons you may want to make a grid of points covering a geographic area. In my case, I wanted to work out which point in South Africa was the furthest from a police station. The idea was to create a grid with points 1km apart. Then I could compare the distance between each point and the surrounding police stations. There are probably better ways to do this but doing this way got me thinking about how it could be done in <a href=\"https:\/\/www.qgis.org\/\">QGIS<\/a>.<\/p>\n\n\n\n<p>It\u2019s pretty simple if you follow the steps and <a href=\"https:\/\/www.youtube.com\/watch?v=weVXd3XqrDY\">this video<\/a> was enormously helpful as a starting point.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get your map<\/h2>\n\n\n\n<p>You\u2019ll need a map of the area. I chose a world map as the starting point but you could use a more local map. I downloaded the High Definition World Country Polygons from the <a href=\"https:\/\/datacatalog.worldbank.org\/search\/dataset\/0038272\">World Bank Data catalogue<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/03\/1WorldBankData-Maps.png\" alt=\"\" class=\"wp-image-34\"\/><\/figure>\n\n\n\n<p>Unzip this file and look for the .shp file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Open your map in QGIS<\/h2>\n\n\n\n<p>Open QGIS and start a new project (Click Project\u2192New in the top menu)<\/p>\n\n\n\n<p>Drag the .shp file from the unzipped folder to the Layers panel on the bottom left of QGIS. This will create a new layer and add the new map to the right-hand panel.<\/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\/03\/2LoadingMap-1024x493.png\" alt=\"\" class=\"wp-image-35\"\/><\/figure>\n\n\n\n<p><strong>Sidenote:<\/strong><\/p>\n\n\n\n<p>If you want to add labels to the map you can right-click on the new layer you just created and select \u201cproperties\u201d. This will bring up a dialog with a lot of options. Select the \u201cLabels\u201d option and then \u201cSingle Labels\u201d. The \u201cvalue\u201d dropdown menu select the name in your preferred language. In this case select \u201cNAME_EN\u201d. This will add country labels to the map.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/03\/3QGISAddLabels-1.png\" alt=\"\" class=\"wp-image-37\"\/><\/figure>\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\/03\/4WithLabels-1024x535.png\" alt=\"\" class=\"wp-image-38\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Find the area you want to add a grid to<\/h2>\n\n\n\n<p>To isolate the area you want to add the grid to, click the \u2018Select Features\u201d tool in the top menu bar and then click on the country you\u2019re interested in.<\/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\/03\/5SelectArea-1024x589.png\" alt=\"\" class=\"wp-image-39\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Create a new layer from the selection<\/h2>\n\n\n\n<p>With the country selected, click on the \u201cEdit\u201d menu and then \u201cCopy Features\u201d. Then click on \u201cEdit\u201d again and this time select \u201cPaste Features As\u201d. Select \u201cTemporary Scratch Layer\u201d from the options and give your new layer a name. Here we\u2019ve called it \u201cZA\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\/03\/6QGISNewLayer-2-1024x667.png\" alt=\"\" class=\"wp-image-42\"\/><\/figure>\n\n\n\n<p>Untick the world layer to view just the country you selected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Make a grid<\/h2>\n\n\n\n<p>To make a grid of points across the country select the toolbox in the top menu (its the gear icon).<\/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\/03\/7SelectedArea-1-1024x605.png\" alt=\"\" class=\"wp-image-44\"\/><\/figure>\n\n\n\n<p>In the toolbox that appears, search for \u201cgrid\u201d and look for the \u201cCreate Grid\u201d tool.<\/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\/03\/8Toolbox-1-1024x466.png\" alt=\"\" class=\"wp-image-46\"\/><\/figure>\n\n\n\n<p>Double-click on this which will bring up a window with options.<\/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\/03\/9QGIS-GridOptions-1024x818.png\" alt=\"\" class=\"wp-image-47\"\/><\/figure>\n\n\n\n<p>The first thing to notice are the warnings. The default map layer uses degrees. This needs to be changed so that we can measure in metres\/kilometres. Click the small globe icon to the right of the \u201cGrid CRS\u201d option.<\/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\/03\/10QGIS-GridOptionsChangeCRS-1024x818.png\" alt=\"\" class=\"wp-image-48\"\/><\/figure>\n\n\n\n<p>This will bring up an options window. There are various ways to change the co-ordinates but as a start, search for \u201cproject\u201d in the \u201cfilter\u2019 bar at the top. Then select an option<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/editor.mediahack.co.za\/databites\/wp-content\/uploads\/sites\/3\/2023\/03\/11QGIS-CRS-Options.png\" alt=\"\" class=\"wp-image-49\"\/><\/figure>\n\n\n\n<p>Select one of the projection options. You may want to play around with the options once you\u2019re familiar with the process.<\/p>\n\n\n\n<p>You\u2019ll then be able to select the horizontal and vertical spacing in metres or kilometres.<\/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\/03\/12QGIS-GridoptionsinM-1024x815.png\" alt=\"\" class=\"wp-image-50\"\/><\/figure>\n\n\n\n<p>Change the grid spacing to what you need, we\u2019re using a 1km by 1km grid. Notice that you can also switch between points and rectangles for the grid in the \u201cGrid type\u201d option.<\/p>\n\n\n\n<p>Before you create the grid, make sure to select the right \u201cGrid extent\u201d. If you just want to make a grid the country layer click on the three dots and select the country layer as the extent. Click the tree dots, then \u201cUse Layer Extent\u201d. We select the \u201cZA\u201d layer we created before.<\/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\/03\/13QGIS-Grid-Extent-1024x814.png\" alt=\"\" class=\"wp-image-51\"\/><\/figure>\n\n\n\n<p>Now you can run the process, which can take some time depending on the area you\u2019re covering.<\/p>\n\n\n\n<p>Once that\u2019s finished you will have a grid overlaying your country map. Depending on the spacing you chose you probably won\u2019t be able to see the map, just the overlay of points. You\u2019ll also see a new \u201cGrid\u201d layer in the layers panel to the bottom left.<\/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\/03\/14QGIS-grid-1024x694.png\" alt=\"\" class=\"wp-image-52\"\/><\/figure>\n\n\n\n<p>To show the grid and the map map outline you need to use the country map as a clipping path for the points. This will remove the points outside the country\u2019s borders.<\/p>\n\n\n\n<p>Go back to your toolbox and search for \u201cClip\u201d, then click on the vector layer clip option<\/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\/03\/15QGIS-Clip-1024x663.png\" alt=\"\" class=\"wp-image-53\"\/><\/figure>\n\n\n\n<p>Double-click on that for the options window.<\/p>\n\n\n\n<p>In the options you need to set the grid as the input layer and the country as the overlay layer.<\/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\/03\/16QGIS-Clip-Options-1024x819.png\" alt=\"\" class=\"wp-image-54\"\/><\/figure>\n\n\n\n<p>Now run this to create the clip path. By default the new layer will be called \u201cClipped\u201d. You can set that in the clip options. Again, this can take a little while depending on your grid spacing and the size of your country.<\/p>\n\n\n\n<p>When the clipping process is finished, deselect the \u201cGrid\u201d layer in the layer window and you should see just the clipped path and the country outline.<\/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\/03\/17QGIS-post-clip-1024x616.png\" alt=\"\" class=\"wp-image-55\"\/><\/figure>\n\n\n\n<p>Right now it doesn\u2019t look much like a grid but if you zoom in closely you\u2019ll see all the points marking out the grid.<\/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\/03\/18QGIS-Grid-zoom-1024x683.png\" alt=\"\" class=\"wp-image-56\"\/><\/figure>\n\n\n\n<p>You can now export the grid data in the format you want. One word of caution: check the latitude and longitude labels in the data. They may need to be converted back to GPS coordinates.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a number of reasons you may want to make a grid of points covering a geographic area. In my case, I wanted to work out which point in South Africa was the furthest from a police station. <\/p>\n","protected":false},"author":1,"featured_media":86700,"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-33","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\/33","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=33"}],"version-history":[{"count":2,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":89532,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions\/89532"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/media\/86700"}],"wp:attachment":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=33"},{"taxonomy":"newsletter-post","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/newsletter-post?post=33"},{"taxonomy":"site","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/site?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}