I'm using QGIS 3.4. print layout to create an atlas with photos of features. I have a folder with photos and each photo is named with an ID of related feature.

Example: If ID of feature is 543, photo is named "543.JPG"

I'm using an expression to define a path to photo: concat('C:/Users/user/Desktop/Photos/', "id" ,'.JPG')

This works fine, but sometimes the photo of a feature is missing in folder and then I get a huge red X instead of a photo.

enter image description here

Is there a way to exclude the picture from rendering if it is not found in folder?

I found an example (link here) that uses "data defined override", but it requires the features to have an attribute "image path" and uses it to determine if the image will be rendered or not based on existence of that value. I don't have image path in my data, i just use feature ID to get the photo.

  • Are you using atlas?
    – ahmadhanb
    Feb 13, 2019 at 9:22
  • Yes, I'm using atlas. Feb 13, 2019 at 9:26

1 Answer 1


You have two options:

Option 1:

Apply the following expression on the Position and Size of the photo frame.

enter image description here

You can apply it only on X position if you want as follows:

when @atlas_featureid in (200,250) then 320 

Where the 200 and 250 are just examples of the feature ids that do not have photos and the 320 is a value to place the frame outside the layout, assuming you are exporting to A3 size paper.

Option 2:

Create empty photos (just a white background photos) in any photo editing software and give them a name same as the id of the ID field, which I do not think you want this option.

  • So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct? Feb 13, 2019 at 10:50
  • Yes, just add the feature ids between the brackets () in the expression. No need to add another when statement unless the value after then is different.
    – ahmadhanb
    Feb 13, 2019 at 10:57
  • The thing is, there are (potentially) a lot of features and photos, so I'm trying to find a workaround. I don't want to go through all features and photos to make a list of features without photos. In that case, adding "photo name" column to the data model seems like the best solution since the number of photos is still relatively small (few hundred) compared to the number of features (thousands). Feb 13, 2019 at 11:08
  • I provided my answer based on your question that you have feature ids, but if you find feature names can be better for your case, then try it.
    – ahmadhanb
    Feb 13, 2019 at 11:19
  • There's no need to go through all your features and compare them to the photos. All you need is a list of photos in that one file, as text. This is a relatively simple, non-GIS problem. A quick internet search of the phrase "get list of files in a folder as text" will solve it.
    – csk
    Feb 14, 2019 at 22:24

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.