Script to generate the geopackage used for the Collideoscope heatmap (which originated here).
The geopackage is generated by combining road features from OS Open Road shapefiles with the points of all incidents in the Collideoscope database. Each feature in the output has a density
attribute which represents the number of incidents per metre along the feature. Only road features with >1 incident (total) are included.
The simplest way to generate the geopackage is to use the Makefile
to get you up and running quickly. Requires Docker and read-only access to the Collideoscope Postgres database.
$ export COLLIDEOSCOPE_DATABASE_URL="postgres://user:password@postgreshost:5432/collideoscope"
$ curl https://raw.githubusercontent.com/mysociety/collideoscope-heatmap/master/Makefile | make -f - heatmap
This takes an hour or so to run, and will generate heatmap.gpkg
in the current directory.
You gain more control over the behaviour of the script by invoking docker run
manually. For example if you already have OS Open Roads downloaded locally to $HOME/Downloads
and want to use that, and want the heatmap stored somewhere other than the current directory:
$ export COLLIDEOSCOPE_DATABASE_URL="postgres://user:password@postgreshost:5432/collideoscope"
$ docker run \
-e COLLIDEOSCOPE_DATABASE_URL \
-e OS_OPEN_ROADS_PATH=/input/oproad_essh_gb.zip \
-e OUTPUT_PATH=/output/collideoscope.gpkg \
-v /data/library/mapserver:/output \
-v ${HOME}/Downloads:/input \
-t davea/collideoscope-heatmap
The script uses pipenv
for virtualenv management, so install that if you haven't already. Then, run the script:
$ cat .env
COLLIDEOSCOPE_DATABASE_URL=postgres://user:password@postgreshost:5432/collideoscope
$ pipenv install
$ pipenv run python generate_heatmap.py