By David Crowther
Question:
How do you create a heatmap within QGIS?
Answer:
A Heatmap is a common method to show incident rates across a geographic area. They are created using an interpolation technique which are commonly used in mapping Temperature, Terrain and Crime datasets.
When generating heatmaps you should be conscious of the interpolation technique that you use and it should try to complement the type of data that you are mapping. This FAQ does not look to describe those mathematical techniques and why they are used, but as a rule you should use the below techniques with these datasets:
- Triangular Irregular Networks (TIN) – Terrain datasets
- Inverse Distance Weighting (IDW) – Temperature values
- Kernel Density Estimator (KDE) – Crime Incidents
In this FAQ we have a dataset of crime incidents across Northamptonshire, where each incident is represented as a single point on the map.
Showing a crime map of point locations has its advantages and disadvantages.
Pros:
- they are easily understood by the user.
- each incident has a given location, so is accurate and doesn’t generalise across a region.
Cons:
- they can be too accurate for sensitive datasets.
- do not allow the user to see if there are multiple points at the same location.
- do not consider co-incident data, so applies no weighting where there are multiple incidents in the same area.
- only maps data at a given location and does not allow users to understand possible incident rates for their chosen location.
So, while Point data maps are useful, you may wish to utilise some form of interpolation to better understand a weighting of incident rates to generate an incident map across the whole area.
In QGIS, there is a Heatmap tool available within the Processing Toolbox.
In the Heatmap (KDE) tool….
Choose the following options and settings:
- Point Layer = your crime incident point layer.
- Radius = the radial distance from any given point that is used to work out if other incidents are nearby. The larger the distance the bigger the output hotshots will be.
- Output Raster size = the pixel size of the raster heatmap. The smaller the pixel size, the more fine the resolution of the raster heatmap image will be. The larger the pixel size the more pixelated/blocky the output will be.
Small Radius e.g., 100 metres – will mean the hotspots don’t join up to create a continuous surface.
Bigger Radius e.g., 350 metres – will mean you create a continuous heatmap surface.
Large Pixel Size e.g. 100 metres – will result in a pixelated map.
Smaller Pixel Size e.g. 10 metres – will create a smoother surface.
Trial and error will help you determine the Radius and Pixel Size to use for your data. In my example I have chosen a Radius of 250 metres and a pixel (grid) size of 10 metres.
Having created the heatmap surface, we can choose the Layer Properties to change the colour band being used and apply some additional techniques to add colour ranges and classification techniques.
Firstly, lets change the Render Type from Singleband Grey to Singleband Pseudocolour.
Choose the Colour Ramp to apply e.g. Spectral.
You can also change the interpolation technique, but we will leave this as Linear.
If you now press Classify the data is separated out into ranges. Each Pixel created in the heatmap surface will have a value, and will therefore be coloured red, amber, green, blue etc… based on that high or low value.
If you now press Apply, the classification changes the heatmap surface from grey to the newly classified colour ramp.
Initially the Spectral Colour Ramp has the colours the wrong way around, as it has Red for Low values and Blue for High values. So, edit the Layer Properties and Invert the Colour Ramp to swap the colours around.
When you now apply the changes, the blue areas are those with the lowest incident rates, and the red hotspot areas are showing the highest incident rates.
If we now add the Crime (Point) Layer back into the map as single points on top of the heatmap surface, we can start to visualise the interpolation of incident rates across our chosen area.
This is a perfect example of why we would use a heatmap for incident data. As we can see there is a red hotspot on right of the map, but there appears to only be one crime point there.
However, if we interrogate that location, there are 7 incident points on top of each other. With a simple point map this hotspot would have been missed but using the heatmap technique we have identified this hotspot area!
Comments (0 comments)