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.
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.