Difference between revisions of "Analyzing Crime Data in Ottawa using QGIS"

From CUOSGwiki
Jump to navigationJump to search
Line 4: Line 4:
 
==Where to get the data?==
 
==Where to get the data?==
 
Based on the statistics that the Ottawa Police Service have provided, the MADGIC librarians at Carleton University created the shapefiles and they are available for downloaded from the MacOdrum Library website. Considering it is an open source dataset, no login information is required.
 
Based on the statistics that the Ottawa Police Service have provided, the MADGIC librarians at Carleton University created the shapefiles and they are available for downloaded from the MacOdrum Library website. Considering it is an open source dataset, no login information is required.
  +
 
The shapefiles are available for download at this link: http://madgic.library.carleton.ca/deposit/GIS/Crime_Statistics.zip
 
The shapefiles are available for download at this link: http://madgic.library.carleton.ca/deposit/GIS/Crime_Statistics.zip
   

Revision as of 20:37, 5 October 2020

Introduction

The main purpose of this tutorial is to identify trends in crime in the Ottawa region using open source software. QGIS is the software that will be used for this tutorial. QGIS version 3.14 "Pi" can be downloaded here: (https://www.qgis.org/en/site/forusers/download.html). The data includes many different types of crimes that occurred in Ottawa from 2005 to 2013. The sub regions include: Orleans, Innes, Barrhaven, Kanata North, West-Carleton March, Stittsville-Kanata West, Bay, College, Knoxdale-Merivale, Gloucester-Southgate, Beacon Hill-Cyrville, Rideau-Vanier, Rideau-Rockcliffe, Somerset, Kitchissippi River, Capital, Alta Vista, Cumberland, Osgoode, Rideau-Goulbourn, Gloucester-South Nepean and Kanata South. Some examples of the crimes in the data set are: Total Criminal Code of Canada (CCC) including Traffic, Total Criminal Code of Canada (CCC) excluding Traffic, Crimes against Person, Total number of Homicides, Total Number of Attempted Murders, Total Number of Robberies and Total Number of Assaults (including Sexual Assaults), Total Number of Other Sexual Offences, Number of Abductions, Total Number of Uttering Threats or Intimidation Offences and Total Number of Other Crimes.

Where to get the data?

Based on the statistics that the Ottawa Police Service have provided, the MADGIC librarians at Carleton University created the shapefiles and they are available for downloaded from the MacOdrum Library website. Considering it is an open source dataset, no login information is required.

The shapefiles are available for download at this link: http://madgic.library.carleton.ca/deposit/GIS/Crime_Statistics.zip

Wheretoget.png

Loading the Dataset into the QGIS

First step was to select Add Vector Layer symbol. Second step was to use Browse function to locate the data. Finally all shapefiles (.shp) from each year were selected from the Crime Wards Shp folder and loaded into QGIS.

Loading.png

Layer Properties

Layers Properties can be opened by right clicking any of the layers and selecting properties. Right clicking the Layer Properties would bring up the following screen.Layer Properties include: General Settings, Style, Labels, Fields, Rendering, Display, Actions, Joints, Diagrams and Metadata.

Layerpro.png

General Settings

General1.png

Under General Settings:

  • Layer name can be modified and displayed as something else
  • Layer source can be modified
  • Data source encoding can be changed (System, Windows, and Macintosh etc.)
  • Coordinate Reference System can be changed
  • Scale dependency can be turned on to restrict the minimum and the maximum scale

Labels

Labels.png

Labels can be turned on turned and displayed for any columns. Labels Settings include:

  • Text (to modify the size, font style, transparency, color and style of the text)
  • Formatting (to modify the line height and alignment)
  • Buffer
  • Background (to modify the background settings)
  • Shadow
  • Placement (to modify the placement such as: offset from centroid, offset centroid, around centroid, using perimeter, horizontal and free and to set up priority for the text)
  • Rendering (to perform scale based visibility and pixel based visibility etc.)

Fields

Fields.png

Within the Field properties’ you can edit the field data as well as create new fields using the Field Calculator. Any new fields you create will appear at the bottom of the field list. Scroll down and make sure they appear right.

New output-field name, output-field type, output-field width and output-field precision should be determined when creating a new column. As an example new field called “area” is created, which is under geometry function called “$area”. It is going to be used to determine the population density because the data does not have that information, it only has total population. (Area/ 1000000 was used to get the area km^2 value)

Creatingarea.png

Creating the population density field

The total population divided by the total area would give us the population density. This process needs to be done for each layer that is going to be used. I am going to repeat the same process for the 2010 and 2013 layers so that the comparison between those layers can be done. If you want to use other layers rather than 2005, 2010 and 2013, area calculation and population density needs to be done for the interested layers.

Popden.png

Rendering

Rendering can be done to simplify the geometry. Simplification threshold can be customized, and the scale can be set up for rendering process.

NewRendering.png

Additional Settings under Layer Properties

Additionally Display Settings, Actions, Joints and Metadata can be accessed under Layer Properties.

Additionals.png


Using Style and Diagram Functions under Layer Properties

Style Function

Under Style there is a dropdown menu, which the Single Symbol, Categorized, Graduate, Rule Based, Point Displacement, Inverted Polygons and Heat Map can be selected. For the purpose of this tutorial I am mainly going to focus on the Graduate Style.

Single Symbol

Single Symbol Function is useful for showing the features without any categorization. As an example below: Map of Ottawa without any categorization.

Mapottsingle.png

Categorized Style

Categorized style is useful for showing simple categorizations. As an example below: Map of Ottawa showing the wards in different colors.

Catott.png

Graduated Symbols

Graduated Symbols are useful for displaying the features based on their numerical values. First style needs to be selected as Graduated then column needs to be selected and after that Classes, Color Ramp, and Legend Format needs to be determined. As an example: I have selected Population density for the column and set the class number to 10, then I have selected the color ramp to red (the higher the number the darker red it would be), and I have set the legend format to %1 - %2.

NewGradSymbol.png


Pop2005.png

Figure is showing the population density by the wards for 2005 in Ottawa

Rob2005.png

Figure is showing the total number of robberies by the wards in 2005 in Ottawa

Quick Analysis: Even though Somerset ward has one of the highest population densities with Rideau Vanier ward. The total number of robberies are lower at Somerset ward compare to Rideau Vanier ward. Capital ward has one of the highest population densities in the city coming after Somerset ward and Rideau Vanier ward, however Capital ward has one of the lowest total number of robberies in Ottawa.

Diagrams

Diagrams are useful for showing multiple features on a single layer. First display diagram should be toggled on. Then diagram type should be selected (Pie Chart, Histogram or Text diagram). After that priority level was set to medium. Furthermore size and positions can be rearranged under the size and the position tabs. Additionally minimum size of the diagram was set to 5 to make all the diagrams visible. Then under Position tab placement was selected to free. And finally attributes were assigned, in this case total number of robberies, total number of abductions and total number of break ins were assigned as an attribute.

NewDia.png


Maps below are showing the difference between the Pie Chart diagram type and text diagram type for the same data.

Piechartdia.png

Figure is showing the Pie chart diagram type

Textdia.png

Figure is showing the text diagram type

Looking at Statistics in 3D

Analyzing and interpreting the statistics of the Ottawa Crime Data in 2D has many uses. But you can look at the same data in 3D.

Utilizing the QGIS plugin QGIS2threejs you can transform flat 2D DEMs, vector data and terrain data into 3D maps. Looking at other Tutorials and background information you can get a better grasp of the capabilities of this plugin;

Before starting anything you need to install the QGIS2threejs Plugin. This is done by clicking the Plugins tab on the main banner, then selecting Manage and Installing Plugins. This will generate a Plugins wizard. Plugins2.png

2threejs.png

As you can see there are many plugins. If you know the desired plugin you can scroll to it or you can search the list of plugins. Each plugin comes with it's own description. Once you've selected your desired plugin click Install Plugin.

Looking around you'll see that nothing really has changed. If you click on the Web tab on the main ribbon you'll see QGIS2threejs, click on it.

2threejs2.png

The QGIS2threejs Plugin has alot of power in what you can do. Along the top you can choose from among template files.

2threejs3.png

Along the left-hand side you can see how you can choose from many options. While on the right-hand side you can set your inputs.

Clicking World lets you set your extents, the default will be your project.
Clicking Controls allows you to choose in what manner you want to interact with your 3D map.
Clicking DEM lets you select which elevation data to use or just leave it as a flat plane.
Clicking Additional DEM allows you to add more DEM's (ex. Heat maps) to you map, adding content.
Clicking Point allows you to choose from existing Point features within your project to add in or become the focus of.
Clicking Line allows you to choose from existing Line features within your project to add in or become the focus of.
Clicking Polygon allows you to choose from existing Polygon features within your project to add in or become the focus of.

Within this example we'll focus on the Polygon aspect and check out the first CrimeWards_2005. Notice that you can select multiple Polygons and incorporate them into your map.

By selecting this polygon you'll notice how the inputs on the right are no longer grayed-out and you can set your desired inputs. Object Type has two options; Extrude or Overlay.

Overlay works with existing DEM files and allows you to drape it over with your settings.

Extrude on the other hand extrudes your polygon based on a set height. This will be the one to select for this exercise.

Within the Z coordinate mode you have options on where the extrusion will occur from. The default is the DEM but you can choose a field. You then can set the desired height.

For this example we'll leave it at the default Relative to DEM and set the height to 0 for now as we're not working with any DEMs.

Within the Style mode you can select how you want the 3D map to be depicted by setting Color, Transparency, Height and Value.

There are options within the Color input, select Random as this will be very distinct, as well as Transparency, leave at it's default. Within Height we'll be selecting what Field in the CrimeWards_2005 that'll be your focus.

Let's choose Assault Rates (asslt_rate) and give it a Multiplier of 10 so differences will be very exaggerated.

The Features mode allows you to select which features will be the output. You can choose everything or something specific.

Check All features

Within the Attribute and label mode you can choose what attributes will be on your map as you interact with it. First you'll have to check Export attributes.

Within the Label field you can assign whatever label you want to each of your polygons (Ex. Ward Name) or just leave them blank.

Label height and Value can also be set but we'll leave them as is for now.

Lastly you can set an Output HTML file path but you needn't right now. Your wizard should look like this.

Demo1.png

You'll now have an interactive window wherein you can zoom in and move around looking at each ward. In this case you can see that the Rideau-Vanier ward clearly has the largest Assault Rate.

You can click on individual wards and see their attributes.

This method of mapping allows you to visually analyze the distribution of your stats. Though this is at a very basic level further development would allow you to create 3D maps with an abundance of content.

Additional Statistics

Additional statistics can be obtained under Vector tab/Analysis tool/Basic Statistics. Input Vector Layer needs to be selected then type of crime needs to be selected. As a result it will show the mean, standard deviation, sum, min, and max, number of unique values, range and median.

NewAnalysis1.png

NewAnalysis2.png

Different Scenarios

Scenario 1 (Comparing the Impaired driving data from 2005, 2010 and 2013)

Sa.png

Quick Analysis: The number of impaired driving occurrences in suburbs (Kanata, Cumberland) from 2005 to 2010 has become lower. However the number of impaired driving occurrences in east end from 2010 to 2013 has become significantly higher, and the number of impaired driving occurrences increased dramatically in College ward in from 2005 and 2010 to 2013.


Scenario 2 (Analyzing the total number of violent crimes, the total number of assaults and the number of traffic offences from 2010 data using Diagrams )

Sce2.png


The diagrams are showing that the western and the southern areas of Ottawa have less number of violent crimes, assaults and traffic offences even though they have relatively similar population density. Somerset ward has the highest population density as well as the highest number of violent crimes, assaults and traffic offences.

Conclusion

Conclusively this tutorial highlights that QGIS was a powerful open source GIS software for analyzing the crime trends in Ottawa from 2005 to 2013. There are many other different crimes to analyze from, only limited number of crimes were highlighted in this tutorial. The QGIS software can be downloaded from the website highlighted above and the crime data can be downloaded from the MacOdrum Library website mentioned above for further analysis.

Reference List

  • Ottawa Police Service Crime Data. (2013).

The data is gathered from the Carleton University MADGIC Desk’s website.

Retrieved from: http://madgic.library.carleton.ca/deposit/GIS/Crime_Statistics.zip

  • QGIS 2.8.2 Software downloaded from:

https://www.qgis.org/en/site/forusers/download.html