Over that past few days I’ve been playing around with creating heatmaps to overlay onto OpenStreetMap – the image on the left is where I’ve got to so far. My interest in this is for creating heatmaps from data collected during my colleagues health sciences research in Ethiopia.
There are already several programs and services available to create heatmaps, for example gheat and OpenHeatMap. But none of these quite suited me, gheat because I didn’t want to create a full tile server – just an image to overlay on a particular area of the map and OpenHeatMap because I wanted to have access to the code to tweak how I wanted.
I then found heatmap.py which (using a similar algorithm to gheat) did almost exactly what I wanted. There were only a couple of changes that I needed to make:
1) Update to account for the Mercator projection – I wanted my overlay to be on a view of the whole world (zoom level 2 in OpenStreetMap). When I first ran the program the areas over northern Europe (and others) were almost but not quite inline with the marker overlays, but this was due to the projection. I just edited the input script to convert my lat/lng coordinates into Mercator coordinates. I also hooked up the heatmap.py script to read the lat/lng coordinated from a MySQL database.
2) Allow the script to have weights against each point. The current script looks at the number of points in a particular area (or on top of each other) to generate the ‘heat’. I also wanted to allow for points to have a weight – as mentioned here. I’ve not yet implemented the weighting, but I’m not anticipating this to be too tricky. GHeat (as far as I can tell) doesn’t allow for weights on points, but OpenHeatMap does (please let me know if I’m wrong about this).
All has been much easier than I’d expected, I’ve learnt a little more about python and once I’ve got the weighting working how I’d like, then I’ll share the code back.