4

I have a line layer and I computed the attribute "length" with the field calculator. After that, I changed the geometry of some lines with the editing toolbar. That means the values of "length" in the attribute table are not correct anymore. Is there an automatic way (or at least a quick way) to update the values of "length" to the correct actual length of the line geometries?

I know I could update the values using the field calculator. I also know I could use a virtual field. But I want to have the best out of these two options. I would like to have the automatic updates (like virtual fields) and the fact of having the correct values in the geodata itself instead of having these correct values only in my QGIS Project file (.qgz).

I observed that my coworkers do many mistakes using the field calculator, that's why I am looking for another solution.

1
  • I haven't used the AutoFields plugin so you can run your own tests: plugins.qgis.org/plugins/AutoFields. I do use the calculate geometry plugin which puts a menu item when one right clicks a layer. It's faster and less likely to make a mistake than using the field calculator. If you use file geodatabases the shape_length field should auto-update when you save your edits.
    – johns
    Mar 11, 2021 at 18:12

1 Answer 1

7

You can do this:

  1. Properties layer -> attribute form -> choose attribute where you need length ->Defaults -> put default value: $length -> check "apply default value on update"

Now when you make new line then value automaticly generate length line, when you modify line - length changing too :)

enter image description here

1
  • That works perfectly! Thanks! Mar 14, 2021 at 11:36

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.