Exclude image from rendering in layout if file not found
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.
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
add a comment |
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.
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
Are you using atlas?
– ahmadhanb
Feb 13 at 9:22
Yes, I'm using atlas.
– Marin Leontenko
Feb 13 at 9:26
add a comment |
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.
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
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.
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
qgis atlas qgis-print-layouts
edited Feb 13 at 20:44
underdark♦
68.8k13178344
68.8k13178344
asked Feb 13 at 9:18
Marin LeontenkoMarin Leontenko
15211
15211
Are you using atlas?
– ahmadhanb
Feb 13 at 9:22
Yes, I'm using atlas.
– Marin Leontenko
Feb 13 at 9:26
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
You have two options:
Option 1:
Apply the following expression on the Position and Size of the photo frame.
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.
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 anotherwhen
statement unless the value afterthen
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You have two options:
Option 1:
Apply the following expression on the Position and Size of the photo frame.
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.
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 anotherwhen
statement unless the value afterthen
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
add a comment |
You have two options:
Option 1:
Apply the following expression on the Position and Size of the photo frame.
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.
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 anotherwhen
statement unless the value afterthen
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
add a comment |
You have two options:
Option 1:
Apply the following expression on the Position and Size of the photo frame.
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.
You have two options:
Option 1:
Apply the following expression on the Position and Size of the photo frame.
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.
answered Feb 13 at 9:41
ahmadhanbahmadhanb
23.3k32153
23.3k32153
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 anotherwhen
statement unless the value afterthen
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
add a comment |
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 anotherwhen
statement unless the value afterthen
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Are you using atlas?
– ahmadhanb
Feb 13 at 9:22
Yes, I'm using atlas.
– Marin Leontenko
Feb 13 at 9:26