Tuesday, 20 March 2018

labeling - QGIS: relations in label expressions



In my project I have a many-to-one relationship.


For example I have a vector layer "Towns" and a data layer "TownsInfo".


Each town record consists of "Name" and "Id". Each TownsInfo record consist of "Id", "TownId", "Population" and "Source".


I want to show "Population" of town as label where "Source" is 'Wikipedia' for example.


How can I use "Population" and "Source" attributes from "Towns" expression builder?


Update 1


I've meant getting information only from records where "Source" is 'Wikipedia'



Answer



I've found out a solution.


I've made rule-based filtering with expression:



relation_aggregate( 'TownsInformationRelation', 'max', CASE WHEN "Source" = 'Wikipedia' THEN "Population" ELSE 0 END )

And also I've used filter:


relation_aggregate( 'TownsInformationRelation', 'count', CASE WHEN "Source" = 'Wikipedia' THEN 'true' ELSE NULL END )

Thanks!


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...