Thursday, 26 December 2019

Get Attributes from 1:n relation in QGIS as Expression to use in Atlas


I need to set up way signs for something like a "hiking-GIS". In the first step I made a network analysis (using QNEAT3) to find the distance from the signs ("Way Signs") to the available destinations ("Destinations") along the trail network ("Ways"). The result is the "OD-Matrix". So far so good... to see all destination distances for every single sign, I was setting up a 1:n relation via project properties. You can see all relevant results in the screenshot:


enter image description here


I'm able to see all destinations with distances in the attribute form - great! But I need to get for every sign all it's destinations with distance. To get a real printable sign, I thought about to use the Atlas to switch trough every sign (layer 'Way Signs' as coverage layer) and use a expression text field to show the destinations with distances.


So the question is: How do I get the 1:n related attributes via expressions to use them in the Atlas (or anywhere else)?


enter image description here



Answer




A starting point with expressions would be to use the Aggregate and Array functions: A construct like the following will put all destinations (from the joined layer) in an array which belongs to the current atlas feature:


string_to_array(
Aggregate(
layer:='OD-Matrix',
aggregate:='concatenate',
expression:="destination_id", concatenator:=',',
filter:="origin_id"=attribute( @atlas_feature, 'name')))

with array_get() you can access the members of the array


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...