0

i have set up a 1:n relation in QGIS. The parent layer contains trees (point geometry) and some basic informations about. The related table contains measurements which should be carried out to keep the tree healty. In the "Measurements"-table each measurement has a numeric priority (ranging from 1 to 5). I want to achieve that as soon a measurment was carried out and a worker ticks a box in the attribute form (boolean column "Done") of the "Measurement"-table the field "Priority" which exists also in in the main table is updated with the highest priority of the remaining measurements.

I assume this can be done using "actions". But is there a way where the user does not have to proactively execute the action so the procedure is fully automated?

The tables are in a geopackage if that matters.

1 Answer 1

1

you can use virtual field in your tree layer together with an aggregate expression to get the max value of the priority field, something like:

 aggregate( 
 layer:='measurements',
 aggregate:='max',
 expression:="priority",
 filter:=("fk"=attribute(@parent, 'id')) 
 and ("done"='false'))

where "fk" is the foreign key to trees and 'id' the primary key of trees...

1
  • 1
    ah thats a good start. although i would prefere not to fiddle with the layer's structure (the field "Priority" already exists and introducing a new virtual field makes things complicated when i export the layer from QGIS again so the client can use it in his administrative toolwhich only accepts this certain layer structure
    – sn1ks
    Commented Jun 10, 2020 at 7:11

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.