Loading vector layer in Python console?












0















I am trying to load a vector file to QGIS Python console.





v_layer = iface.addVectorLayer("G://ConsultancyDataTransferBodhi (Louis) GorringeQGISShapefilesBiological ShapefilesSeabirdsAt sea densities of gannet in the breeding season710_br.shp")


Below identifies the error code I always get when I enter this script.



enter image description here



From looking at other examples online it seems that they add a bit at the end of the script within single quote marks ('). As seen in the image below in the red box.



enter image description here



I am aware this is specified for where they have saved their documents, but I am unaware of what the (') columns mean. I feel this is the reason why my vector layer wont load. Can anyone confirm, or know a reason why the vector layer wont loads?










share|improve this question




















  • 3





    Please remember to include the error text as ASCII in the body of your question. Images are not legible on all devices and are not searchable.

    – Vince
    yesterday
















0















I am trying to load a vector file to QGIS Python console.





v_layer = iface.addVectorLayer("G://ConsultancyDataTransferBodhi (Louis) GorringeQGISShapefilesBiological ShapefilesSeabirdsAt sea densities of gannet in the breeding season710_br.shp")


Below identifies the error code I always get when I enter this script.



enter image description here



From looking at other examples online it seems that they add a bit at the end of the script within single quote marks ('). As seen in the image below in the red box.



enter image description here



I am aware this is specified for where they have saved their documents, but I am unaware of what the (') columns mean. I feel this is the reason why my vector layer wont load. Can anyone confirm, or know a reason why the vector layer wont loads?










share|improve this question




















  • 3





    Please remember to include the error text as ASCII in the body of your question. Images are not legible on all devices and are not searchable.

    – Vince
    yesterday














0












0








0








I am trying to load a vector file to QGIS Python console.





v_layer = iface.addVectorLayer("G://ConsultancyDataTransferBodhi (Louis) GorringeQGISShapefilesBiological ShapefilesSeabirdsAt sea densities of gannet in the breeding season710_br.shp")


Below identifies the error code I always get when I enter this script.



enter image description here



From looking at other examples online it seems that they add a bit at the end of the script within single quote marks ('). As seen in the image below in the red box.



enter image description here



I am aware this is specified for where they have saved their documents, but I am unaware of what the (') columns mean. I feel this is the reason why my vector layer wont load. Can anyone confirm, or know a reason why the vector layer wont loads?










share|improve this question
















I am trying to load a vector file to QGIS Python console.





v_layer = iface.addVectorLayer("G://ConsultancyDataTransferBodhi (Louis) GorringeQGISShapefilesBiological ShapefilesSeabirdsAt sea densities of gannet in the breeding season710_br.shp")


Below identifies the error code I always get when I enter this script.



enter image description here



From looking at other examples online it seems that they add a bit at the end of the script within single quote marks ('). As seen in the image below in the red box.



enter image description here



I am aware this is specified for where they have saved their documents, but I am unaware of what the (') columns mean. I feel this is the reason why my vector layer wont load. Can anyone confirm, or know a reason why the vector layer wont loads?







pyqgis qgis-python-console






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









PolyGeo

53.4k1780239




53.4k1780239










asked yesterday









BodhiBodhi

17612




17612








  • 3





    Please remember to include the error text as ASCII in the body of your question. Images are not legible on all devices and are not searchable.

    – Vince
    yesterday














  • 3





    Please remember to include the error text as ASCII in the body of your question. Images are not legible on all devices and are not searchable.

    – Vince
    yesterday








3




3





Please remember to include the error text as ASCII in the body of your question. Images are not legible on all devices and are not searchable.

– Vince
yesterday





Please remember to include the error text as ASCII in the body of your question. Images are not legible on all devices and are not searchable.

– Vince
yesterday










2 Answers
2






active

oldest

votes


















4














These are mentioned in the QGIS documentation:



layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")




So the parameters are:




  1. Path to shapefile;

  2. The name you want to give to the shapefile when it is loaded;

  3. The name of the vector data source/provider.






share|improve this answer































    3














    Along with @Joseph answer, the shp path has both "/" and "" characters which will cause other errors. Here are three examples of valid slash path options:



    # three valid shp path options
    layer = iface.addVectorLayer("C:/path/to/shapefile/file.shp", "layer name you like", "ogr")
    layer = iface.addVectorLayer("C:\path\to\shapefile\file.shp", "layer name you like", "ogr")
    layer = iface.addVectorLayer(r"C:pathtoshapefilefile.shp", "layer name you like", "ogr")





    share|improve this answer


























    • will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

      – Bodhi
      yesterday











    • Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

      – artwork21
      yesterday











    • Thankyou both, and sounds good to me. Will do it now

      – Bodhi
      yesterday











    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%2f310614%2floading-vector-layer-in-python-console%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









    4














    These are mentioned in the QGIS documentation:



    layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")




    So the parameters are:




    1. Path to shapefile;

    2. The name you want to give to the shapefile when it is loaded;

    3. The name of the vector data source/provider.






    share|improve this answer




























      4














      These are mentioned in the QGIS documentation:



      layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")




      So the parameters are:




      1. Path to shapefile;

      2. The name you want to give to the shapefile when it is loaded;

      3. The name of the vector data source/provider.






      share|improve this answer


























        4












        4








        4







        These are mentioned in the QGIS documentation:



        layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")




        So the parameters are:




        1. Path to shapefile;

        2. The name you want to give to the shapefile when it is loaded;

        3. The name of the vector data source/provider.






        share|improve this answer













        These are mentioned in the QGIS documentation:



        layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")




        So the parameters are:




        1. Path to shapefile;

        2. The name you want to give to the shapefile when it is loaded;

        3. The name of the vector data source/provider.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        JosephJoseph

        56.9k799195




        56.9k799195

























            3














            Along with @Joseph answer, the shp path has both "/" and "" characters which will cause other errors. Here are three examples of valid slash path options:



            # three valid shp path options
            layer = iface.addVectorLayer("C:/path/to/shapefile/file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer("C:\path\to\shapefile\file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer(r"C:pathtoshapefilefile.shp", "layer name you like", "ogr")





            share|improve this answer


























            • will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

              – Bodhi
              yesterday











            • Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

              – artwork21
              yesterday











            • Thankyou both, and sounds good to me. Will do it now

              – Bodhi
              yesterday
















            3














            Along with @Joseph answer, the shp path has both "/" and "" characters which will cause other errors. Here are three examples of valid slash path options:



            # three valid shp path options
            layer = iface.addVectorLayer("C:/path/to/shapefile/file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer("C:\path\to\shapefile\file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer(r"C:pathtoshapefilefile.shp", "layer name you like", "ogr")





            share|improve this answer


























            • will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

              – Bodhi
              yesterday











            • Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

              – artwork21
              yesterday











            • Thankyou both, and sounds good to me. Will do it now

              – Bodhi
              yesterday














            3












            3








            3







            Along with @Joseph answer, the shp path has both "/" and "" characters which will cause other errors. Here are three examples of valid slash path options:



            # three valid shp path options
            layer = iface.addVectorLayer("C:/path/to/shapefile/file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer("C:\path\to\shapefile\file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer(r"C:pathtoshapefilefile.shp", "layer name you like", "ogr")





            share|improve this answer















            Along with @Joseph answer, the shp path has both "/" and "" characters which will cause other errors. Here are three examples of valid slash path options:



            # three valid shp path options
            layer = iface.addVectorLayer("C:/path/to/shapefile/file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer("C:\path\to\shapefile\file.shp", "layer name you like", "ogr")
            layer = iface.addVectorLayer(r"C:pathtoshapefilefile.shp", "layer name you like", "ogr")






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered yesterday









            artwork21artwork21

            30.9k554120




            30.9k554120













            • will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

              – Bodhi
              yesterday











            • Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

              – artwork21
              yesterday











            • Thankyou both, and sounds good to me. Will do it now

              – Bodhi
              yesterday



















            • will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

              – Bodhi
              yesterday











            • Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

              – artwork21
              yesterday











            • Thankyou both, and sounds good to me. Will do it now

              – Bodhi
              yesterday

















            will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

            – Bodhi
            yesterday





            will the name of the vector data source/provide most likley be 'ogr'. I am trying to get used to python scripting and some of my shapefiles dont work with 'ogr' ending. How would I identify the data source/provider for individual shapefiles?

            – Bodhi
            yesterday













            Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

            – artwork21
            yesterday





            Good question, however I would recommend you post that as a new question in this forum and include any error messages you may receive when using the addVectorLayer() method.

            – artwork21
            yesterday













            Thankyou both, and sounds good to me. Will do it now

            – Bodhi
            yesterday





            Thankyou both, and sounds good to me. Will do it now

            – Bodhi
            yesterday


















            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%2f310614%2floading-vector-layer-in-python-console%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?