How to add an existing QGSVectorLayer to QGIS project?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







4















I know I can pull a vector file into my current project using:



vlayer = iface.addVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


But if I create my layer using something like:



vlayer = QgsVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


and then I do some processing on vlayer how do I then add it to the current project or map layers list?










share|improve this question


















  • 1





    Can you expand on what you mean by "processing"? Editing the layer such as modifying features, running a tool from the processing toolbox etc? Or do you mean something like: QgsProject.instance().addMapLayer(vlayer)?

    – Joseph
    Mar 6 at 13:00











  • that is the correct answer

    – Ian Turton
    Mar 6 at 13:05











  • Any sort of process that changes the layer features

    – Ian Turton
    Mar 6 at 13:05











  • You can see in the PyQGIS cookbook how to add a QgsVectorLayer to the project docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…

    – etrimaille
    Mar 6 at 15:33











  • @etrimaille - thanks, I spotted that soon after I got the answer here :-)

    – Ian Turton
    Mar 7 at 8:02


















4















I know I can pull a vector file into my current project using:



vlayer = iface.addVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


But if I create my layer using something like:



vlayer = QgsVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


and then I do some processing on vlayer how do I then add it to the current project or map layers list?










share|improve this question


















  • 1





    Can you expand on what you mean by "processing"? Editing the layer such as modifying features, running a tool from the processing toolbox etc? Or do you mean something like: QgsProject.instance().addMapLayer(vlayer)?

    – Joseph
    Mar 6 at 13:00











  • that is the correct answer

    – Ian Turton
    Mar 6 at 13:05











  • Any sort of process that changes the layer features

    – Ian Turton
    Mar 6 at 13:05











  • You can see in the PyQGIS cookbook how to add a QgsVectorLayer to the project docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…

    – etrimaille
    Mar 6 at 15:33











  • @etrimaille - thanks, I spotted that soon after I got the answer here :-)

    – Ian Turton
    Mar 7 at 8:02














4












4








4








I know I can pull a vector file into my current project using:



vlayer = iface.addVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


But if I create my layer using something like:



vlayer = QgsVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


and then I do some processing on vlayer how do I then add it to the current project or map layers list?










share|improve this question














I know I can pull a vector file into my current project using:



vlayer = iface.addVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


But if I create my layer using something like:



vlayer = QgsVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr")


and then I do some processing on vlayer how do I then add it to the current project or map layers list?







qgis-3 pyqgis-3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 6 at 12:48









Ian TurtonIan Turton

50.2k548118




50.2k548118








  • 1





    Can you expand on what you mean by "processing"? Editing the layer such as modifying features, running a tool from the processing toolbox etc? Or do you mean something like: QgsProject.instance().addMapLayer(vlayer)?

    – Joseph
    Mar 6 at 13:00











  • that is the correct answer

    – Ian Turton
    Mar 6 at 13:05











  • Any sort of process that changes the layer features

    – Ian Turton
    Mar 6 at 13:05











  • You can see in the PyQGIS cookbook how to add a QgsVectorLayer to the project docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…

    – etrimaille
    Mar 6 at 15:33











  • @etrimaille - thanks, I spotted that soon after I got the answer here :-)

    – Ian Turton
    Mar 7 at 8:02














  • 1





    Can you expand on what you mean by "processing"? Editing the layer such as modifying features, running a tool from the processing toolbox etc? Or do you mean something like: QgsProject.instance().addMapLayer(vlayer)?

    – Joseph
    Mar 6 at 13:00











  • that is the correct answer

    – Ian Turton
    Mar 6 at 13:05











  • Any sort of process that changes the layer features

    – Ian Turton
    Mar 6 at 13:05











  • You can see in the PyQGIS cookbook how to add a QgsVectorLayer to the project docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…

    – etrimaille
    Mar 6 at 15:33











  • @etrimaille - thanks, I spotted that soon after I got the answer here :-)

    – Ian Turton
    Mar 7 at 8:02








1




1





Can you expand on what you mean by "processing"? Editing the layer such as modifying features, running a tool from the processing toolbox etc? Or do you mean something like: QgsProject.instance().addMapLayer(vlayer)?

– Joseph
Mar 6 at 13:00





Can you expand on what you mean by "processing"? Editing the layer such as modifying features, running a tool from the processing toolbox etc? Or do you mean something like: QgsProject.instance().addMapLayer(vlayer)?

– Joseph
Mar 6 at 13:00













that is the correct answer

– Ian Turton
Mar 6 at 13:05





that is the correct answer

– Ian Turton
Mar 6 at 13:05













Any sort of process that changes the layer features

– Ian Turton
Mar 6 at 13:05





Any sort of process that changes the layer features

– Ian Turton
Mar 6 at 13:05













You can see in the PyQGIS cookbook how to add a QgsVectorLayer to the project docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…

– etrimaille
Mar 6 at 15:33





You can see in the PyQGIS cookbook how to add a QgsVectorLayer to the project docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…

– etrimaille
Mar 6 at 15:33













@etrimaille - thanks, I spotted that soon after I got the answer here :-)

– Ian Turton
Mar 7 at 8:02





@etrimaille - thanks, I spotted that soon after I got the answer here :-)

– Ian Turton
Mar 7 at 8:02










1 Answer
1






active

oldest

votes


















4
















  • To add an existing single layer:



    vlayer = QgsVectorLayer("some/path/to/shapefile.shp", "admin", "ogr")
    QgsProject.instance().addMapLayer(vlayer)







  • To add existing multiple layers:



    vlayer1 = QgsVectorLayer("some/path/to/shapefile1.shp", "admin1", "ogr")
    vlayer2 = QgsVectorLayer("some/path/to/shapefile2.shp", "admin2", "ogr")
    layers = [vlayer1 , vlayer2]
    QgsProject.instance().addMapLayers(layers)







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',
    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%2f314564%2fhow-to-add-an-existing-qgsvectorlayer-to-qgis-project%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









    4
















    • To add an existing single layer:



      vlayer = QgsVectorLayer("some/path/to/shapefile.shp", "admin", "ogr")
      QgsProject.instance().addMapLayer(vlayer)







    • To add existing multiple layers:



      vlayer1 = QgsVectorLayer("some/path/to/shapefile1.shp", "admin1", "ogr")
      vlayer2 = QgsVectorLayer("some/path/to/shapefile2.shp", "admin2", "ogr")
      layers = [vlayer1 , vlayer2]
      QgsProject.instance().addMapLayers(layers)







    share|improve this answer




























      4
















      • To add an existing single layer:



        vlayer = QgsVectorLayer("some/path/to/shapefile.shp", "admin", "ogr")
        QgsProject.instance().addMapLayer(vlayer)







      • To add existing multiple layers:



        vlayer1 = QgsVectorLayer("some/path/to/shapefile1.shp", "admin1", "ogr")
        vlayer2 = QgsVectorLayer("some/path/to/shapefile2.shp", "admin2", "ogr")
        layers = [vlayer1 , vlayer2]
        QgsProject.instance().addMapLayers(layers)







      share|improve this answer


























        4












        4








        4









        • To add an existing single layer:



          vlayer = QgsVectorLayer("some/path/to/shapefile.shp", "admin", "ogr")
          QgsProject.instance().addMapLayer(vlayer)







        • To add existing multiple layers:



          vlayer1 = QgsVectorLayer("some/path/to/shapefile1.shp", "admin1", "ogr")
          vlayer2 = QgsVectorLayer("some/path/to/shapefile2.shp", "admin2", "ogr")
          layers = [vlayer1 , vlayer2]
          QgsProject.instance().addMapLayers(layers)







        share|improve this answer















        • To add an existing single layer:



          vlayer = QgsVectorLayer("some/path/to/shapefile.shp", "admin", "ogr")
          QgsProject.instance().addMapLayer(vlayer)







        • To add existing multiple layers:



          vlayer1 = QgsVectorLayer("some/path/to/shapefile1.shp", "admin1", "ogr")
          vlayer2 = QgsVectorLayer("some/path/to/shapefile2.shp", "admin2", "ogr")
          layers = [vlayer1 , vlayer2]
          QgsProject.instance().addMapLayers(layers)








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 6 at 13:24









        JosephJoseph

        58.8k7102207




        58.8k7102207






























            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%2f314564%2fhow-to-add-an-existing-qgsvectorlayer-to-qgis-project%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

            Aardman Animations

            Are they similar matrix

            “minimization” problem in Euclidean space related to orthonormal basis