An interactive web map of the New Zealand Transport Agency's Crash Analysis System (CAS) data, representing all accidents that have been attended by police, given a location, and that we have chosen to present (based on currency).
Made with Python (to read the raw CSVs and produce a nice GeoJSON with useful filters and attributes to build the popups) and Leaflet (to display the GeoJSON on the map).
- Chris Hewitt (NZTA), for early feedback and a "go ahead"
- Tom Pettit (Wellington City Council; New Zealand Centre for Sustainable Cities) for support and feedback
- The NZTA, for publishing this data in a largely machine-readable format
- Harkanwal Singh, the New Zealand Herald Data Editor, for featuring the map.
Please, feel absolutely free. The data is open, and so is this. Get the map working on your local computer with the following terminal commands:
cd /path/to/directory/
git clone https://github.com/alpha-beta-soup/national-crash-statistics
If you have Python2, then run
python -m SimpleHTTPServer 8000
If you have Python3:
python3 -m http.server 8000
The navigate to http://localhost:8000/ in your browser to have a look at the map. This is how you can preview any changes you make.
cd /tmp/
git clone https://github.com/jswhit/pyproj.git
cd pyproj
python setup.py build
sudo python setup.py install
cd /tmp/
wget https://pypi.python.org/packages/source/g/geojson/geojson-1.0.9.tar.gz#md5=94880d993dba8b184de122c5a84fa329
gunzip geojson-1.0.9.tar.gz | tar -xopf geojson-1.0.9.tar
cd geojson-1.0.9
python setup.py build
sudo python setup.py install
The basic structure is as follows:
nzta2geojson.py
creates the filedata.geojson
that represents the location of each crash. Its properties are what the filters look for (e.g.alcohol = true
will give you all accidents where alcohol was a listed "role or factor" in the accident). The Python script is what performs these checks, once, before writing the output. This is executed withcd source/ && python nzta2geojson.py
.nzta-crash-analysis.js
is the Javascript script that creates the Leaflet map and uses JQuery for the filtering proceedure.index.html
andnzta-crash-analysis.css
represent the structure of the webpage and the styling of the various elements.
There is no database, just a static file. We know that's not ideal, and are looking to scale up in the future (perhaps you can help out). When we do, we'll be able to present all 14 years' of data that is available to the public, as opposed to the 7 months' worth we show now.
Other ways to help out include designing (or re-designing if you're angry) the icons that appear in the pop-ups, or giving us feedback on what does and doesn't work so well.
We'd also love to make some interactive charts of the information, because a map doesn't even reveal the most interesting patterns that undoubtedly exist in a dataset of this nature.