Automating citation of Data Source in Map?











up vote
4
down vote

favorite
1












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.



enter image description here










share|improve this question









New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    yesterday










  • retagged this accordingly.
    – Jochen Schwarze
    yesterday















up vote
4
down vote

favorite
1












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.



enter image description here










share|improve this question









New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    yesterday










  • retagged this accordingly.
    – Jochen Schwarze
    yesterday













up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





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.



enter image description here










share|improve this question









New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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.



enter image description here







qgis print-composer layouts expression






share|improve this question









New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Jochen Schwarze

6,06331354




6,06331354






New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









kalaw23

211




211




New contributor




kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






kalaw23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    yesterday










  • retagged this accordingly.
    – Jochen Schwarze
    yesterday














  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    yesterday










  • retagged this accordingly.
    – Jochen Schwarze
    yesterday








1




1




This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
yesterday




This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
yesterday












retagged this accordingly.
– Jochen Schwarze
yesterday




retagged this accordingly.
– Jochen Schwarze
yesterday










2 Answers
2






active

oldest

votes

















up vote
3
down vote













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



enter image description here



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


enter image description here



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


enter image description here






share|improve this answer























  • 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
    yesterday












  • thx, we all keep on learning! ;-)
    – Jochen Schwarze
    yesterday


















up vote
2
down vote













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.






share|improve this answer























    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',
    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
    });


    }
    });






    kalaw23 is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304822%2fautomating-citation-of-data-source-in-map%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








    up vote
    3
    down vote













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



    enter image description here



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


    enter image description here



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


    enter image description here






    share|improve this answer























    • 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
      yesterday












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      yesterday















    up vote
    3
    down vote













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



    enter image description here



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


    enter image description here



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


    enter image description here






    share|improve this answer























    • 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
      yesterday












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      yesterday













    up vote
    3
    down vote










    up vote
    3
    down vote









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



    enter image description here



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


    enter image description here



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


    enter image description here






    share|improve this answer














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



    enter image description here



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


    enter image description here



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


    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered yesterday









    Jochen Schwarze

    6,06331354




    6,06331354












    • 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
      yesterday












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      yesterday


















    • 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
      yesterday












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      yesterday
















    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
    yesterday






    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
    yesterday














    thx, we all keep on learning! ;-)
    – Jochen Schwarze
    yesterday




    thx, we all keep on learning! ;-)
    – Jochen Schwarze
    yesterday












    up vote
    2
    down vote













    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.






    share|improve this answer



























      up vote
      2
      down vote













      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.






      share|improve this answer

























        up vote
        2
        down vote










        up vote
        2
        down vote









        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Matt Needle

        17913




        17913






















            kalaw23 is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            kalaw23 is a new contributor. Be nice, and check out our Code of Conduct.













            kalaw23 is a new contributor. Be nice, and check out our Code of Conduct.












            kalaw23 is a new contributor. Be nice, and check out our Code of Conduct.
















            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304822%2fautomating-citation-of-data-source-in-map%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

            Ellipse (mathématiques)

            Quarter-circle Tiles

            Mont Emei