Automating citation of data source in QGIS print composer?
I have 20 thematic maps with different sources like CITY PLANNING OFFICE, ENVIRONMENT OFFICE, AGRICULTURE OFFICE etc.
Since I have many maps, I want to automate the data source citation of my thematic maps by simply having a code or process. I want that each map layout, the data source will change based on the map that is being viewed. This will lessen the burden because I am not having to manually type the data source for each map layout.
I saw someone discussed about variables and it got my hopes high but it didn't work for me because the layer variables cannot be used in text label in map layout. Only the Global and project variables were working.
qgis print-composer layouts expression attribution
add a comment |
I have 20 thematic maps with different sources like CITY PLANNING OFFICE, ENVIRONMENT OFFICE, AGRICULTURE OFFICE etc.
Since I have many maps, I want to automate the data source citation of my thematic maps by simply having a code or process. I want that each map layout, the data source will change based on the map that is being viewed. This will lessen the burden because I am not having to manually type the data source for each map layout.
I saw someone discussed about variables and it got my hopes high but it didn't work for me because the layer variables cannot be used in text label in map layout. Only the Global and project variables were working.
qgis print-composer layouts expression attribution
1
This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 '18 at 7:35
retagged this accordingly.
– Jochen Schwarze
Dec 4 '18 at 8:41
ye, it automatically tagged arcgis.
– kalaw23
Dec 6 '18 at 8:59
add a comment |
I have 20 thematic maps with different sources like CITY PLANNING OFFICE, ENVIRONMENT OFFICE, AGRICULTURE OFFICE etc.
Since I have many maps, I want to automate the data source citation of my thematic maps by simply having a code or process. I want that each map layout, the data source will change based on the map that is being viewed. This will lessen the burden because I am not having to manually type the data source for each map layout.
I saw someone discussed about variables and it got my hopes high but it didn't work for me because the layer variables cannot be used in text label in map layout. Only the Global and project variables were working.
qgis print-composer layouts expression attribution
I have 20 thematic maps with different sources like CITY PLANNING OFFICE, ENVIRONMENT OFFICE, AGRICULTURE OFFICE etc.
Since I have many maps, I want to automate the data source citation of my thematic maps by simply having a code or process. I want that each map layout, the data source will change based on the map that is being viewed. This will lessen the burden because I am not having to manually type the data source for each map layout.
I saw someone discussed about variables and it got my hopes high but it didn't work for me because the layer variables cannot be used in text label in map layout. Only the Global and project variables were working.
qgis print-composer layouts expression attribution
qgis print-composer layouts expression attribution
edited Dec 19 '18 at 12:32
Jochen Schwarze
6,26831555
6,26831555
asked Dec 4 '18 at 3:48
kalaw23
212
212
1
This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 '18 at 7:35
retagged this accordingly.
– Jochen Schwarze
Dec 4 '18 at 8:41
ye, it automatically tagged arcgis.
– kalaw23
Dec 6 '18 at 8:59
add a comment |
1
This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 '18 at 7:35
retagged this accordingly.
– Jochen Schwarze
Dec 4 '18 at 8:41
ye, it automatically tagged arcgis.
– kalaw23
Dec 6 '18 at 8:59
1
1
This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 '18 at 7:35
This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 '18 at 7:35
retagged this accordingly.
– Jochen Schwarze
Dec 4 '18 at 8:41
retagged this accordingly.
– Jochen Schwarze
Dec 4 '18 at 8:41
ye, it automatically tagged arcgis.
– kalaw23
Dec 6 '18 at 8:59
ye, it automatically tagged arcgis.
– kalaw23
Dec 6 '18 at 8:59
add a comment |
2 Answers
2
active
oldest
votes
You should use the layers Metadata for it. In the Layers properties, fill in Attribution - Title string like shown below (you may use the Url too, as well):
Then insert the following expression into your label item (note the output preview in the screenshot and the arguments description of the layer_properties
function on the right, you may access layer name, feature count and many more, no need for custom functions):
layer_properties(layer_id, 'attribution')
The layer_id
must be in single quotes, you may obtain it either from the layers variables (but you cannot copy and paste it from there) or via the python console (with the desired layer selected):
iface.activeLayer().id()
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
add a comment |
If the source is the layer name you could define your own custom function and use it as an expression in the label content dialog.
Click "Insert an Expression..." in the Main Properties of the label. Select the function editor tab and paste the following. Click "Save and Load Functions".
# Be sure to import iface from qgis.utils
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args='auto', group='Custom')
def get_layer_name(feature, parent):
return qgis.utils.iface.activeLayer().name()
Then back on the Expression tab of the "Insert an Expression..." dialog double click the get_layer_name
function (under Custom) to add it to your expression.
After clicking OK, the name of active layer in your main QGIS window will appear in your label. You will have to refresh the Layout Manager to update the name after a different layer is selected.
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%2f304822%2fautomating-citation-of-data-source-in-qgis-print-composer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should use the layers Metadata for it. In the Layers properties, fill in Attribution - Title string like shown below (you may use the Url too, as well):
Then insert the following expression into your label item (note the output preview in the screenshot and the arguments description of the layer_properties
function on the right, you may access layer name, feature count and many more, no need for custom functions):
layer_properties(layer_id, 'attribution')
The layer_id
must be in single quotes, you may obtain it either from the layers variables (but you cannot copy and paste it from there) or via the python console (with the desired layer selected):
iface.activeLayer().id()
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
add a comment |
You should use the layers Metadata for it. In the Layers properties, fill in Attribution - Title string like shown below (you may use the Url too, as well):
Then insert the following expression into your label item (note the output preview in the screenshot and the arguments description of the layer_properties
function on the right, you may access layer name, feature count and many more, no need for custom functions):
layer_properties(layer_id, 'attribution')
The layer_id
must be in single quotes, you may obtain it either from the layers variables (but you cannot copy and paste it from there) or via the python console (with the desired layer selected):
iface.activeLayer().id()
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
add a comment |
You should use the layers Metadata for it. In the Layers properties, fill in Attribution - Title string like shown below (you may use the Url too, as well):
Then insert the following expression into your label item (note the output preview in the screenshot and the arguments description of the layer_properties
function on the right, you may access layer name, feature count and many more, no need for custom functions):
layer_properties(layer_id, 'attribution')
The layer_id
must be in single quotes, you may obtain it either from the layers variables (but you cannot copy and paste it from there) or via the python console (with the desired layer selected):
iface.activeLayer().id()
You should use the layers Metadata for it. In the Layers properties, fill in Attribution - Title string like shown below (you may use the Url too, as well):
Then insert the following expression into your label item (note the output preview in the screenshot and the arguments description of the layer_properties
function on the right, you may access layer name, feature count and many more, no need for custom functions):
layer_properties(layer_id, 'attribution')
The layer_id
must be in single quotes, you may obtain it either from the layers variables (but you cannot copy and paste it from there) or via the python console (with the desired layer selected):
iface.activeLayer().id()
edited Dec 4 '18 at 8:49
answered Dec 4 '18 at 8:39
Jochen Schwarze
6,26831555
6,26831555
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
add a comment |
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
Thanks for this, Jochen. Very useful! I wasn't aware of this when I wrote my answer. Just to let you know, you can copy the layer_id from the variables by selecting it and using Ctrl + C (right-click does not work).
– Matt Needle
Dec 4 '18 at 10:32
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
thx, we all keep on learning! ;-)
– Jochen Schwarze
Dec 4 '18 at 11:37
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
Do I still need to manually update the expression every time I change the active layer? layer_property('LAYER','ATRRIBUTION')
– kalaw23
Dec 6 '18 at 9:04
add a comment |
If the source is the layer name you could define your own custom function and use it as an expression in the label content dialog.
Click "Insert an Expression..." in the Main Properties of the label. Select the function editor tab and paste the following. Click "Save and Load Functions".
# Be sure to import iface from qgis.utils
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args='auto', group='Custom')
def get_layer_name(feature, parent):
return qgis.utils.iface.activeLayer().name()
Then back on the Expression tab of the "Insert an Expression..." dialog double click the get_layer_name
function (under Custom) to add it to your expression.
After clicking OK, the name of active layer in your main QGIS window will appear in your label. You will have to refresh the Layout Manager to update the name after a different layer is selected.
add a comment |
If the source is the layer name you could define your own custom function and use it as an expression in the label content dialog.
Click "Insert an Expression..." in the Main Properties of the label. Select the function editor tab and paste the following. Click "Save and Load Functions".
# Be sure to import iface from qgis.utils
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args='auto', group='Custom')
def get_layer_name(feature, parent):
return qgis.utils.iface.activeLayer().name()
Then back on the Expression tab of the "Insert an Expression..." dialog double click the get_layer_name
function (under Custom) to add it to your expression.
After clicking OK, the name of active layer in your main QGIS window will appear in your label. You will have to refresh the Layout Manager to update the name after a different layer is selected.
add a comment |
If the source is the layer name you could define your own custom function and use it as an expression in the label content dialog.
Click "Insert an Expression..." in the Main Properties of the label. Select the function editor tab and paste the following. Click "Save and Load Functions".
# Be sure to import iface from qgis.utils
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args='auto', group='Custom')
def get_layer_name(feature, parent):
return qgis.utils.iface.activeLayer().name()
Then back on the Expression tab of the "Insert an Expression..." dialog double click the get_layer_name
function (under Custom) to add it to your expression.
After clicking OK, the name of active layer in your main QGIS window will appear in your label. You will have to refresh the Layout Manager to update the name after a different layer is selected.
If the source is the layer name you could define your own custom function and use it as an expression in the label content dialog.
Click "Insert an Expression..." in the Main Properties of the label. Select the function editor tab and paste the following. Click "Save and Load Functions".
# Be sure to import iface from qgis.utils
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args='auto', group='Custom')
def get_layer_name(feature, parent):
return qgis.utils.iface.activeLayer().name()
Then back on the Expression tab of the "Insert an Expression..." dialog double click the get_layer_name
function (under Custom) to add it to your expression.
After clicking OK, the name of active layer in your main QGIS window will appear in your label. You will have to refresh the Layout Manager to update the name after a different layer is selected.
edited Dec 4 '18 at 8:33
answered Dec 4 '18 at 8:26
Matt Needle
38313
38313
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f304822%2fautomating-citation-of-data-source-in-qgis-print-composer%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
1
This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 '18 at 7:35
retagged this accordingly.
– Jochen Schwarze
Dec 4 '18 at 8:41
ye, it automatically tagged arcgis.
– kalaw23
Dec 6 '18 at 8:59