Playing with heatmaps

My 'hello world' heatmap

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 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 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.


  1. Dan says:


    Liked your post about from back in 2010. Any luck on getting the ability to weight the points?

  2. Alex says:

    Hi Dan, Yes, I got the weighting working (though I forget how it works now!)… take a look at:

  3. Dan says:

    GREAT! This helps out a town with the project. Thanks for the reply and great work! Assuming the integration goes well we might be able to use this on our website…

  4. Alex says:

    No worries 🙂 Let me know if you do use it in the end, I’d be interested to see.

  5. Dan says:

    We’ve been lagging on the maps, and are getting ready to move forward on those. Can you explain something to me – does this python script just generate an image file? So when users zoom in the “heat” won’t change? Or does work similar to gHeat, where users see different heat upon zooming in?

    The challenge I’m faced with is I need the ability to weight points, but don’t believe gHeat can handle that…

    Thanks again-

  6. Alex says:

    No, it just generates an image file (IIRC!) – so the HEAT doesn’t change when you zoom in/out. There’s probably too much processing to do to be able to make it generate the heat on the fly. Although one way to may be able to get it to work is to create your own tile server and have the heat preset onto each of the tile images – then it wouldn’t need to do any processing on the fly – just serving tile images, and in the you could regenerate the images with the heat however regularly you like.

Leave a Reply