Analyzing violent crime¶
Many of the poorest neighborhoods in the City of Chicago face violent crimes. Since some studies have linked alcohol to different crimes, there is pressure on the city officials to close down liquor establishments. The local business owners, on the other hand, want to block such restrictions as it could negatively impact business and the social fabric of the City. In this sample, we will perform an illustrative analysis to find a find a possible relation between violent crimes and liquor establishments. This will also help us figure out if poverty and unemployment rate are factors which contribute to more crimes in a specific area of the city. We will be using the Crime Analysis data from ArcGIS Living Atlas of the World in order to perform this analysis. The data was orginally obtained from the 2014 Violent Crime Data in the City of Chicago data portal (https://data.cityofchicago.org).
Through this sample, we will demonstrate the utility of a number of spatial analysis methods including hot spot analysis, feature overlay, data enrichment and spatial selection using ArGIS API for Python.
Further, based on the results of the analysis, this sample will try to assist with an effective solution to this problem.
Table of Contents
- Outline of Steps
- Necessary Imports
- Connect to your GIS
- Get the data for the analysis
- Create a hot spot map of violent crime densities
- Create a hot spot map of liquor vendors to compare to the violent crime hot spot map
- Get poverty data for each of the polygon grids in the violent crime hot spot analysis layer
- Create a hot spot map of poverty
- Overlay the violent crime and liquor vendor to find where they overlap.
- Overlay-the-violent-crime,-liquor-vendor-and-poverty-hot-spot-maps-to-find-where-they-overlap
- Get the unemployment rate data matching the violent crime trends layer
- Create a hot spot map of the unemployment rate data
- Overlay the crime trends map with the unemployment hot spot map
- Select the high schools falling within a quarter mile of the proposed remediation areas
- Conclusion
- Summary of tools
- Terms of use
Outline of Steps¶
We will use the following workflow for the analysis:
- Retrieve Crime Analysis data.
- Plot the data on map for visualzation
- Perform spatial analysis:
- We will first create hotspots for the crime densities and liquor vendor layers. This will help is in visualizing the significant areas of crime incidences and liquor vendors.
- Enrich the crime layer with poverty and unemployment rate data using the enrich_layer tool.
- Visualize hotspots on the enriched layers.
- Use overlay tool to find relationship between crimes and liquor establishments. This will also help to know whether or not poverty and unemployment rate are factors contributing to more crimes in any specific area of the city.
- Suggest ways for reducing crime based on the results of our analysis
Necessary Imports¶
from datetime import datetime as dt
from IPython.display import display
from arcgis import GIS
from arcgis.features.analyze_patterns import find_hot_spots
from arcgis.features.enrich_data import enrich_layer
from arcgis.features.manage_data import overlay_layers
from arcgis.features.find_locations import find_existing_locations
Connect to your GIS¶
gis = GIS('home')
Get the data for the analysis¶
Search for CrimeAnalysisData layer in ArcGIS Online. We can search for content shared by users outside our organization by setting outside_org to True.
items = gis.content.search('title:CrimeAnalysisData owner:api_data_owner', 'feature layer')
for item in items:
display(item)
We will use the first item for our analysis. Since the item is a Feature Layer Collection, accessing the layers property will give us a list of FeatureLayer objects.
crime_item = items[0]
lyrs = crime_item.layers
The code below cycles through the layers and prints their names.
for lyr in lyrs:
print(lyr.properties.name)
We'll get the second layer and assign it to the violent_crimes
variable. Similarly, get the analysis_boundary
layer.
violent_crimes = lyrs[2] # Violent Crime 2014
analysis_boundary = lyrs[3] # Analysis Boundary
Let's visualize the crime incidents on a map of Chicago.
crime_map = gis.map('Chicago')
crime_map
crime_map.add_layer(violent_crimes)
It is difficult to discern spatial patterns with so many points on the map. To make sense of the more than 22,000 crime points, and over 1,500 business points, we will map them using hot spot analysis.
We can add a number of different layer objects such as FeatureLayer, FeatureCollection, ImageryLayer, MapImageLayer to the map by calling the add_layer() method.
Create a hot spot map of violent crime densities¶
ArcGIS has a set of tools to help us identify, quantify and visualize satial patterns in our data by identifying areas of statistically significant clusters.
The find_hot_spots
tool allows us to visualize areas having such clusters.
crime_hot_spots = find_hot_spots(violent_crimes,
output_name='ViolentCrimeHotSpots' + str(dt.now().microsecond),
bounding_polygon_layer=analysis_boundary)
crime_hot_spots
crime_spots_map = gis.map('Chicago')
crime_spots_map