Basic overview

The Hoyodecrimen REST API allows you to query crime data about Mexico City. You can even do fancy things like get the top 9 cuadrantes where homicide counts changed the most.

Since the API is based on REST principles and returns JSON data, it’s very easy to write applications that use it. You can use your browser to access any API URL, or pretty much any HTTP client in any programming language (yes, even something like STATA).

For example, https://hoyodecrimen.com/api/v1/crimes will return a list of all crimes in the database. https://hoyodecrimen.com/api/v1/cuadrantes will return a list of all the cuadrantes in the Federal District. Once you have a list of crimes and cuadrantes you can use https://hoyodecrimen.com/api/v1/cuadrantes/c-1.1.1/crimes/homicidio%20doloso/series to get a time series of the homicide rate in cuadrante C-1.1.1 (the API is case insensitive). Note that homicidio%20doloso can be changed to all to get all the crimes that occurred in that cuadrante.

Status

This is beta software and paths may break (but not much). If you notice an error, have any comments, or stuff you’d like added to the API raise an issue on GitHub or email me at diego [at] diegovalle.net. All crime data comes from the Mexico City open data portal

License

Data accessed via this API is provided under the Creative Commons Attribution 4.0 International License. If you use this data you must link back to https://hoyodecrimen.com/ as the origin of the data. You may also consult our privacy policy.

What’s available

Service Action URI
Point in Polygon Given a longitude and latitude return the corresponding cuadrante and sector
/api/v1/cuadrantes/pip/(string: long)/(string: lat)
/api/v1/cuadrantes/crimes/(string: crime)/pip/(string: long)/(string: lat)
/api/v1/cuadrantes/crimes/(string: crime)/pip_extra/(string: long)/(string: lat)
Latitude and Longitude Return the latitude and longitude of crimes
/api/v1/latlong/crimes/(string: crime)/coords/(string: long)/(string: lat)/distance/(integer: distance)
Time Series Crime counts ordered by month of occurrence for a cuadrante or sector
/api/v1/sectores/(string: sector)/crimes/(string: crime)/series
/api/v1/cuadrantes/(string: cuadrante)/crimes/(string: crime)/series
List Cuadrantes or Sectores Sum of crimes that occurred in a cuadrante or sector for a specified period of time
/api/v1/cuadrantes/(string: cuadrante)/crimes/(string: crime)/period
/api/v1/sectores/(string: sector)/crimes/(string: crime)/period
/api/v1/cuadrantes/(string: cuadrante)/crimes/(string: crime)/period/change
Top Most Violent A list of the cuadrantes and sectors with the highest rates (sectores), crime counts (cuadrantes) or change in crime counts (cuadrantes)
/api/v1/sectores/crimes/(string: crime)/top/rates
/api/v1/cuadrantes/crimes/(string: crime)/top/counts
/api/v1/cuadrantes/crimes/(string: crime)/top/counts/change
DF data A time series of the sum of all crimes that occurred in the Federal District
/api/v1/df/crimes/(string: crime)/series
Enumerate Get a list of the names of all cuadrantes, sectores, crimes or municipios
/api/v1/cuadrantes
/api/v1/sectores
/api/v1/crimes
/api/v1/municipios
GeoJSON Return maps as GeoJSON
/api/v1/cuadrantes/geojson
/api/v1/sectores/geojson
/api/v1/municipios/geojson
Day and Hour Return number of crimes by day and hour
/api/v1//df/crimes/(string:crime)/hours
/api/v1/df/crimes/(string:crime)/days

Getting Started

All endpoints are GET requests that send back an object filled will the relevant data. You really want to use JSONP to access the API. Here is a basic example of how to handle JSONP requests using jQuery.

$.ajax({
    dataType: 'jsonp',
    url: 'https://hoyodecrimen.com/api/v1/cuadrantes/c-1.1.1/crimes/homicidio%20doloso/series',
    success: function(data) {
        // console.debug(data)
    }
});

Handling Errors

If there is a validation error with the request, or the cuadrante or crime queried does not exist, an error object will be passed back which contains a short description of what went wrong.

Example Error Response:

$.ajax({
    dataType: 'jsonp',
    // notice the invalid start_date
    url: 'https://hoyodecrimen.com/api/v1/cuadrantes/c-1.1.1/crimes/all/series?start_date=2014-99?end_date=2014-07',
    success: function(data) {
        // console.debug(data)
    },
    error: function(xhr, error) {
        // console.debug(xhr.responseText); // error description
        // console.debug(xhr.status); //should be 400
    }
});

Note

Population is given in persons/year and corresponds to that of the 2010 census.

API Reference

GET /api/v1/cuadrantes/geojson

Returns a map of the cuadrantes delictivos encoded as geojson

Status Codes:
  • 200 OK – return a geojson map
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/geojson HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json
GET /api/v1/municipios/geojson

Returns a map of the municipios that make up the Federal District encoded as geojson

Status Codes:
  • 200 OK – return a geojson map
Response Headers:
 

Example request:

GET /api/v1/municipios/geojson HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json
GET /api/v1/sectores/geojson

Returns a map of the sectores delictivos encoded as geojson

Status Codes:
  • 200 OK – return a geojson map
Response Headers:
 

Example request:

GET /api/v1/sectores/geojson HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json
GET /api/v1/cuadrantes

Enumerate all the cuadrantes and the sectors and municipios they belong to

Status Codes:
  • 200 OK – when all the cuadrantes were found
Response Headers:
 

Example request:

GET /api/v1/cuadrantes HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"cuadrante": "P-1.1.1",
"cve_mun": "09010",
"municipio": "ALVARO OBREGON",
"sector": "ALPES"
},
...
GET /api/v1/municipios

Enumerate all municipios in the Federal District

Status Codes:
  • 200 OK – when all the municipios were found
Response Headers:
 

Example request:

GET /api/v1/municipios HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json
{
"rows": [
{
"cuadrante": "P-1.1.1",
"cve_mun": "09010",
"municipio": "ALVARO OBREGON",
"sector": "ALPES"
},
...
GET /api/v1/sectores

Enumerate all the sectores in the database

Status Codes:
  • 200 OK – when all the sectores were found
Response Headers:
 

Example request:

GET /api/v1/sectores HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"cve_mun": "09010",
"municipio": "ALVARO OBREGON",
"sector": "ALPES"
},
...
GET /api/v1/crimes

Enumerate all the crimes in the database

Status Codes:
  • 200 OK – when all the crimes were found
Response Headers:
 

Example request:

GET /api/v1/crimes HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"crime": "HOMICIDIO DOLOSO"
},
{
"crime": "ROBO A NEGOCIO C.V."
},
{
"crime": "ROBO DE VEHICULO AUTOMOTOR C.V."
}
...
GET /api/v1/latlong/crimes/(string: crime)/coords/(string: long)/(string: lat)/distance/(int: distance)

Given a latitude and longitude return all crimes within a certain distance

Returns a list containg the cuadrante polygon as GeoJSON, all the crimes that occurred in the cuadrante by date, the sum of crime counts that occurred in the whole DF during the last 12 months, and the sum of crimes in the cuadrante containing the longitude and latitude during the last 12 months

Parameters:
  • long – long
  • lat – lat
  • crime – the name of a crime or the keyword all
Query Parameters:
 
  • start_date – Start of the period from which to start aggregating in %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Status Codes:
  • 200 OK – when the cuadrante corresponding to the latitude and longitude is found
  • 400 Bad Request – when the latitude or longitude where incorrectly specified
  • 404 Not Found – when the latitude or longitude are outside of the Federal District cuadrante area or the crime requested doesn’t exist
Response Headers:
 

Example request:

GET /api/v1/latlong/crimes/all/coords/-99.13333/19.43/distance/500 HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"cuadrante": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "C-1.4.4",
"month": 1,
"population": 1405,
"sector": "CORREDOR - CENTRO",l
"year": 2013
},
...
"cuadrante_period": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"population": 16860
},
...
"df_period": [
{
"count": 823,
"crime": "HOMICIDIO DOLOSO",
"population": 8785874
},
...
"latlong": [
{
"crime": "VIOLACION",
"date": "2016-08-15",
"hour": "12:00",
"lat": 19.428935,
"long": -99.136566
},
 ...
"pip": [
{
"cuadrante": "C-1.4.4",
"geomery": "{"type":"MultiPolygon","coordinates":[[[[-99.129543,19.436234],[-99.12966,19.435347],[-99.129766,19.43449],[-99.12994,19.433287],[-99.130025,19.432576],[-99.130206,19.431322],[-99.130576,19.428702],[-99.132613,19.428972],[-99.136883,19.429561],[-99.136343,19.433343],[-99.136008,19.435295],[-99.135754,19.437014],[-99.13479,19.436886],[-99.133691,19.436745],[-99.131628,19.436484],[-99.129543,19.436234]]]]}",
"sector": "CORREDOR - CENTRO"
}
GET /api/v1/cuadrantes/crimes/(string: crime)/pip_extra/(string: long)/(string: lat)

Given a latitude and longitude determine the cuadrante they correspond to. Include extra crime info

Returns a list containg the cuadrante polygon as GeoJSON, all the crimes that occurred in the cuadrante by date, the sum of crime counts that occurred in the whole DF during the last 12 months, and the sum of crimes in the cuadrante containing the longitude and latitude and the nearest 8 cuadrantes during the last 12 months

Parameters:
  • long – long
  • lat – lat
  • crime – the name of a crime or the keyword all
Status Codes:
  • 200 OK – when the cuadrante corresponding to the latitude and longitude is found
  • 400 Bad Request – when the latitude or longitude where incorrectly specified
  • 404 Not Found – when the latitude or longitude are outside of the Federal District cuadrante area or the crime requested doesn’t exist
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/crimes/all/pip_extra/-99.13333/19.43 HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"cuadrante": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "C-1.4.4",
"month": 1,
"population": 1405,
"sector": "CORREDOR - CENTRO",l
"year": 2013
},
...
"cuadrante_period": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"population": 16860
},
...
"df_period": [
{
"count": 823,
"crime": "HOMICIDIO DOLOSO",
"population": 8785874
},
...
"latlong": [
{
"crime": "VIOLACION",
"date": "2016-08-15",
"hour": "12:00",
"lat": 19.428935,
"long": -99.136566
},
 ...
"pip": [
{
"cuadrante": "C-1.4.4",
"geomery": "{"type":"MultiPolygon","coordinates":[[[[-99.129543,19.436234],[-99.12966,19.435347],[-99.129766,19.43449],[-99.12994,19.433287],[-99.130025,19.432576],[-99.130206,19.431322],[-99.130576,19.428702],[-99.132613,19.428972],[-99.136883,19.429561],[-99.136343,19.433343],[-99.136008,19.435295],[-99.135754,19.437014],[-99.13479,19.436886],[-99.133691,19.436745],[-99.131628,19.436484],[-99.129543,19.436234]]]]}",
"sector": "CORREDOR - CENTRO"
}
GET /api/v1/cuadrantes/crimes/(string: crime)/top/counts/change

Return the top ranked cuadrantes where crime counts increased the most.

When no date parameters are specified the top 5 cuadrantes are returned for the last 3 months compared with the same period during the previous year (e.g. July-May 2018 compared with July-May 2017). All population data returned by this call is in persons/year and comes from the 2010 census

Parameters:
  • crime – the name of a crime or the keyword all
Status Codes:
  • 200 OK – when the top 5 cuadrantes are found
  • 400 Bad Request – when the one of the dates was incorrectly specified or the periods overlap
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_period1 – Start of the period from which to start counting. Together with end_period1 this will specify the first period. Formatted as %Y-%m (e.g. 2016-01)
  • end_period1 – End of the first period. Formatted as %Y-%m (e.g. 2016-01)
  • start_period2 – Start of the period from which to start counting. Together with end_period2 this will specify the second period. Formatted as %Y-%m (e.g. 2016-01)
  • end_period2 – End of the second period. Formatted as %Y-%m (e.g. 2016-01)
  • rank – Return the top X ranked cuadrantes.
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/crimes/homicidio%20doloso/top/counts/change HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "O-2.2.9",
"difference": 5,
"end_period1": "2013-07",
"end_period2": "2014-07",
"period1_count": 0,
"period2_count": 5,
"population": 43116,
"rank": 1,
"sector": "QUETZAL",
"start_period1": "2013-05",
"start_period2": "2014-05"
},
...
GET /api/v1/cuadrantes/crimes/(string: crime)/pip/(string: long)/(string: lat)

Given a latitude and longitude determine the cuadrante they correspond to. Include extra crime info

Returns a list containg the cuadrante polygon as GeoJSON, all the crimes that occurred in the cuadrante by date, the sum of crime counts that occurred in the whole DF during the last 12 months, and the sum of crimes in the cuadrante containing the longitude and latitude during the last 12 months

Parameters:
  • long – long
  • lat – lat
  • crime – the name of a crime or the keyword all
Status Codes:
  • 200 OK – when the cuadrante corresponding to the latitude and longitude is found
  • 400 Bad Request – when the latitude or longitude where incorrectly specified
  • 404 Not Found – when the latitude or longitude are outside of the Federal District cuadrante area or the crime requested doesn’t exist
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/crimes/all/pip/-99.13333/19.43 HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"cuadrante": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "C-1.4.4",
"month": 1,
"population": 1405,
"sector": "CORREDOR - CENTRO",l
"year": 2013
},
...
"cuadrante_period": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"population": 16860
},
...
"df_period": [
{
"count": 823,
"crime": "HOMICIDIO DOLOSO",
"population": 8785874
},
...
"pip": [
{
"cuadrante": "C-1.4.4",
"geomery": "{"type":"MultiPolygon","coordinates":[[[[-99.129543,19.436234],[-99.12966,19.435347],[-99.129766,19.43449],[-99.12994,19.433287],[-99.130025,19.432576],[-99.130206,19.431322],[-99.130576,19.428702],[-99.132613,19.428972],[-99.136883,19.429561],[-99.136343,19.433343],[-99.136008,19.435295],[-99.135754,19.437014],[-99.13479,19.436886],[-99.133691,19.436745],[-99.131628,19.436484],[-99.129543,19.436234]]]]}",
"sector": "CORREDOR - CENTRO"
}
GET /api/v1/cuadrantes/(string: cuadrante)/crimes/(string: crime)/period/change

Return the change in crime counts for a specified period of time at the cuadrante level

By default it returns the change during the last 12 months

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • cuadrante – the name of the cuadrante or the keyword all to return all cuadrantes
Status Codes:
  • 200 OK – when the change in crime counts is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_period1 – Start of the period from which to start counting. Together with end_period1 this will specify the first period. Formatted as %Y-%m (e.g. 2016-01)
  • end_period1 – End of the first period. Formatted as %Y-%m (e.g. 2016-01)
  • start_period2 – Start of the period from which to start counting. Together with end_period2 this will specify the second period. Formatted as %Y-%m (e.g. 2016-01)
  • end_period2 – End of the second period. Formatted as %Y-%m (e.g. 2016-01)
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/all/crimes/all/period/change HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "O-2.2.9",
"difference": 5,
"end_period1": "2013-07",
"end_period2": "2014-07",
"period1_count": 0,
"period2_count": 5,
"population": 43116,
"sector": "QUETZAL",
"start_period1": "2013-05",
"start_period2": "2014-05"
},
...
GET /api/v1/sectores/(string: sector)/crimes/(string: crime)/period/change

Return the change in crime counts for a specified period of time at the sector level

By default it returns the change during the last 12 months

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • sector – the name of the sector or the keyword all to return all sectores
Status Codes:
  • 200 OK – when the change in crime counts is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_period1 – Start of the period from which to start counting. Together with end_period1 this will specify the first period. Formatted as %Y-%m (e.g. 2016-01)
  • end_period1 – End of the first period. Formatted as %Y-%m (e.g. 2016-01)
  • start_period2 – Start of the period from which to start counting. Together with end_period2 this will specify the second period. Formatted as %Y-%m (e.g. 2016-01)
  • end_period2 – End of the second period. Formatted as %Y-%m (e.g. 2016-01)
Response Headers:
 

Example request:

GET /api/v1/sectores/all/crimes/all/period/change HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"crime": "HOMICIDIO DOLOSO",
"difference": 5,
"end_period1": "2013-07",
"end_period2": "2014-07",
"period1_count": 0,
"period2_count": 5,
"population": 43116,
"sector": "QUETZAL",
"start_period1": "2013-05",
"start_period2": "2014-05"
},
...
GET /api/v1/cuadrantes/crimes/(string: crime)/top/counts

Return the top ranked cuadrantes with the highest crime counts for a given period of time.

When no dates parameters are specified the top 5 cuadrantes for the last 12 months are returned (e.g. If July is the last date in the database, then the period July 2018 to Aug 2017 will be analyzed). All population data returned by this call is in persons/year and comes from the 2010 census

Parameters:
  • crime – the name of a crime or the keyword all
Status Codes:
  • 200 OK – when the top 5 cuadrantes are found
  • 400 Bad Request – when the one of the dates was incorrectly specified or the periods overlap
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start counting. Formatted as %Y-%m (e.g. 2016-01)
  • end_date – End of the period to analyze. Must be greater or equal to start_date. Formatted as %Y-%m (e.g. 2016-01)
  • rank – Return all cuadrantes ranked higher. Defaults to 5
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/crimes/homicidio%20doloso/top/counts HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json
{
"rows": [
{
"count": 12,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "N-2.2.1",
"end_date": "2014-07",
"population": 1833,
"rank": 1,
"sector": "CUCHILLA",
"start_date": "2013-08"
},
...
GET /api/v1/cuadrantes/(string: cuadrante)/crimes/(string: crime)/series

Return the count of crimes that occurred in a cuadrante, by date

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • cuadrante – the name of the cuadrante from which to return the time series or the keyword ``all to return all cuadrantes
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime or cuadrante is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start the series. %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/c-1.1.1/crimes/violacion/series HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "C-1.1.1",
"month": 1,
"population": 1594,
"sector": "ANGEL - ZONA ROSA",
"year": 2013
},
...
GET /api/v1/municipios/(string: municipio)/crimes/(string: crime)/series

Return the count of crimes that occurred in a municipio, by date

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • cuadrante – the name of the municipio from which to return the time series or the keyword ``all to return all municipios
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime or municipio is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start the series. %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/municipios/tlalpan/crimes/homicidio%20doloso/series
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 1,
"crime": "HOMICIDIO DOLOSO",
"cve_mun": "09012",
"date": "2016-01",
"municipio": "TLALPAN",
"population": 633181
},
...
GET /api/v1/cuadrantes/(string: cuadrante)/crimes/(string: crime)/period

Return the sum of crimes that occurred in each cuadrante for a specified period of time

By default it returns the sum of crimes during the last 12 months for all the cuadrantes in the database

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • cuadrante – the name of the cuadrante or the keyword all to return all cuadrantes
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start aggregating in %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/all/crimes/all/period HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "C-1.1.1",
"end_date": "2014-07",
"population": 1594,
"sector": "ANGEL - ZONA ROSA",
"start_date": "2013-08"
},
...
GET /api/v1/municipios/(string: municipio)/crimes/(string: crime)/period

Return the sum of crimes that occurred in each municipio for a specified period of time

By default it returns the sum of crimes during the last 12 months for all the cuadrantes in the database

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • municipio – the name of the municipio or the keyword all to return all municipios
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime or municipio is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start aggregating in %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/municipios/tlalpan/crimes/all/period HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"cuadrante": "C-1.1.1",
"end_date": "2014-07",
"population": 1594,
"sector": "ANGEL - ZONA ROSA",
"start_date": "2013-08"
},
...
GET /api/v1/sectores/crimes/(string: crime)/top/rates

Return the top ranked sectors with the highest crime rates for a given period of time.

When no date parameters are specified the top 5 cuadrantes are returned for the last 12 months (e.g. If July is the last date in the database then the period July 2018 to Aug 2017 will be analyzed). Crimes where no sector was specified (NO ESPECIFICADO) are ignored. All population data returned by this call is in persons/year and comes from the 2010 census

Parameters:
  • crime – the name of a crime or the keyword all
Status Codes:
  • 200 OK – when the top 5 cuadrantes are found
  • 400 Bad Request – when the one of the dates was incorrectly specified or the periods overlap
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start counting. Formatted as %Y-%m (e.g. 2016-01)
  • end_date – End of the period to analyze. Must be greater or equal to start_date. Formatted as %Y-%m (e.g. 2016-01)
  • rank – Return all sectores with a rate ranked higher. Defaults to 5
Response Headers:
 

Example request:

GET /api/v1/sectores/crimes/homicidio%20doloso/top/rates HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 22,
"crime": "HOMICIDIO DOLOSO",
"end_date": "2014-07",
"population": 33787,
"rank": 1,
"rate": 65.1,
"sector": "CONGRESO",
"start_date": "2013-08"
},
...
GET /api/v1/sectores/(string: sector)/crimes/(string: crime)/series

Return the count of crimes that occurred in a sector, by date

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • cuadrante – the name of the cuadrante from which to return the time series or the keyword ``all to return all sectores
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime or cuadrante is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start the series. %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/sectores/angel%20-%20zona%20rosa/crimes/violacion/series HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 0,
"crime": "HOMICIDIO DOLOSO",
"month": 1,
"population": 25606,
"sector": "ANGEL - ZONA ROSA",
"year": 2013
},
...
GET /api/v1/sectores/(string: sector)/crimes/(string: crime)/period

Return the sum of crimes that occurred in a particular or in all sectores for a specified period of time

By default it returns the sum of crimes during the last 12 months for all the sectores in the database

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
  • sector – the name of the sector or the keyword all to return all sectores
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start aggregating in %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/sectores/all/crimes/all/period HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 26,
"crime": "HOMICIDIO DOLOSO",
"end_date": "2014-07",
"population": 171047,
"sector": "ABASTO-REFORMA",
"start_date": "2013-08"
},
...
GET /api/v1/cuadrantes/pip/(string: long)/(string: lat)

Given a latitude and longitude determine the cuadrante they correspond to.

Parameters:
  • long – longitude
  • lat – longitude
Status Codes:
  • 200 OK – when the cuadrante corresponding to the latitude and longitude is found
  • 400 Bad Request – when the latitude or longitude where incorrectly specified
  • 404 Not Found – when the latitude or longitude are outside of the Federal District cuadrante area
Response Headers:
 

Example request:

GET /api/v1/cuadrantes/pip/-99.13333/19.43 HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response:

HTTP/1.1 200 OK
Vary: Accept
Content-Type: application/json

{
  "pip":
    [
      {
        "cuadrante": "C-1.4.4",
        "geomery": "{"type":"MultiPolygon","coordinates":[[[[-99.129543,19.436234],[-99.12966,19.435347],[-99.129766,19.43449],[-99.12994,19.433287],[-99.130025,19.432576],[-99.130206,19.431322],[-99.130576,19.428702],[-99.132613,19.428972],[-99.136883,19.429561],[-99.136343,19.433343],[-99.136008,19.435295],[-99.135754,19.437014],[-99.13479,19.436886],[-99.133691,19.436745],[-99.131628,19.436484],[-99.129543,19.436234]]]]}",
        "sector": "CORREDOR - CENTRO"
      }
    ]
}
GET /api/v1/df/crimes/(string: crime)/series

Return the sum of crimes that occurred in the Federal District

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start the series. %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/df/crimes/violacion/series HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 64,
"crime": "VIOLACION",
"month": 1,
"population": 8785874,
"year": 2013
},
...
GET /api/v1/df/crimes/(string: crime)/hours

Return the number of crimes by hour

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start aggregating in %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/df/crimes/ALL/hours HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 206,
"crime": "HOMICIDIO DOLOSO",
"end_date": "2016-09",
"hour": "00",
"start_date": "2015-10"
},
{
"count": 231,
"crime": "HOMICIDIO DOLOSO",
"end_date": "2016-09",
"hour": "01",
"start_date": "2015-10"
},

GET /api/v1/df/crimes/(string: crime)/days

Return the number of crimes by day

Parameters:
  • crime – the name of crime or the keyword all to return all crimes
Status Codes:
  • 200 OK – when the sum of all crimes is found
  • 404 Not Found – when the crime is not found in the database
Query Parameters:
 
  • start_date – Start of the period from which to start aggregating in %Y-%m format (e.g. 2016-01)
  • end_date – End of the period to analyze in %Y-%m format (e.g. 2016-06). Must be greater or equal to start_date
Response Headers:
 

Example request:

GET /api/v1/df/crimes/ALL/hours HTTP/1.1
Host: hoyodecrimen.com
Accept: application/json

Example response (truncated):

HTTP/1.1 200 OK
Content-Type: application/json

{
"rows": [
{
"count": 201,
"crime": "HOMICIDIO DOLOSO",
"dow": 0,
"end_date": "2016-09",
"start_date": "2015-10"
},
{
"count": 148,
"crime": "HOMICIDIO DOLOSO",
"dow": 1,
"end_date": "2016-09",
"start_date": "2015-10"
},