3

In QGIS 3.22. For a vector layer, I would like to have a certain attribute (Field_A) be both

  • editable by a user, AND
  • automatically filled in by an expression for features that are not user-edited.

As a simple example, say that Field_A corresponds to the polygon surface area;

  • Most of the time, polygons should simply be automatically filled with the expression $area, and update dynamically as such (via a Default Value, for example).
  • However, occasionally, there is a polygon that the user knows should be filled with a different value (perhaps the real surface area concerned with the project is different). The user does not want to change the polygon and would rather simply edit the value to whatever they want, and have this new, edited value remain that way (i.e. not update automatically to $area the next time there is a change).

So what I am looking for is a way for an attribute to distinguish between user-edited values (to be preserved as such) and non-user edited values (to be updated dynamically by a default expression). Or in other words, a way of allowing a user override of the default expression.

There are a few methods of automatically updating attribute values that I am aware of, but do not make this distinction:

  1. 'Default Values' (layer properties-->attributes form) allows dynamic updates, but the field becomes uneditable.

  2. 'Virtual Fields' (layer properties-->fields, and created with field calculator) also allows dynamic updates, but the field is uneditable; additionally, the values are not saved in the data.

  3. the 'AutoFields' plugin is, as far as I can tell, no longer available.

  4. I know that Python-based methods exist, though as far as I know they do not allow for this distinction.

It seems like it should be possible to allow a "user override" of the default -- such as a conditional statement where IF a user edits a value, the value to keep is that edited value, and ELSE the value to keep should be calculated from a given expression. Is it possible to refer to a "user edit" as an expression term? Any other ideas?

5
  • You could use two fields, one for automated area, the other for user-entered values? Commented Nov 11, 2021 at 14:15
  • Based on the comment by @Erik: create a virtual field with if-condition: if the field with user filled values is empty (NULL), return $area, otherwise the manually entered value of that field. Commented Nov 11, 2021 at 17:47
  • Thanks guys, this would be a workaround in some cases. I would still like to know if it is possible (in Python for example) to enable such a 'user override' of a field expression. (Without needing to create more fields.) Commented Nov 11, 2021 at 19:01
  • 1
    @pete, two things: 1) Autofields is no longer available because QGIS 3 brings most of its functionality out of the box, and 2) regarding your question, at some extent, leaving the Apply default value on update unchecked in the Layer properties --> Default Values section, and still setting a default value expression (e.g., $area or area($geometry)) could help you. It will give you an automatic value but also will preserve user edits. Commented Nov 11, 2021 at 19:44
  • thanks for the suggestion @GermánCarrillo; it seems however that leaving Apply default value on update unchecked will only supply the default value upon creating a new feature; it does not update an existing feature dynamically when it is modified (including those without user edits). Commented Nov 11, 2021 at 20:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.