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




















  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    Dec 4 at 7:35










  • retagged this accordingly.
    – Jochen Schwarze
    Dec 4 at 8:41










  • ye, it automatically tagged arcgis.
    – kalaw23
    Dec 6 at 8:59















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




















  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    Dec 4 at 7:35










  • retagged this accordingly.
    – Jochen Schwarze
    Dec 4 at 8:41










  • ye, it automatically tagged arcgis.
    – kalaw23
    Dec 6 at 8:59













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















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















share|improve this question













share|improve this question




share|improve this question








edited Dec 4 at 8:40









Jochen Schwarze

6,15531454




6,15531454










asked Dec 4 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 at 7:35










  • retagged this accordingly.
    – Jochen Schwarze
    Dec 4 at 8:41










  • ye, it automatically tagged arcgis.
    – kalaw23
    Dec 6 at 8:59














  • 1




    This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
    – Jochen Schwarze
    Dec 4 at 7:35










  • retagged this accordingly.
    – Jochen Schwarze
    Dec 4 at 8:41










  • ye, it automatically tagged arcgis.
    – kalaw23
    Dec 6 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 at 7:35




This screenshot looks like QGIS print composer to me, not ArcGIS desktop as your tag suggests. Confirm?
– Jochen Schwarze
Dec 4 at 7:35












retagged this accordingly.
– Jochen Schwarze
Dec 4 at 8:41




retagged this accordingly.
– Jochen Schwarze
Dec 4 at 8:41












ye, it automatically tagged arcgis.
– kalaw23
Dec 6 at 8:59




ye, it automatically tagged arcgis.
– kalaw23
Dec 6 at 8:59










2 Answers
2






active

oldest

votes

















up vote
4
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
    Dec 4 at 10:32












  • thx, we all keep on learning! ;-)
    – Jochen Schwarze
    Dec 4 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 at 9:04




















up vote
3
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
    });


    }
    });














    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
    4
    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
      Dec 4 at 10:32












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      Dec 4 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 at 9:04

















    up vote
    4
    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
      Dec 4 at 10:32












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      Dec 4 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 at 9:04















    up vote
    4
    down vote










    up vote
    4
    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 Dec 4 at 8:49

























    answered Dec 4 at 8:39









    Jochen Schwarze

    6,15531454




    6,15531454












    • 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 at 10:32












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      Dec 4 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 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 at 10:32












    • thx, we all keep on learning! ;-)
      – Jochen Schwarze
      Dec 4 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 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 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 at 10:32














    thx, we all keep on learning! ;-)
    – Jochen Schwarze
    Dec 4 at 11:37




    thx, we all keep on learning! ;-)
    – Jochen Schwarze
    Dec 4 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 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 at 9:04














    up vote
    3
    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
      3
      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
        3
        down vote










        up vote
        3
        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 Dec 4 at 8:33

























        answered Dec 4 at 8:26









        Matt Needle

        30413




        30413






























            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.





            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

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?