My layer "users_print_view" contains image path. I would like to display this as image in print composer. I can copy path and "Adds a new picture to the layout" and paste it but I would like it to be automatic. Can I there use Variable? Choose there like layer and column? Or maybe other way... Do you have some ideas?
To build on @kartoza-geek's answer, you can use all kinds of variables and values to determine the image filepath. Use their answer if you are relying on another layer to get the filename.
If your image filename is based on the project filename, you can use the project filename as a variable and extract the image name from it using regexp.
So in your example if the project file is
abcd_1234A_efgh.qgs the following regexp expression will extract anything between the first and second instances of an underscore from the project name (
Then just concatenate the relevant image filetype extension (e.g.
.png) at the end, and at the beginning, the path to your image (if it's relative to your project file location, you can use
@project_folder as a variable).
For example if the file is 1234A.jpg in the
images subfolder of where your qgs file is and you are using Windows...
Which would return something like
You can of course add other values from your atlas features, other layer features, etc. to this string if required.
You are trying to add an image to the map but the map item (picture) has no relationship with the layer items. So what you need to do is the following.
- Add an image to the map.
- In data defined settings select
- Enter the following formulae
aggregate(layer:='New_scratch_layer_34fb05c7_8585_4ab4_ac73_d29eb398f3c2',aggregate:='concatenate', expression:="path", concatenator:=',')
Replace the layername with yourlayer name.
NB I tested this with a layer with a single record. You would need to modify the expression to fetch the correct row if you have multiple entries.
If you have multiple entries you can use a filter just like below
aggregate(layer:='images_72aff17a_57df_4cf2_82ac_21400778cbc0',aggregate:='concatenate', expression:="path", filter:="name"='test')
This can be done by data-defining the image paths, and is documented in the Creating a Report section in the QGIS User Manual: