3

In QGIS/QField, I have a feature (plants) with child features, which are dated observations of the plant, and I would like to make the appearance (color or shape) of the feature depend on whether there is an observation after some given date, say, July 1 2022 (to make it easy to see whether the plant has resprouted this year). But I haven't managed to work out what the syntax for that would be, or find an example somewhere.

Here are the parent's fields: enter image description here

and here the child's:

enter image description here

In terms of implementation, there might be too much looping (for each plant, for each observation, is it later than date X, return yes when one is found, no when all are inspected and none has been found), but there isn't that much data.

1
  • oops, QGis/QField; question edited! Commented Dec 1, 2022 at 21:16

2 Answers 2

7

Hopefully this is what you are aiming for. Let me know if I have misunderstood your data structure.

I have two tables, one plants_parent and the other plants_child. plants_parent has 3 records which are the plant locations. plants_child is a no-geometry table containing observations of those plants on different dates.

Parent layer

enter image description here

Child layer

enter image description here

Relation

In the Project -> Properties, I set a many-to-one relation using a plant_id column in the child, related to the fid in the parent. The relation is named plants_relation.

Expression

Using the following expression as a rule-based symbology, it is possible to see which plants have been observed after 2022-07-01.

There are several nested functions, the first 3 comments should be read bottom to top to make sense.

array_length(                              -- check if the array has any elements after filtering
    array_filter(                          -- filter the array for dates after 2022-07-01
        relation_aggregate(                -- aggregate all dates (per parent plant) into an array
            'plants_relation',              -- name of the relation in the project properties
            'array_agg',                 
            date_seen                      -- the field values to aggregate
        ), 
        @element > make_date(2022, 7, 1)   -- @element is the current array element being evaluated
    )
) > 0                                      -- rule returns true when there are dates remaining after filtering
Result

enter image description here

Note: labels for visualisation were created using the same expression inside a case statement.

2
3

I'd try tackle this would be by using rule based symbology if I understand what you're asking.

Data

Data

Expressions

Expressions

Outcome

Outcome

1
  • It's a many-to-one relation, as clarified above. I have succeeded in getting different displays with a rule-based symbology that just checks that a 'seen' attribute isn't NULL, and maybe that's good enough, but fully automatic would be better if practical. Commented Dec 2, 2022 at 2:58

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.