The Metropolitan Police Department of the City of St. Louis collects monthly crime statistics to inform the public of the type and location of crimes. This post takes a look at the crime statistics for July 2014. The data is provided as a CSV (comma separated values) file which contains 20 columns containing times, locations and crime descriptions. We can import this information into the Wolfram Language using the Import command:
In[]:=
data=Import["July2014.CSV"];
Here is a snapshot of the first 20 recorded crimes for this month. A full explanation of this data is provided on the website. (For a part of this data set the actual crime occurrence is before the month of July, but we will include them since they were recorded for July 2014). For our purposes we use the Description and Crime fields and the location fields (XCoord and YCoord):
In[]:=
data=data[[All,{1,9,11,19,20}]];Grid[data[[1;;21]],ItemSize->Full]
Out[]=
Complaint | Crime | Description | XCoord | YCoord |
14-030620 | 21000 | RAPE -- FORCIBLE | 0 | 0 |
14-031420 | 69602 | LARCENY-ALL OTHER $500 - $24,999 | 889438. | 1004318 |
14-029455 | 179210 | SEX OFFNS-CHILD MOLESTATION-FIRST DEGREE | 0 | 0 |
14-033895 | 115400 | STLG BY DECEIT/IDENTITY THEFT REPORT | 904291. | 1020354 |
14-030968 | 67601 | LARCENY-FROM BUILDING $500 - $24,999 | 879143. | 998940. |
14-029638 | 204100 | FAMILY & CHILD CRIME-ENDANGR WELF CHILD | 887717 | 1033290 |
14-034430 | 115400 | STLG BY DECEIT/IDENTITY THEFT REPORT | 0 | 0 |
14-034082 | 115400 | STLG BY DECEIT/IDENTITY THEFT REPORT | 0 | 0 |
13-005573 | 67601 | LARCENY-FROM BUILDING $500 - $24,999 | 0 | 0 |
14-029139 | 65701 | LARCENY-MTR VEH PARTS UNDER $500 | 901057. | 1006555 |
14-032508 | 67601 | LARCENY-FROM BUILDING $500 - $24,999 | 896804. | 1010529 |
14-034691 | 67601 | LARCENY-FROM BUILDING $500 - $24,999 | 884147. | 1004647 |
14-030370 | 262100 | PORNAGRAPHY-PROMOTING | 879748. | 1011877 |
14-033935 | 111110 | FRAUD-BAD CHECK/INSUF FUNDS/OVER $150 | 878181. | 1014948 |
14-031395 | 115400 | STLG BY DECEIT/IDENTITY THEFT REPORT | 880334. | 997317. |
14-034503 | 65701 | LARCENY-MTR VEH PARTS UNDER $500 | 902147. | 1028781 |
14-032707 | 69602 | LARCENY-ALL OTHER $500 - $24,999 | 905630. | 1035403 |
14-033437 | 65601 | LARCENY-MTR VEH PARTS $500 - $24,999 | 899572. | 1044964 |
14-034671 | 65701 | LARCENY-MTR VEH PARTS UNDER $500 | 888607 | 994223. |
14-029939 | 67701 | LARCENY-FROM BUILDING UNDER $500 | 877934. | 1008590 |
We can turn this data into a Dataset, which is a built-in function to work with data in a convenient way:
In[]:=
keys=First[data];values=Rest[data];dataset=Dataset[Map[Association@@MapThread[Rule,{keys,#}]&,values]]
Out[]=
We will delete cases which have no recorded location (XCoord and YCoord equal to zero):
In[]:=
dataset=dataset[Select[And[#XCoord!=0.,#YCoord!=0.]&]]
Out[]=
Next we will need to take the XCoord and YCoord values and convert them to usable latitudes and longitudes. The XCoord and YCoord values are so-called Eastings and Northings for the Missouri East State Plane projection. In practice I needed to use a slightly modified version of this projection, with a slightly modified GridOrigin:
projection="SPCS83MO01";
This converts the data into useable geo positions (in latitude/longitude format):
In[]:=
(geomarkers=Normal@dataset[All,GeoPosition[GeoGridPosition[{Quantity[#XCoord,"Feet"],Quantity[#YCoord,"Feet"]},projection]]&])//RandomSample[#,20]&
Out[]=
{GeoPosition[{38.6576,-90.2253}],GeoPosition[{38.6695,-90.2213}],GeoPosition[{38.6651,-90.2628}],GeoPosition[{38.6108,-90.2853}],GeoPosition[{38.6185,-90.3051}],GeoPosition[{38.5776,-90.2539}],GeoPosition[{38.664,-90.207}],GeoPosition[{38.5766,-90.2331}],GeoPosition[{38.672,-90.2794}],GeoPosition[{38.6267,-90.2612}],GeoPosition[{38.6045,-90.2784}],GeoPosition[{38.673,-90.2034}],GeoPosition[{38.6105,-90.2793}],GeoPosition[{38.6096,-90.2088}],GeoPosition[{38.5511,-90.2593}],GeoPosition[{38.5724,-90.2897}],GeoPosition[{38.7165,-90.235}],GeoPosition[{38.6722,-90.2789}],GeoPosition[{38.5854,-90.2634}],GeoPosition[{38.5836,-90.2447}]}
Which can then be mapped onto GeoGraphics :
In[]:=
GeoGraphics[{Red,Opacity[.4],AbsolutePointSize[5],Point[#]}&/@geomarkers,GeoRange->13000,GeoScaleBar->"Metric",ImageSize->Large]
Out[]=
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Mapping Crime Statistics in St. Louis
by Arnoud Buzing
Wolfram Community, STAFF PICKS, 2014
https://community.wolfram.com/groups/-/m/t/329022
by Arnoud Buzing
Wolfram Community, STAFF PICKS, 2014
https://community.wolfram.com/groups/-/m/t/329022