I've been playing around with the heatmap plugin for QGIS and I am wondering if it is possible to make heatmap with using a similar plugin/tool that uses polygons as well as points?

I would like to get a representation of the density of the data in much the same way that the heatmap plugin does with points.

The following image is a rough sketch of my desired result:

enter image description here

  • 3
    Have you thought about generating centroids for your polygons, and building the heatmap from those?
    – andytilia
    Commented Nov 16, 2012 at 16:56
  • 1
    Some more details about your data would help. What do the polygons represent, and how are they distributed? Can you post a sample pic?
    – andytilia
    Commented Nov 16, 2012 at 16:58
  • @andytilia: Centroids don't accurately represent the coverage of the polygons. The polygons represent resource use within a 1200m2 area. Some polygons are tiny representing a good berry patch and others are huge covering the habitats of caribou and moose. I've been looking into binning a hexagonal grid and then counting overlaps... but I'm pretty much a noob so I haven't been able find a good tutorial that I can understand on that subject.
    – NWT Adam
    Commented Nov 16, 2012 at 20:00
  • 1
    see QGIS heatmap plugin qgis.spatialthoughts.com/2012/07/…
    – rkm
    Commented Nov 20, 2012 at 17:37
  • Do the numeric values carry any meaning for you or are you just looking for a pretty/clear visualisation?
    – underdark
    Commented Nov 23, 2012 at 19:26

6 Answers 6


If I understand your question correctly I have done something similar before; just had to remember what I did.

This will work if your polys are overlapping AND not the same layer. If they are on the same layer and it it is possible, move them to seperate layers, if you don't the target layer will just inherit one of the values.

The key process to use is the Join attributes by location under the Vector > Data Mangement menu. Here specify your hexagonal field as the target layer and the join layer as one of your polygons. Name your resulting layer and tick the radio button for Keep All Records.

The resulting layer should be a copy of your hexgonal layer with all the cells that intersected your polygon layer. Now for the interation use your last resulting layer as the target layer and join the next polygon layer. Take the resulting lasyer and join your next layer until you have join all your layers.

Your final layer should have inherited all the attribute fields of the previous layers and much of it may say NULL.

This is where we have to play in some of the guts of a shapefile, so if you havn't saved the layer as a shapefile do so now. And remove the layer from your workspace in QGIS.

Open the shapefile's *.dbf files in OpenOffice Calc, DO NOT use Excel. It will mangle the file and it useless, learned that the hard way. And do not reorder the data, it is very specific on the order of rows in the file as well. Check to make sure the NULLs now are Zeros if they are not, replace them carefully.

Now insert the shapefile into QGIS and open the Attribute Table. It should now show zeros instead of NULL. Use the Field Calculator and sum the fields that are realted to your work in a new column.

Now you have a summed field that should show with a degree of accuracy the values of the all the feature collections overlaping the target field. You can use the Symbology function to color your polygons based upon the value of your summed field for a nice choropleth map.

If you want to rid of all the unused field in the file. Just open the dbf file again in Calc and delete the unwanted columns at will. Personally, I'd advise learning to get comfortable going into a shapefile this way as I do it often.

  • Unfortunately, I've got hundreds of polygons overlapping with in the same layer. Can you see a way to around this without separating these out in to a few hundred layers?
    – NWT Adam
    Commented Nov 22, 2012 at 5:24
  • 1
    You can create a polygon overlay with PostGIS (if you use it) which breaks up your overlapping polys. gis.stackexchange.com/questions/83/… Prehaps someone with better SQL-fu can help us here and how to get the resulting polys to inherit their values, I am not too good at it.
    – RomaH
    Commented Nov 23, 2012 at 15:10
  • 1
    Another option, one I would suggest strongly too, is maybe it is time to rethink your exact approach to your problem. What data are you trying to map? Is there a reason to assume the value would be homogenous throughout the polygons? Would overlapping polygon actually have an accumulative effects? Unless you have good evidence to suggest these things the use of this map for any kind of predictive modeling might be on shaky ground. Just think hard about, you might have the correct solution but you might discover a better way to model or map it.
    – RomaH
    Commented Nov 23, 2012 at 15:22
  • 1
    Thanks for the PostGIS suggestion. I'll have a look at it but I am just getting to know how to use PostGIS. As for reassessing the question... I see what you mean but I am not sure how else I could visualise what we are trying to express. Our data represents all of the areas that the community elders and resource users map as productive or important from a cultural perspective. We understand that the value map not be homogeneous throughout the polygon but it's close enough for the point that we want to express with the map.
    – NWT Adam
    Commented Nov 23, 2012 at 16:54
  • 1
    Thumbs down to anything manual in qgis -- especially once you starting dealing with //tons// of shapefiles, you could end up in a really frustrating position. You will not regret using your SQL-fu, be it with postGIS plugin or GRASS plugin (see my answer below: gis.stackexchange.com/a/42188/7689).
    – egbutter
    Commented Nov 27, 2012 at 18:18

Maybe you can generate a set of random points into your polygons, there is a QGIS tool for that ? If you have overlapping polygons, then you have higher density of them in this area. Then use heatmap for the points. You would need to run several rounds to find optimal number of points, as result depends on that.

If your data shows distribution of some habitats, which is fuzzy anyway, then this could be closest to the real world situation where one point reflects approximately one specimen.

  • 1
    +1 Great idea. Only thing I would add is to Join at Location with the point data and hexagonal polys, get rid of any non-matching features and then generate points in that, so your single points wouldn't get drowned-out among all the other points.
    – RomaH
    Commented Nov 26, 2012 at 13:42
  • This seems to give the best looking result. Thanks to all the people that offered solutions. I kind of feel bad giving the bounty to just one person as there seems to be a number of good solutions!
    – NWT Adam
    Commented Nov 27, 2012 at 6:27

This is a general workflow using rasters. I don't know the specifics to accomplish it in QGIS.

  1. Use intersection tool to create a new vector layer of the areas of polygon overlap
  2. Convert your vector layers, including the overlap layer, to rasters
  3. Use raster arithmetic (probably addition) to combine the rasters
  4. Result should be a raster that looks like a heatmap

Alpha/null values and/or layer transparency would allow you to overlay the raster on any basemap.

  • After going through this work flow I am left with a large grey block covering the extent of the new raster. How do I get this to look like a heat map?
    – NWT Adam
    Commented Nov 20, 2012 at 21:42
  • 1
    Are there different values assigned to the pixels in the final raster? A few thoughts: You may have to specify a finer resolution (more pixels) when creating the rasters; the rasters should be the same size and resolution; you may need to stretch or modify the resultant raster's colormap to show brighter colors for larger values.
    – user3461
    Commented Nov 20, 2012 at 22:33
  • Okay I got the colour map set up but I'm only get getting two colours blue (value 0) and red value (2) the red value covers the area of my vector original layers and my overlap layer. I am guessing that the layers each got given a value of 1 rather than each polygon when they were rasterised. Then when the rasters were added the total value equalled 2. How do get the values to be maintained/added at the polygon level rather than the layer level?
    – NWT Adam
    Commented Nov 20, 2012 at 22:52
  • the finer resolution raster should help
    – user3461
    Commented Nov 21, 2012 at 0:19
  • How do I make a finer resolution raster?
    – NWT Adam
    Commented Nov 21, 2012 at 2:14

Try this instead, if it fits your requirements, it isn't a computational solution to the dataset but if you are looking for simply an infographic solution you could try this instead.

Join attributes by location, with your heaxgonal cells as as the target and your point data as the join. Choose to keep all features. Set the symbology to the cells with the inherited value to desired color and set transparency to the something like 50%.

Then on your layer with the circle polys set their symbology to the same color and transparency. Place the circle poly in front of the cell poly. This will give the illusion of increased saturation as the value increases.

If you wish you could also extract the lines of the all the polys and overlay on top so sublayer outlines don't appear to be coloured over by the other layers.

You will have to play with the colours and transparency to find the best solution. I find the same colours looks best but experiement.


I suggest you use the GRASS plugin -- QGIS has pretty limited functionality (and why reinvent the wheel in python when software like GRASS already exists?):


[next two lines might be necessary, depending on whether your polygons already have a value]


this is where we add up the overlap in the polygons then make the raster based on those columns

v.to.db ... qcolumns=sum(col_with_polygon_value)

v.out.ogr [r.out.ogr]

With plain QGIS it could be tricky, you may need custom scripting, or use spatial database like PostGIS or Spatialite. I would create regular grid of points with PostGIS or generate as CSV text file and import this. Then draw circle around each point with st_buffer, or rectangules with ST_MakeEnvelope, and count all overlapping areas of each buffer. Then you probably want to remove all 0 values, if it means "no data". Finally you can do heatmap for the grid, using counter as Weight field.

You need to experiment with different grid resolutions to find optimal one. In essence it is very similar to the raster approach suggested by Kevin, just staying in vector world.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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