Exclude image from rendering in layout if file not found

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3















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.










share|improve this question
























  • Are you using atlas?

    – ahmadhanb
    Feb 13 at 9:22











  • Yes, I'm using atlas.

    – Marin Leontenko
    Feb 13 at 9:26















3















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.










share|improve this question
























  • Are you using atlas?

    – ahmadhanb
    Feb 13 at 9:22











  • Yes, I'm using atlas.

    – Marin Leontenko
    Feb 13 at 9:26













3












3








3








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.










share|improve this question
















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.







qgis atlas qgis-print-layouts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 at 20:44









underdark

68.7k13178344




68.7k13178344










asked Feb 13 at 9:18









Marin LeontenkoMarin Leontenko

14311




14311












  • Are you using atlas?

    – ahmadhanb
    Feb 13 at 9:22











  • Yes, I'm using atlas.

    – Marin Leontenko
    Feb 13 at 9:26

















  • Are you using atlas?

    – ahmadhanb
    Feb 13 at 9:22











  • Yes, I'm using atlas.

    – Marin Leontenko
    Feb 13 at 9:26
















Are you using atlas?

– ahmadhanb
Feb 13 at 9:22





Are you using atlas?

– ahmadhanb
Feb 13 at 9:22













Yes, I'm using atlas.

– Marin Leontenko
Feb 13 at 9:26





Yes, I'm using atlas.

– Marin Leontenko
Feb 13 at 9:26










1 Answer
1






active

oldest

votes


















3














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:



Case
when @atlas_featureid in (200,250) then 320
end


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.






share|improve this answer























  • So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

    – Marin Leontenko
    Feb 13 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 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).

    – Marin Leontenko
    Feb 13 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 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 at 22:24










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312020%2fexclude-image-from-rendering-in-layout-if-file-not-found%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














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:



Case
when @atlas_featureid in (200,250) then 320
end


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.






share|improve this answer























  • So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

    – Marin Leontenko
    Feb 13 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 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).

    – Marin Leontenko
    Feb 13 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 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 at 22:24















3














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:



Case
when @atlas_featureid in (200,250) then 320
end


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.






share|improve this answer























  • So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

    – Marin Leontenko
    Feb 13 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 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).

    – Marin Leontenko
    Feb 13 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 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 at 22:24













3












3








3







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:



Case
when @atlas_featureid in (200,250) then 320
end


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.






share|improve this answer













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:



Case
when @atlas_featureid in (200,250) then 320
end


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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 13 at 9:41









ahmadhanbahmadhanb

23.2k32153




23.2k32153












  • So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

    – Marin Leontenko
    Feb 13 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 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).

    – Marin Leontenko
    Feb 13 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 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 at 22:24

















  • So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

    – Marin Leontenko
    Feb 13 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 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).

    – Marin Leontenko
    Feb 13 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 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 at 22:24
















So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

– Marin Leontenko
Feb 13 at 10:50





So, option 1 still requires that I manually specify a list of features that miss photos? Am I correct?

– Marin Leontenko
Feb 13 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 at 10:57





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

– Marin Leontenko
Feb 13 at 11:08





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

– Marin Leontenko
Feb 13 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 at 11:19






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 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 at 22:24





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 at 22:24

















draft saved

draft discarded
















































Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312020%2fexclude-image-from-rendering-in-layout-if-file-not-found%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay