4

I'm using QGIS 3 and trying to create a heat map using GPS data acquired during various trips. I want the resulting heatmap to clearly show each location acquired at least once with some radius (such as 10m) with green, gradually transitioning to red for the most frequently visited locations. But I'm having an issue that the most visited places have so many instances (I don't know how many but it could be hundreds or thousands) that most of the positions are invisible. I have tried setting the first gradient stop to the minimum it will let me enter (0.1%) and still a lot of my positions are invisible and a large percentage are a very faint green, despite setting the 0.1% value to 100% brightness green, and only a single bright red dot suggesting that there is one location that has been visited much more than all the others.

I would like to set the color ramp gradient so that I use black for 0 instances, light green for 1 instance, and then run the gradient up to red for 100%. Ideally I would like to set a second stop near the top of the range so it would scale linearly in the low count range and then show anything way above that in a different color. Then I am using addition to add the color to the map background. Even better I think would be to set transparent for 0 and a color gradient for non-zero. But I don't see a way to set a discrete stop so that I can distinguish between 0 and non-zero.

I saw this question but these seem to be talking about a different type of data set (maybe where each position has a count attached to it?) whereas in my case I just have GPS position reports which could be very close but not identical (for instance, two positions 1m apart would count close to being the same since they are within 10m). Also, the data set grows over time so setting the gradient stop to a fixed percent (which won't work anyway since I can't go below 0.1%) won't work either as it would have to be manually calculated and decreased each time.

1 Answer 1

4

Basic idea

Create an attribute that counts the no. of nearby points, than scale these values exponentially to reduce the range between min/max values so that you can set gradient stops properly. Be aware of the colors you use and reflet if the heatmap you create can be understood and interpreted in an appropriate way (details below).

How you can solve the issue

  1. Create an attribute value count to your point layer using Field calculator that counts how many points are within a radius of 10 m to each point. Use this expression:

    array_length( overlay_nearest( @layer,$id,max_distance:=10, limit:=1000))
    
  2. Inspect the range of values you get for the field created and than reduce this range, scaling the values exponentially using again Field calculator with the function scale_exp (see documentation for information how to use it) to creae a field scaled. You could e.g. reduce an input range from 0 to 6734 to an output range from 1 to 10 with this expression: scale_exp("count", 0,6734,1,10,2) - the no. 2 at the end is the exponent and can be freely chosen (read the help, linked above, for details).

    For large discrepancies between numbers (in most places, there are just a few points within 10m, in a few places a very high number), best use a small value, like 0.1.

  3. Now apply the heatmap renderer and set the Weight points by field to the scaled attribute created before. Now you can easily set the gradient stops as you like. Also use the the Maximum value setting of the heatmap renderer.

Points with an initial range of 0 to 6734 (max value, see red arrow next to no. 2, min. value next to no. 3). These values are scaled exponentially to arange of 1 to 10: this scaled value is used for the heatmap. You see 0 values (e.g. no 1) set to transparent: enter image description here


What to be aware of

  • Green to red color ramps are considered bad style in cartography due to color blindness issues. See especially Colorbrewer for evaluating the robustness of individual color schemes and Vischeck (simulates colorblind vision), but also these sites for more information: Red … Green … What?, How to Use Color Blind Friendly Palettes to Make Your Charts Accessible and many more.
  • When visualizing your points in this way, the optical impression might not reveal the real meaning of the colors. It's not intuitive and might be misleading. Heatmaps can look great, but can be tricky to understand appropriately. So really reflect what you want to do, how you want to inform those reading the map what the colors actually mean - and if there is not a better option for your task.
1
  • 1
    I hadn't thought of setting a maximum value... setting it to 256 with transparency for < 0.1% gets most of the way there. Thanks!
    – Michael
    Dec 27, 2021 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.