3

Today I was calculating length of features to know how long a certain route will be. I was wondering if there is a quicker way to find out the length of a selection of features?

I am looking for a solution like a simple text in the lower status bar that says Selection: 350 m and maybe switches to amount of points or m² area selected according to the layer I'm on. Just in the style of Excel telling you how many cells you have selected and sum/min/max/etc of them.

Is this possible to acchieve in QGIS? In other words: am I overseeing an integrated option or is there maybe a plugin, that does that?

4
  • You might want to try the statistics panel, with $length as expression: docs.qgis.org/3.22/en/docs/user_manual/introduction/…
    – Kasper
    Commented Feb 23, 2023 at 11:43
  • I tried that and I get a value. Can I assume the value is in meters? It doesn't give any units...
    – e-shirt
    Commented Feb 23, 2023 at 12:08
  • The $length fonction respects both the current project's ellipsoid setting and distance unit settings...
    – J.R
    Commented Feb 23, 2023 at 13:15
  • You can try this plugin. Not published but if you click on the Code button on the GitHub page you can download a zip file and install it from that.
    – Ben W
    Commented Feb 26, 2023 at 6:07

2 Answers 2

10

You may use the statistics panel (View>Panel>Statistics Panel) with the "Selected feature only" option. You will need to change the field to length or area depending on the information you want.

If length or area fields don't exist in your dataset you may use an expression in the statistic panel to calculate them.

enter image description here

0
4

You can also use the following PyQGIS script for the layer with projected coordinates. It prints the length of the selected line.

def print_length(selected, deselected, clearAndSelect):
    if len(selected) == 1:
        global layer
        feature = layer.getFeature(selected[0])
        length = feature.geometry().length()
        print(length)
    
layer = QgsProject.instance().mapLayersByName("LAYER_NAME")[0]
layer.selectionChanged.connect(print_length)

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.