2

If I have 2 attribute columns and I wish to change certain values, is it possible for the second attribute column to automatically update its values based on an expression?

Example:

Age |  Status
10  |  Child
14  |  Child

If I change the Age from 14 to 18, I would like the Status to automatically change from Child to Adult, so it would look like the following:

Age |  Status
10  |  Child
18  |  Adult

I must only be able to do this within QGIS and without the use of database functionalities such as PostGIS/SpatiaLite etc. I've looked at Value relations but that only seems to provide drop-down box for the user to select the relating columns. I've also looked at Relation Reference but it won't allow me to select a "Relation" (not even sure what Relation Reference actually does).

Please advise?

I am using QGIS 2.2.

6

What you want is available starting from QGIS 2.6 and is called Virtual Field. Just create a new attribute, select "Virtual Field" and insert the expression used to calculate the new column.

For your case:

CASE WHEN "Age" < 18 THEN 'Child' ELSE 'Adult' END 

You can use a recent nightly build / test build to use this new feature.

The value relation and relation reference widgets are used to show attributes from a first table (layer) on a second table.

  • Almost seems as if QGIS 2.6 is the Holy Grail for all my problems! Thank you Matthias, I will test this with the new build. – Joseph Sep 8 '14 at 14:59
  • @Joseph, I had quite the same problem (gis.stackexchange.com/questions/107090/…) recentely and solved it with QGIS 2.2 and 2.4 by setting up a custom form. In a python script for this form I used the field.textChanged method to update one field based on a change in another field.. However, this cool new 'virtual field' is much more handy! – Kay Sep 8 '14 at 18:30
  • Awesome @Kay, that's an interesting alternative. I will have to try it sometime as it can help me learn more about python. But yes, I am also looking forward to seeing the attributes of layers and joined-layers update automatically! – Joseph Sep 9 '14 at 9:29

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.