1

I have a point layer (Dormouse) linked to a child geometry-less table (DormouseSurveyData) with a 1-n relationship. I am trying to set up the symbology of the point layer to change color dependent on if there is a value in the 'Presence' field of my child table.

I am aware that I could either join the tables or create a virtual layer to achieve this but I need the symbology to update as the records are updated so that when data is input in the field the symbology will dynamically update accordingly.

I have tried many different variations but the ones i thought most likely to work are below:

case
    when dbquery('DormouseSurveyData','Presence','Tube_ID = attribute($currentfeature,'id')')
        then color_rgb(0,200,0)
    
    when 'DormouseSurveyData_2acaff7f_d2b5_47a2_875c_0859987007d7.Tube_ID' =  'Dormouse.id' and 'DormouseSurveyData_2acaff7f_d2b5_47a2_875c_0859987007d7.Presence' = "False"
        then color_rgb(200,0,0)
    
    else color_rgb(0,0,200)
end

case
    when dbvalue('DormouseSurveyData','Presence','Tube_ID', 'ID')
        then color_rgb(0,200,0)
    when dbvalue('DormouseSurveyData','Presence','Tube_ID', 'ID')
        then color_rgb(200,0,0)
    else color_rgb(0,0,200)
end

The relationship links Dormouse.id to DormouseSurveyData.Tube_ID

Below are snippets of the two tables. Both with testing data.

When I run either expression in the data override for the fill color of my symbology i just get the 'else' result (ie blue).

Dormouse Table

DormouseSurveyData Table

1
  • How did you realize the link? Can you provide example data? What happens when you try your expressions?
    – Erik
    Commented Sep 16, 2021 at 12:29

2 Answers 2

1

Have you tried relation_aggregate function for classification of the layer?

E.g.

relation_aggregate(
relation:='relationdomousexblaablaablaa21321144124',aggregate:='max',expression:="precense") 

relation_aggregate function brings the id or what ever field you need "Up" to your visualization layer and then you can classify your data based on the other 1:N table values.

0

Based on the answer provided by Sanna Jokela, I created the code below which works perfectly for my purposes and can be easily expanded upon:

case 
when relation_aggregate('DormouseSu_Tube_ID_Dormouse_c_id', 'count', "presence" = 1) = 0 then color_rgb(0,0,200)
else color_rgb(0,200,0)
end

For anyone else wanting to use this, the field 'Presence' is just a confirmation field so only contains '1' for yes or '0' for no. The code above counts up the number of times the child features have a value of '1'. If that is >0 then I know there was confirmed presence on my point so it can be colored accordingly. If not, then the else statement kicks in and puts the default color.

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.