Feature-Driven Atlas Print with one to many relation pictures

Hello everyone,

I am trying to create an Atlas layout which would contain all the information from my layer (lets name it LAYER-X).
Everything works perfectly exept for the pictures.
I have set a relation with Tabel-X so that I can take as many pictures as I want.
I do not need all the photos in my report just one or two.

Does any one knows how I can do that?


Imported from GitHub discussion by @McGeo22 on 2023-08-30T11:48:49Z

If you don’t need an additional level in your report then you can access the pictures (the path) with the expression

relation_aggregate('<relation_name>','array_agg', "path_field")[0]

Reads the path_field from your relation in an array, and indexing the first one with 0.


Imported from GitHub comment by @signedav on 2023-08-30T11:56:26Z

Thank you very much for your answer.

I also thought of this solution, but when I implement it in my QField project, the printed PDF does not contain an image, although I do not get an error message…

When using relation_aggregate I get something like this ‘DCIM/XXXXXXXXX.JPEG’, which should work or am I missing something?


Imported from GitHub comment by @McGeo22 on 2023-08-30T13:09:43Z

Does it work in QGIS?


Imported from GitHub comment by @signedav on 2023-08-30T13:21:14Z

Maybe you have to add project_folder || relation_agg.... Not sure.


Imported from GitHub comment by @signedav on 2023-08-30T13:23:00Z

Interestingly it doesn’t work in QGIS either, but I tested another project where I know it works and it does (in QGIS)…
This is very strange and requires more testing on my side I think.


Imported from GitHub comment by @McGeo22 on 2023-08-30T13:43:08Z

anyway thank you for your help.


Imported from GitHub comment by @McGeo22 on 2023-08-30T13:43:32Z

I have the same set up like you described: Pictures are in a 1:n related table. For my use case i decided it is enough to print 4 pictures of a parent feature. This is how i set it up:

  1. Created a page with 4 raster image canvases. On page properties of the “picture page” i checked the box Exclude page from exports and added an expression so the page is not printed if there are no pictures:
CASE 
WHEN project_home+'/'+ array_get( string_to_array( relation_aggregate(relation:='relation_name',aggregate:='concatenate',expression:="fieldname_of_your_picture_path",concatenator:='; '),delimiter:='; '),0) IS NULL THEN TRUE
ELSE FALSE
END

  1. For the raster images i set an data defined override with following expression:

project_home+'/'+ array_get( string_to_array( relation_aggregate(relation:='Bäume_Bilder',aggregate:='concatenate',expression:="Bildpfad",concatenator:='; '),delimiter:='; '),0)

Note: the ‘0’ in the end of the expression takes the first picture child feature (picture) into account. You need to change it to 1-3 for each of the other raster images.

This works fine in QField :slight_smile:


Imported from GitHub comment by @meyerlor on 2024-06-24T07:41:56Z