I want to perform a line density analysis for my line data, based on an attribute.

The heatmap option (kernel density analysis) seems to be only possible for point data.

I have tried to convert my line data into points, and create a heatmap, but the attributes for the weight were lost on the conversion.

This is a line density analysis performed with ArcGIS. I was looking to do the same with QGIS.

enter image description here

Is it possible to perform a similar line density analysis in QGIS? and this is the data on QGIS


I can't find a way to do this in QGIS via the DB Manager / SQLite functions, but in PostGIS, we do the following:

from linedata as l

This, exported to a new table, allows the points of the lines (for our case from PGRouting students to their school) so we can visualize the hotspot of routes the students 'could' take:

enter image description here


Using a similar approach to the answer from @DPSSpatial, I would use the QChainage plugin to create evenly spaced points along each line.

This plugin generates points along the line, but it doesn't copy across any attributes over from the line.

Here I'm assuming WGS84 (4326, Degrees Lat/Lon). You probably want to do this using an appropriate projection in meters.

  • use QChainage to generate points along the line, e.g. every 0.05 degrees
  • Buffer this layer e.g. by 0.001 degrees.
  • Do a Spatial Join (Vector > Data Management Tools > Join Attributes by Location) (using "Intersects"), from the buffered points to your original line layer. This will let the points pick up the influence value from the lines beneath them.
  • Convert this layer back to points using Vector > Geometry Tools > Polygon Centroids

Finally, I would use the standard heatmap renderer. Make sure you use the weight points by setting and use the influence field.

You should now have something like this. The numbers along each line show the "influence" value.

enter image description here


In fact, it is possible to do line density in QGIS using the standard menus sending parameters to the GDAL executables.

Using gdal_rasterize using the -burn -add switch would create a raster of densities of lines or points, with no search radius as kernel densities and similar. Just how many points or how much lines within a raster cell.

gdal_rasterize is found in the menu Raster -> Conversion -> Rasterize. In the last text field, you press the pencil button and alter the text to include "-burn 1 -add" similar to below. Naturally, you change the -tr (resolution) parameters and the input and output name according to your situation.

gdal_rasterize -burn 1 -add -tr 200.0 200.0 -l lines C:/lines.shp C:/out_lines.tif

Jukka Rahkonen gave me the hints on the gdal_dev mailing list. I've been looking for this for literally years.

Concerning the raster cell values for rasterized lines, I am unsure of what the values represent. Apparently it is not number of lines or lenghts of lines.

Line density with gdal_rasterize

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.