1

Is there a way to make a QGIS symbology that uses attribute fields from other features?

Example:

<featurecollection>
  <feature> 
    <id>1235</id>    <!-- same id --> 
    <time>100</time> <!-- older ----> 
  </feature>
  <feature>
    <id>1235</id>    <!-- same id --> 
    <time>101</time> <!-- newer ----> 
  </feature>
  
  <feature>
    <id>1236</id>    <!-- unique id -> 
    <time>102</time> <!-- is new ----> 
  </feature>
</featurecollection>

When there are 2 features with the same "id", then the symbology of the feature having the older time should have a certain (symbology A) style. The feature with the identical "id" with a newer time value should have another (symbology B) style.

When there is only 1 feature with an "id", then that feature should have the "B" symbology style.

With symbology categorize this will of course not work. A have some basic knowledge of Rule based symbology .. is that the way to go?

Or are there other ways?

Adding a new field to the source file is not possible. An XSD determines the fields and I cannot add a field to that XSD like that.

Possibility 2: can I add a attribute field and have it populated dynamically within QGIS?

Other possibilities?

1 Answer 1

1

You can use a rule-based symbology with two rules.

The default one is for the "new" style, then add another for the "old" style

enter image description here

Click the little epsilon icon beside the "old" rule filter and enter the following expression

"time"  < maximum( "time",null,"id" =  attribute( $currentfeature, 'id' ))

it uses the maximum aggregate function over the current layer. It asks for the greatest value from the "time" column, but only for records whose field "id" has the same value as the current feature "id". Once it has found this maximum, it compares it with the current feature "time" and return as true/false boolean.

enter image description here

1
  • Brilliant! Thank you very much!
    – tm1701
    Commented Aug 4, 2023 at 9:03

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.