Loading vector layer in Python console?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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
    Jan 31 at 13:48















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
    Jan 31 at 13:48













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 Jan 31 at 21:57









PolyGeo

53.5k1780240




53.5k1780240










asked Jan 31 at 13:23









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
    Jan 31 at 13:48












  • 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
    Jan 31 at 13:48







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
Jan 31 at 13:48





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
Jan 31 at 13:48










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
      Jan 31 at 14:34











    • 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
      Jan 31 at 14:46











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

      – Bodhi
      Jan 31 at 14:47










    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 Jan 31 at 13:43









        JosephJoseph

        57.4k7100197




        57.4k7100197























            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
              Jan 31 at 14:34











            • 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
              Jan 31 at 14:46











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

              – Bodhi
              Jan 31 at 14:47















            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
              Jan 31 at 14:34











            • 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
              Jan 31 at 14:46











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

              – Bodhi
              Jan 31 at 14:47













            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 Jan 31 at 14:08

























            answered Jan 31 at 13:54









            artwork21artwork21

            31k554120




            31k554120












            • 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
              Jan 31 at 14:34











            • 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
              Jan 31 at 14:46











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

              – Bodhi
              Jan 31 at 14:47

















            • 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
              Jan 31 at 14:34











            • 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
              Jan 31 at 14:46











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

              – Bodhi
              Jan 31 at 14:47
















            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
            Jan 31 at 14:34





            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
            Jan 31 at 14:34













            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
            Jan 31 at 14:46





            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
            Jan 31 at 14:46













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

            – Bodhi
            Jan 31 at 14:47





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

            – Bodhi
            Jan 31 at 14:47

















            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

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?