I have a grid of 10 km x 10 km polygons, and am planning survey transect lines across the area. I am trying to use the Sum Line Lengths tool to calculate the total transect length in each polygon. The transect line is a single, continuous line, which zig-zags across the grid. The CRS is UTM, units metres.

The issue I have is that the summed length is incorrect - it is less than it should be.

I think this is due to the transect line repeating its track across the grid cells - might this be the case?

So the transect crosses over precisely the same ground a few times.

Another minor issue, but perhaps a clue to what is happening, is the line count is also incorrect: it's either 0 or 1, when in some cells it should be 2 or 3.

I've done various tests with line layers on the same grid of polygons, and Sum Line Length gives the correct output if the lines, or single line with multiple passes through the cell, do(es) not repeat its track precisely as I want it to in reality... The number of lines / cell is always wrong though.

I am using QGIS v2.18.16.


1 Answer 1


I'm not sure how to troubleshoot the Sum Line Lengths tool, but here's another way to achieve the same thing.

  1. Clip the transect layer using the grid layer.
  2. Add a $length field to the clipped transect layer.
  3. Install the RefFunctions plugin. This adds some functions to the Expression Builder, including the intersecting_geom_sum() function.
  4. Use the intersecting_geom_sum() function to calculate the total transect length within each grid cell.

Note: It's possible that the intersecting_geom_sum() function will include all transect segments that touch the grid cell. If that happens, make a very small (eg, 1 cm) negative buffer on the grid layer. Proceed with step 4, using the buffer layer to calculate the intersecting_geom_sum().

  • Hello csk - thank you very much. That sounds like a useful approach for me - I'll give it a go.
    – ChrisP
    Oct 18, 2018 at 13:43
  • csk - I used the QGIS tool 'clip' with the transect line as the input and the grid polygons as the clipping layer. This only output a single line though, with $length 1648 km. Almost the entire transect line is located inside the grid, and its $length is 3166 km. It seems to be the same problem as I got using Sum Line Length. Any idea why it isn't being clipped into small grid cell-sized segments with the clip tool, and why the line length is measured less than it really is?
    – ChrisP
    Oct 18, 2018 at 14:00
  • Hi again - I tried various line-split-at-polygon tools but could not get the correct total line length. I worked around it by re-making the transect line as multiple line features representing successive 'passes' across the survey area. Sum Line Length now gives the correct cell and total line lengths.
    – ChrisP
    Oct 18, 2018 at 15:10

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.