is there a simple way (without writing script or python skills) to auto calculate and auto populate length attribute in QGIS? When I add a new line feature in my layer, I'd like the attribute length to be calculated and populated as I complete the task of adding the line. Right now, I create all my geometry and then update existing field with $length in the Field Calculator.
1 Answer
You want the length to be displayed along your line and auto-update as you draw or edit the line? In this case, simply label your line with the expression length($geometry)
For the attribute table, use Creating a Virtual Field - when you create a new field with the field-calculator, select virtual field and set the expression you like - e.g. length($geometry)
. However, I have to toggle edit-mode, close- and re-open the attribute-table to see the updated values. Simply press the refresh attribute-table does not work.
-
Stumbled upon this problem too. To get the value right away, create a virtual field as described and define the default value with the same expression (no need to apply the default value). Default values are evaluated when the editing popup is created, while virtual fields are evaluated after saving.– cymedMay 9 at 12:23