Loading vector layer in Python console?
Clash Royale CLAN TAG#URR8PPP
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.
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.
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
add a comment |
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.
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.
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
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
add a comment |
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.
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.
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
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.
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.
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
pyqgis qgis-python-console
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
These are mentioned in the QGIS documentation:
layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")
So the parameters are:
- Path to shapefile;
- The name you want to give to the shapefile when it is loaded;
- The name of the vector data source/provider.
add a comment |
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")
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
These are mentioned in the QGIS documentation:
layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")
So the parameters are:
- Path to shapefile;
- The name you want to give to the shapefile when it is loaded;
- The name of the vector data source/provider.
add a comment |
These are mentioned in the QGIS documentation:
layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")
So the parameters are:
- Path to shapefile;
- The name you want to give to the shapefile when it is loaded;
- The name of the vector data source/provider.
add a comment |
These are mentioned in the QGIS documentation:
layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")
So the parameters are:
- Path to shapefile;
- The name you want to give to the shapefile when it is loaded;
- The name of the vector data source/provider.
These are mentioned in the QGIS documentation:
layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer name you like", "ogr")
So the parameters are:
- Path to shapefile;
- The name you want to give to the shapefile when it is loaded;
- The name of the vector data source/provider.
answered Jan 31 at 13:43
JosephJoseph
57.4k7100197
57.4k7100197
add a comment |
add a comment |
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")
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
add a comment |
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")
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
add a comment |
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")
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")
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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