Donate using PayPal

CycleStreets API (v2)

  • Details for:
  • API overview
  • Obtain API key
  • Usage policy
  • Uptime policy

Collisions data

This API call provides information on collisions based on STATS19 data.

This includes all data from 1999 to 2021 inclusive. Please let us know if you have a use-case for earlier data.

An example usage of this API can be seen on the Bikedata website.

Currently, for filtering by type of road user, it can filter only for locations where the casualty(ies) include a cyclist(s), but further development is pending to generalise this.

You can also retrieve details of an individual collision using collisions.location API call.

Example

Example which retrieves collisions near the Catholic Church junction, Cambridge, requesting friendly datetime strings, including random jitter.

(In this example, a limit of only 3 locations has been set, to avoid a long example on this page, but normally a limit of 400 would be appropriate for web viewing.)

https://api.cyclestreets.net/v2/collisions.locations?bbox=0.1252,52.1979,0.1302,52.1999&casualtiesinclude=cyclist&limit=3&datetime=friendly&jitter=1&zoom=17
https://api.cyclestreets.net/v2/collisions.locations?boundary=[[0.126659,52.199417],[0.127463,52.199759],[0.127860,52.199174],[0.127211,52.198710],[0.126659,52.199417]]&casualtiesinclude=cyclist&limit=3&datetime=friendly&jitter=1&zoom=17

Result:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "id": "2013353084513",
                "datetime": "6:55pm, 4th October 2013",
                "severity": "serious",
                "casualties": "Cyclist",
                "number_of_casualties": "2",
                "number_of_vehicles": "2",
                "url": "https://www.cyclestreets.net/collisions/reports/2013353084513/",
                "apiUrl": "https://api.cyclestreets.net/v2/collisions.location?id=2013353084513",
                "latitude": "52.199108",
                "longitude": "0.127413"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    0.12741219,
                    52.19910810
                ]
            }
        },
        {
            "type": "Feature",
            "properties": {
                "id": "2012350237312",
                "datetime": "9:00am, 25th May 2012",
                "severity": "serious",
                "casualties": "Cyclist",
                "number_of_casualties": "1",
                "number_of_vehicles": "2",
                "url": "https://www.cyclestreets.net/collisions/reports/2012350237312/",
                "apiUrl": "https://api.cyclestreets.net/v2/collisions.location?id=2012350237312",
                "latitude": "52.198328",
                "longitude": "0.125765"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    0.12576501,
                    52.19832810
                ]
            }
        },
        {
            "type": "Feature",
            "properties": {
                "id": "2013353071213",
                "datetime": "12:25pm, 30th September 2013",
                "severity": "slight",
                "casualties": "Cyclist",
                "number_of_casualties": "1",
                "number_of_vehicles": "2",
                "url": "https://www.cyclestreets.net/collisions/reports/2013353071213/",
                "apiUrl": "https://api.cyclestreets.net/v2/collisions.location?id=2013353071213",
                "latitude": "52.199816",
                "longitude": "0.128032"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    0.12803217,
                    52.19981589
                ]
            }
        }
    ]
}

Request parameters - required

bbox csv string of longitude/latitudes: w,s,e,n
A bounding box string as w,s,e,n in which the locations must reside. Locations will be spread evenly around this bounding box (except if a zoom is supplied and the zoom is at least 17, in which case no such geographical filtering will be applied).
boundary GeoJSON fragment string, as [[lon1,lat1],[lon2,lat2],…,[lon1,lat1]]

A boundary string as geojson-style polygonal coordinates of longitude,latitude that encloses the results.

If the limit is not sufficient to cover all, the order of results will be the most severe casualties then most recent year; the ordering may change in future to match the behaviour of bbox.

The bbox and boundary parameters are mutually exclusive.

Request parameters - optional

casualtiesinclude string: cyclist
Limits collisions to those where the casualty(ies) include the specified type of road user. Currently the only supported value is 'cyclist'. (In future this is likely to be expanded to other values, possibly also as a comma-separated list.)
field:<fieldname> string/number

Filter to fields in the data, e.g. field:Location_Easting_OSGR=369779 would add this as a search constraint. This is useful for advanced search interfaces.

If values are comma-separated, they will be treated as an OR list. E.g. field:severity=slight,serious would match collisions whose severity is either slight or serious. As another example, casualties=Cyclist,Pedestrian would match a casualty list 'Car occupant,Goods vehicle occupant,Pedestrian' because at least one of the OR values is present in that list.

Fieldnames match those shown in the 'accident' part of the collisions.location API call output, or via the collisions.metadata API call.

since date
Earliest date for collisions, as YYYY-MM-DD, e.g. 2015-01-01.
until date
Latest date for collisions, as YYYY-MM-DD, e.g. 2019-06-31.
fields string, comma-separated list of fields from the list below

Controls what information is returned; the fields id is included by default, and longitude and latitude are in the GeoJSON geometry properties.

Available fields, all of which will be returned by default, are:

  • id STATS19 unique identifier for the collision
  • datetime Datetime as a Unixtime timestamp; NB the format can be changed using the datetime parameter (see below)
  • severity Severity (will be either fatal/serious/slight)
  • casualties Comma-separated list of casualties
  • url URL of details on CycleStreets website
  • number_of_casualties Number of casualties
  • number_of_vehicles Number of vehicles involved
limit int, default 400, max 2000
Maximum number of locations returned. It is strongly recommended to use this parameter. A value of 400 is recommended for desktop apps.
page int, min 0
When using format=flat and limit=…, this enables pagination of results.
zoom int (number between 1 and 19)
The map zoom level; this is used (i) by bbox to indicate when the map is close to the ground (17 or above) to avoid spread filtering at close levels; and (ii) by jitter if required.
jitter (recommended) 1|0, default 0

Whether to apply tiny random jitter of a few metres (±3m max in each of N/S and E/W directions) to all points when at close zoom levels (17 or above), to deal with the problem of overlapping points given the limitations of OS northings/eastings grid resolution which is especially problematic at larger junctions with many collisions. Randomisation only affects the GeoJSON geometry values and not the latitude/longitude in the feature properties. This feature requires that zoom is also supplied.

Randomisation is currently generated each time rather than persistent between requests; we hope to change this in future. Also, this feature applies jitter even when points are not overlapping; again, we hope to fix this in future.

format string, default geojson

Sets the output format. Not normally required except in the use-case of requiring an export. The appropriate HTTP headers will be sent. Available values are:

  • geojson: GeoJSON output (see example) (default)
  • flat: Flat-structured JSON. This can be more useful if the data is to be loaded into an HTML table for display.
  • csv: CSV text. If set to this, the specified fields order will be respected.
datetime string

If specified, the datetime field (if requested in the fields list) will be converted from unixtime (the default output format) to a formatted version; the available output formats are:

  • friendly A friendly format suitable for showing on a webpage, e.g. '6:55pm, 4th October 2013'; this is equivalent to date ('g:ia, jS F Y', $date) in PHP
  • friendlydate A friendly date format suitable for showing on a webpage, e.g. '4th October, 2013'; this is equivalent to date ('jS F, Y', $date) in PHP
  • sqldatetime SQL DATETIME format (i.e. simplified ISO 8601 format): YYYY-MM-DD HH:MM:SS
  • unixtime Unixtime (the default)

Response

GeoJSON feature list as per example above. Geometry types will always be Point.

(See GeoJSON example above.)

If using format=float, the structure will be flat JSON, with a pagination block and heading labels, to enable a full interface to be created:

{
    "pagination": {
        "page": 1,
        "totalPages": 34,
        "totalAvailable": 102
    },
    "labels": {
        "id": "Accident Index",
        "accyr": "Year",
        "casualties": "Casualties",
        […]
    },
    "data": {
        "2013353084513": {
            "id": "2013353084513",
            "datetime": "6:55pm, 4th October 2013",
            "severity": "serious",
            "casualties": "Cyclist",
            "number_of_casualties": "2",
            "number_of_vehicles": "2",
            "url": "https://www.cyclestreets.net/collisions/reports/2013353084513/",
            "apiUrl": "https://api.cyclestreets.net/v2/collisions.location?id=2013353084513",
            "latitude": "52.199108",
            "longitude": "0.127413"
        },
        "2012350237312": {
            "id": "2012350237312",
            "datetime": "9:00am, 25th May 2012",
            "severity": "serious",
            "casualties": "Cyclist",
            "number_of_casualties": "1",
            "number_of_vehicles": "2",
            "url": "https://www.cyclestreets.net/collisions/reports/2012350237312/",
            "apiUrl": "https://api.cyclestreets.net/v2/collisions.location?id=2012350237312"
            "latitude": "52.198328",
            "longitude": "0.125765"
        },
        […]
    }
}

Error response

JSON object containing an error key and a text string.

Example errors (text string will vary):

{
    "error": "Neither a bbox nor a detailed boundary have been supplied."
}
{
    "error": "Jittering has been enabled but no zoom has been supplied."
}

We welcome your feedback, especially to report bugs or give us route feedback.

My comments relate to: *






Your comments: *
URL of page: * https://edinburgh.cyclestreets.net/api/v2/collisions.locations/
How did you find out about CycleStreets?:
Your name:
Our ref: Please leave blank - anti-spam measure

* Items marked with an asterisk [*] are required fields and must be fully completed.