Creating a grid overlay for a map using QGIS
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 […]
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 QGIS.
Itâs pretty simple if you follow the steps and this video was enormously helpful as a starting point.
Get your map
Youâll 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 World Bank Data catalogue.
Unzip this file and look for the .shp file.
Open your map in QGIS
Open QGIS and start a new project (Click ProjectâNew in the top menu)
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.
Sidenote:
If you want to add labels to the map you can right-click on the new layer you just created and select âpropertiesâ. This will bring up a dialog with a lot of options. Select the âLabelsâ option and then âSingle Labelsâ. The âvalueâ dropdown menu select the name in your preferred language. In this case select âNAME_ENâ. This will add country labels to the map.
Find the area you want to add a grid to
To isolate the area you want to add the grid to, click the âSelect Featuresâ tool in the top menu bar and then click on the country youâre interested in.
Create a new layer from the selection
With the country selected, click on the âEditâ menu and then âCopy Featuresâ. Then click on âEditâ again and this time select âPaste Features Asâ. Select âTemporary Scratch Layerâ from the options and give your new layer a name. Here weâve called it âZAâ.
Untick the world layer to view just the country you selected.
Make a grid
To make a grid of points across the country select the toolbox in the top menu (its the gear icon).
In the toolbox that appears, search for âgridâ and look for the âCreate Gridâ tool.
Double-click on this which will bring up a window with options.
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 âGrid CRSâ option.
This will bring up an options window. There are various ways to change the co-ordinates but as a start, search for âprojectâ in the âfilterâ bar at the top. Then select an option
Select one of the projection options. You may want to play around with the options once youâre familiar with the process.
Youâll then be able to select the horizontal and vertical spacing in metres or kilometres.
Change the grid spacing to what you need, weâre using a 1km by 1km grid. Notice that you can also switch between points and rectangles for the grid in the âGrid typeâ option.
Before you create the grid, make sure to select the right âGrid extentâ. 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 âUse Layer Extentâ. We select the âZAâ layer we created before.
Now you can run the process, which can take some time depending on the area youâre covering.
Once thatâs finished you will have a grid overlaying your country map. Depending on the spacing you chose you probably wonât be able to see the map, just the overlay of points. Youâll also see a new âGridâ layer in the layers panel to the bottom left.
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âs borders.
Go back to your toolbox and search for âClipâ, then click on the vector layer clip option
Double-click on that for the options window.
In the options you need to set the grid as the input layer and the country as the overlay layer.
Now run this to create the clip path. By default the new layer will be called âClippedâ. 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.
When the clipping process is finished, deselect the âGridâ layer in the layer window and you should see just the clipped path and the country outline.
Right now it doesnât look much like a grid but if you zoom in closely youâll see all the points marking out the grid.
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.