Difference between revisions of "Creating a Heatmap using QGIS"

From CUOSGwiki
Jump to navigationJump to search
Line 58: Line 58:
   
 
==== Result ====
 
==== Result ====
  +
In this section we would be making 2 final maps. One with the output of the Heatmap Render and one with the output of the interpolation tool “Heatmap (Kernel Density Estimation)”.
  +
For the first Map:
  +
# Deselect the new Heatmap layer.
  +
# On the Toolbar Click on Project and then New Print Layout.
  +
# Name the Layout and click Ok.
  +
# On the Toolbar, click Add Item and select Add Map. Create the extent for the map on the layout.
  +
# Add a North Arrow, Scale Bar, Title and Legend.
  +
# Export as PDF or Image.
  +
For the Second Map:
  +
# Reselect the new Heatmap layer.
  +
# Move the “Toronto Neighbourhood” layer above the new “Heatmap” layer and reduce its Opacity to “50%” by right-clicking and the properties and then “Layer Rendering”.
  +
# On the Toolbar Click on Project and then New Print Layout.
  +
# Name the Layout and click Ok.
  +
# On the Toolbar, click Add Item and select Add Map. Create the extent for the map on the layout.
  +
# Add a North Arrow, Scale Bar, Title and Legend.
  +
# Export as PDF or Image.
   
 
==Limitations ==
 
==Limitations ==

Revision as of 03:06, 14 December 2020

Purpose

The purpose of the tutorial is to provide users with a step by step process of how to create a heatmap on QGIS. This tutorial will contain detailed explanations on how to download and use the QGIS software, how to get open source data and how to use the Heatmap feature in Symbology, make analysis and inferences from the data and how to create a map in QGIS. The tutorial will also cover the limitations of QGIS for making Heatmaps. For the tutorial, we would be making a Toronto Crime Heatmap with Data from the Toronto Police.
This tutorial covers themes of Open source Data, Spatial Pattern Analysis and Spatial Interpolation.

Disclaimer: This Tutorial is for Educational Purposes only. The result of the Tutorial shows real crime committed in the city of Toronto. Due to the sensitivity of the data to be used, we would only be making heat maps for Property related crimes.
In accordance with the Municipal Freedom of Information and Protection of Privacy Act, the Toronto Police Service has taken the necessary measures to protect the privacy of individuals involved in the reported occurrences. No personal information related to any of the parties involved in the occurrence will be released as open data. The location of crime occurrences have been deliberately offset to the nearest road intersection node to protect the privacy of parties involved in the occurrence. All location data must be considered as an approximate location of the occurrence and users are advised not to interpret any of these locations as related to a specific address or individual.

Introduction

Heatmaps are one of the best visualization tools for dense point data. Heatmap is an interpolation technique that is useful in determining density of input features. Heatmaps are most commonly used to visualize crime data, traffic incidents, housing density etc. The density is calculated based on the number of points in a location, with larger numbers of clustered points resulting in larger values. Heatmaps allow easy identification of “hotspots” and clustering of points. QGIS has a heatmap renderer that can be used to style a point layer and a Processing algorithm Heatmap (Kernel Density Estimation) that can be used to create a raster from a point layer.

Materials

About QGIS

Quantum GIS, better known and QGIS, is arguably the most powerful and commonly used free open source geographic information system software available. It allows the user to create, edit, visually represent, analyze and publish information. It is available for download on a variety of operating systems from Windows, Mac, Linux and BSD, with recent efforts working towards compatibility with Android. QGIS is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA).

Download QGIS

This tutorial was originally done with QGIS version 3.10.10 ‘A Coruña’ which was released in November 2019. It is available for download on their Official Website. Download and install that version or a more recent version of QGIS for your operating system in order to follow along with the following step-by-step tutorial.

Data Acquisition

There are numerous resources available to acquire spatial data for use in QGIS including Open Data Catalogues, Scholars GeoPortal, Ontario GeoHub etc.
For this tutorial, we will be acquiring data from the “Toronto Police Service Public Safety Data Portal”. The Toronto Police documents and release Public Safety Data. “The Public Safety Data Portal is intended to improve the understanding of policing, improve transparency and enhance confidence through the creation and use of open data for public safety in Toronto.”
Dataset to be used:

  • Major Crime Indicators (MCI) 2014 - 2019 shapefile. Categories are Assault, Break and Enter, Auto Theft, Robbery and Theft Over (Excludes Sexual Assaults)
  • Toronto Neighbourhood Boundary shapefile. This also contains crime data but we just need the shapefile for its boundaries, to provide context for the MCI data.


Steps in data acquisition:

  1. Go to the MCI page by clicking the link (https://data.torontopolice.on.ca/datasets/mci-2014-to-2019)
  2. Click on Download and under Full Dataset click on Shapefile
  3. Repeat the same process for the Neighbourhood Boundary page by clicking the link (https://data.torontopolice.on.ca/datasets/neighbourhood-crime-rates-boundary-file-)
  4. Extract (Unzip) both folders and save in the working director you will be using.

Tools and Methods

Getting started

For this tutorial we would not be changing the Projection and would be using the source projection.

Import Data

  1. The fastest way to import Data is by going through the Browser Panel on the left of your new project screen and navigating to where you stored the 2 shapefiles. In my case I stored the shapefiles in the Download folder. Drag both shapefile to the layers panel. You would need to transform the Neighbourhood Data to match the Projects Projections. Simply click Ok.
  2. Next we would be adding the basemap that is provided by QGIS. in the browser panel, you should see a directory called “XYZ Tiles”. In there is the “OpenStreetMap”. Drag that down to the Layer panel.


At this point your screen should look like this. You might have to rearrange the layers in this order: MCI layer, Neighbourhood layer and OpenStreetMap layer. Feel free to rename the layers, and change the symbology for easy visualization.

Process

In this section we would be altering the data to do what we need with it. Feel free to explore the Attribute Table for the MCI layer.
Because this shapefile contains a lot of data for ranging (Field name: occurren_1) from 2000 - 2019 (even though the shapefile says 2014 - 2019), we would only be working with 2019 data. Due to the sensitivity of the data we are using, we would only be making heat maps for Property related crimes according to the Department of Justice categorization: Break & Entry (all types), Theft of Motor Vehicle and Non-vehicle Theft (all of theft).

Methodology

Result

In this section we would be making 2 final maps. One with the output of the Heatmap Render and one with the output of the interpolation tool “Heatmap (Kernel Density Estimation)”. For the first Map:

  1. Deselect the new Heatmap layer.
  2. On the Toolbar Click on Project and then New Print Layout.
  3. Name the Layout and click Ok.
  4. On the Toolbar, click Add Item and select Add Map. Create the extent for the map on the layout.
  5. Add a North Arrow, Scale Bar, Title and Legend.
  6. Export as PDF or Image.

For the Second Map:

  1. Reselect the new Heatmap layer.
  2. Move the “Toronto Neighbourhood” layer above the new “Heatmap” layer and reduce its Opacity to “50%” by right-clicking and the properties and then “Layer Rendering”.
  3. On the Toolbar Click on Project and then New Print Layout.
  4. Name the Layout and click Ok.
  5. On the Toolbar, click Add Item and select Add Map. Create the extent for the map on the layout.
  6. Add a North Arrow, Scale Bar, Title and Legend.
  7. Export as PDF or Image.

Limitations

Limitations to this tutorial include:

  • QGIS map creation isn't as good as ESRI’s ArcGIS Pro, or ArcMaps
  • Heatmaps can often be misinterpreted. Heat maps express clusters, and one can look at a map and think there is no crime except at the hotspot zone which is wrong
  • Using real crime data might alter one's perception of a city which may or may not be misleading.
  • The Heatmap Render does not produce a legend or values used to calculate for the heatmap. And the interpolation tool “Heatmap (Kernel Density Estimation)” produces a heatmap that is not visually appealing.

Conclusion

Heatmaps are one of the best visualization tools for dense point data and are used to visualize crime data, traffic incidents, housing density and more.
The purpose of the tutorial was to provide users with a step by step process of how to create a heatmap on QGIS. This tutorial contained details on how to download and use the QGIS software, how to get open source data, how to create multiple Heatmaps, and how to make analysis and inferences from the data. The tutorial also covered the limitations of QGIS for.
Due to the facts that we are working with crime data which is sensitive, the tutorial is for Educational Purposes only.
I hope this tutorial will help future users have a better understanding of QGIS, Open source Data and Spatial Pattern Analysis.

Resources

1. Heatmap: https://www.crazyegg.com/blog/understanding-using-heatmaps-studies/
2. QGIS: https://qgis.org/en/site/forusers/download.html
3. Toronto Police SErvice PSDP: https://data.torontopolice.on.ca
4. Department of Justice: https://www.justice.gc.ca/eng/rp-pr/cj-jp/victim/rr05_4/p7.html#a5_2
5. QGIS Expressions: https://docs.qgis.org/2.18/en/docs/user_manual/working_with_vector/expression.html