• Blog posts


    by David Crowther



    Using GeoServer is it possible to create HeatMaps


    Yes, utilising the power of Style Layer Descriptors (SLDs) you can publish individual Point Geometry as HeatMaps by Transforming Vector geometry into Raster Images.


    Firstly, in GeoServer you will need to setup a DATA SOURCE connection to your source data and then publish that as a WMS layer. Here I am publishing a Crime Table from my PostGIS database and applying the generic Point STYLE.


    In a previous FAQ I explored how to create Staked Points to cluster the Crime Points to show High locations of Crime.


    This is a high impact WMS layer, however it would be really great to show these Crime Locations as Hotspots using a Heatmap – something commonly done within desktop GIS.

    After doing a little research I found a link on Stack Exchange with the sample SLD code that would create a Heatmap where individual Points are clustered together – https://docs.geoserver.org/latest/en/user/styling/sld/extensions/rendering-transform.html

    At its core this SLD performs a Render Transformation to aggregate input Vector data to generate a Raster output image. Other Transformations include:


    The online resource suggested that I would need to install a WPS extension…. Although I simply copied the SLD provided without needing to install the extension in my GeoServer and it worked for me!... the steps to do this are outlined below.

    In my GeoServer Instance I created a New Style FileLiverpool Crime Heatmap


    .. and copied in the sample SLD code from the Stack Exchange link.


    Once I then applied the new SLD file to my WMS layer, I was then able to show a Heatmap for my Crime data…


    … this was very exciting as it was the first time I had been able to create a Heatmap WMS from underlying point data.

    Looking at the SLD in more detail at its heart it performs a Transformation to use the underlying Vector dataset (Crimes) to create a Raster Image.


    It then has a Rule that uses a Raster Symbolizer to then Colour each pixel that has a value – Yellow, Red and Blue. In addition, the top two Colour Map Entries find pixels that are 0.02 or 0 and applies a white colour with full OPACITY.


    NB: Without these Colour Map Entries you will colour all Raster Pixels with a colour which will mask the whole image.


    Keeping all Colour Map Entries in and applying the SLD then Transforms the Crime Points into a Raster Heatmap, with the three colours applied and the low/no crime areas opaque.



    Feeling confident I then started to tinker a little!

    The changes I wanted to make included:

    • Swapping the Red and Yellow Ranges to show areas of highest crime with the Red colour
    • Adding in two extra bands with an Amber and a Green Colour
    • Editing the Legend to apply better textual values to explain the banding

    1 - Swapping the Red and Yellow colours simply involved changing the HEX Colour for the bottom two bands.



    2 - Adding the Amber and Green Bands was a simple Copy and Paste to create two new bands and then edit each band with the Orange and Green Colour Hex values.



    3 – I then edited the SLD to rename the Legend Values to replace the words ‘Values’ with High Crime or Low Crime. In addition, I removed the 0.02 band so that the legend looked a little clearer when shown in a Client application e.g. desktop GIS (QGIS) and webGIS (MapThat).



    Finally, I used this new Crime Heatmaps WMS within my client webGIS – MapThat – to create a high impact Crime Hotspot Map for my Users.


    As you zoom in the SLD then recalculates the Heatmap on the fly



    .. and now shown with the Crime Stacked Points WMS we have two high impact WMS Layers allowing our Users to better interpret Crime Patterns across the whole area.