Project 2, Crime in Baltimore 2012-2017
Data Source:
Crime data was from the Baltimore Police Department at the following website Baltimore Police Crime Data.
The Baltimore City Polygon was from the City of Baltimore Open GIS data site at Baltimore Open GIS Data.
Tools used
- create grid
- clip
- count points in polygons
- heatmap
- buffer
Data Analysis:
For this project, I downloaded Baltimore Crime data from January 2012 to October 2018 from the Baltimore Police Department. I immediately removed the data from 2018 since it was not a full yearself. The remaining data set was 6 full years of Baltimore City Crime Data.
This was approximatly three hundred and thirty thousand crimes throughout the years which were sorted by year using SQL Query in a SpatiaLite Database by year and then sorted again to remove nonviolent crimes. At the end around sixty thousand crimes in the six year period fit the descritption i was looking for. A diamond grid of Baltimore City was created and crimes were counted in each polygon for each of the six years. This grid crime map was then made into a gif as is seen below. The dark purple is little to no crime and yellow is the high crime areas.
Data was also removed that was recorded in a abnormal fashion not corresponding to where the actual crimes occured. This includes most hospitals and police stations. Previous to removal, these areas were hotspots on the crime density map.
That gif was composed from the following 6 maps
This is the python I wrote to select features of the active layer and add all the project layers
#this is python created by Tom Hunt to determine high crime areas year to year in baltimore from 2012 to 2017
from qgis.core import *
from qgis.gui import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt
from qgis.utils import iface
def load_layer():
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/2012_violent_crimes_density_edited.shp', '2012 Violent Crimes', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/2013_violent_crimes_density_edited.shp', '2013 Violent Crimes', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/2014_violent_crimes_density_edited.shp', '2014 Violent Crimes', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/2015_violent_crimes_density_edited.shp', '2015 Violent Crimes', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/2016_violent_crimes_density_edited.shp', '2016 Violent Crimes', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/2017_violent_crimes_density_edited.shp', '2017 Violent Crimes', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/Balt_City_polygon/baltimore_city_polygon.shp', 'Baltimore City Boundary', 'ogr')
iface.addVectorLayer('Z:/486/Project_2_New/Shapefiles/Balt_city_harbor_water.shp', 'Baltimore Harbor Water', 'ogr')
# all the above addvectors are confirmed to work.
Layer = iface.mapCanvas().currentLayer()
expr = QgsExpression( "\"NUMPOINTS\"=25" )
it = Layer.getfeatures( QgsFeatureRequest( expr ) )
ids = [i.id() for i in it]
cLayer.setSelectedFeatures( ids)
#These below are to change the color of the layer,
def change_color():
active_layer = iface.activeLayer()
renderer = active_layer.renderer()
symbol = renderer.symbol()
symbol.setColor(QColor(Qt.blue))
active_layer.triggerRepaint()
iface.layerTreeView().refreshLayerSymbology(active_layer.id())
Crime Heat Map
Below is a heat density map made from the point shapefiles added up from 2012 to 2017. You can see a couple portions of the harbor/downtown area with dark red meaning high crime. The Darkest red area is where the Royal Farms Arena is, right at the end of the inner harbor. The other dark red spot to the east of that is a high crime area boxed in by Broadway east to the North, Middle East to the south, Gay Street to the west and Madison Eastend to the East.
Crime Free Areas in Baltimore
The below map was created using my edited/cleaned up Violent crime point vector file containing all violent crime from 2012-2017. I gave all points a 1000 foot buffer and then dissolved the file. Below we will blow up two of the main violent crime free areas.
As you would think, the safest places in Baltimore are parks and industrial areas. cemeteries arent bad either.
Tuscany-Canterbury
A neighborhood with no violent crimes within 1000 feet