I have a MultiLineString vector layer from which I would like to calculate the length.

enter image description here

I have tried to calculate the length with the Field Calculator by putting in the expression $length. The problem is that the dataset is very big (the attribute table consists of about 700,000 features) and my computer or QGIS is not capable of calculating that (at least when using this approach).

Any suggestions of other ways QGIS might be able to calculate the length and deal with the size of the data given the large number of features?

  • 1
    Are you trying to calculate the total length of lines in the layer, or the length for each line in the layer?
    – lambertj
    Commented Jun 27, 2018 at 15:23

4 Answers 4


Field calculator can be activated from Layer Properties window. It is on Fields tab (2.18) or Source Fields tab (3.0/3.2), which calculation is much faster than the one activated from the attribute table.

  • Interesting - do you have a reference for this, or have you tested it?
    – Simbamangu
    Commented Jun 27, 2018 at 16:03
  • @Kazuhito is right. All operations made from the Source Fields tab are very fast. Here is a good example.
    – Cezar B
    Commented Jun 27, 2018 at 16:08
  • Select part of roads with freehand select tool and calculate length for selected, and do it again and again...
    – Frodo
    Commented Jun 27, 2018 at 16:38
  • Yes @Simbamangu I think How to edit a large shapefile in QGIS? was successful case.
    – Kazuhito
    Commented Jun 27, 2018 at 17:24
  • Right, the OP there indicated that the process never completed using (I assume) the calculator in attribute table view, but it succeeded in 20m using the Layer Properties tab. Great, but there's no indication that OP's original method wasn't simply hanging. Can you provide any measured speed comparison between the two methods where it's known that the processes complete? I think your answer's good here but some more info would be worthwhile.
    – Simbamangu
    Commented Jun 28, 2018 at 7:06

One approach would be to split your line feature layer into multiple chunks, calculate the length for lines in each, then merge the split layer.

For example, you can clip your roads to individual polygons in an a shapefile of administrative boundaries (counties in the example below). Select from the menu Vector -> Geoprocessing tools -> Clip, and enable iterate over this layer option (green arrow button, circled below).

enter image description here

Alternatively, you could use Select by Location to select line features that intersect individual polygon boundaries. This may be desireable if you don't wish to split line features at administrative boundaries (i.e., if you want total length of lines that may fall in multiple polygons). Then run the $length calculation for selected subsets of the line layer.

enter image description here


For such number of data, Qgis may hang while trying to calculate the length. If the roads are of different categories, I would suggest you calculate by the categories after which you merge the table results to have your data as whole. You can as well categorize by any other attribute feature that differentiates the roads, run each category separately and finally merge or join results.


If you want to know the total length and some other statistics use the "Show statistical summary" tool. It has letter Sigma as an icon in the main toolbar.

enter image description here

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.