Function Repository Resource:

UKCrimeData

Source Notebook

Look up recent crimes recorded by the UK police

Contributed by: Jon McLoone

ResourceFunction["UKCrimeData"][loc]

finds crimes reported in the previous month within 1 mile of GeoLocation loc.

ResourceFunction["UKCrimeData"][{p1,p2,]

finds crimes reported in the previous month within the polygon bounded by pi.

ResourceFunction["UKCrimeData"][loc,type]

finds crimes of a specific type.

ResourceFunction["UKCrimeData"][loc,type,date]

finds crimes of a specific type recorded in the month containing date.

Details and Options

ResourceFunction["UKCrimeData"] supports the following options:
GeoRangeAutomaticrange to search around the geo location. Ignored if a polygon is specified. Automatic searches a 1 mile radius
"CrimeType""All crime"type of crime to search for
The supported crime types are: "All crime", "Anti-social behaviour", "Bicycle theft", "Burglary", "Criminal damage and arson", "Drugs", "Other theft", "Possession of weapons", "Public order", "Robbery", "Shoplifting", "Theft from the person", "Vehicle crime", "Violence and sexual offences" and "Other crime".

Examples

Basic Examples (2) 

Find crimes recorded in the previous month in Oxford:

In[1]:=
ResourceFunction["UKCrimeData"][
 Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}]]
Out[1]=

Show their locations:

In[2]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}]][GeoListPlot, "Location"]
Out[2]=

View the distribution of types:

In[3]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}]][Counts, "Crime"]
Out[3]=

View only the recorded incidences of Shoplifting:

In[4]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], "CrimeType" -> "Shoplifting"][GeoListPlot, "Location"]
Out[4]=

View crimes in the month of August 2021:

In[5]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], DateObject[{2021, 8, 1}]][GeoListPlot, "Location"]
Out[5]=

Scope (4) 

Locations can be given using GeoPosition:

In[6]:=
ResourceFunction["UKCrimeData"][GeoPosition[{51.75222, -1.25596}], "CrimeType" -> "Bicycle theft"] // Length
Out[6]=

Or using an entity:

In[7]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], "CrimeType" -> "Bicycle theft"] // Length
Out[7]=

Or a UK Postcode:

In[8]:=
ResourceFunction["UKCrimeData"]["OX29 8RY", "CrimeType" -> "Bicycle theft"] // Length
Out[8]=

Or with a polygon of GeoPosition values:

In[9]:=
ResourceFunction["UKCrimeData"][{
   GeoPosition[{51.75, -1.25}],
   GeoPosition[{51.5, -1.25}],
   GeoPosition[{51.5, -1.3}],
   GeoPosition[{51.75, -1.3}]
   }, "CrimeType" -> "Bicycle theft"] // Length
Out[9]=

Options (2) 

When using a single GeoLocation crimes within 1 mile are found:

In[10]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}]][GeoListPlot, "Location"]
Out[10]=

You can control this range with GeoRange:

In[11]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], GeoRange -> Quantity[2, "Miles"]][GeoListPlot, "Location"]
Out[11]=

You can limit the types of crime to be returned with "CrimeType":

In[12]:=
ResourceFunction["UKCrimeData"][
  Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], GeoRange -> Quantity[2, "Miles"], "CrimeType" -> "Bicycle theft"][GeoListPlot, "Location"]
Out[12]=

Possible Issues (1) 

The UK Police API will not return more than 10,000 crimes in a single request:

In[13]:=
ResourceFunction["UKCrimeData"][
 Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], GeoRange -> Quantity[200, "Miles"]]
Out[13]=

Publisher

Jon McLoone

Version History

  • 1.0.1 – 26 April 2022
  • 1.0.0 – 18 January 2022

Source Metadata

Related Resources

License Information