7

I am using qgis2.6 version and new to pyQGIS. I tried to load a vector file using python console in qgis. I don't know where I am wrong. The layer was not loaded and does not show any error too. Help would be appreciated.The code which i tried is below.

wb = QgsVectorLayer('C:\Users\new\Desktop\PyQGIS\pyqgis_data\world_borders.shp', 'world_borders', 'ogr') QgsMapLayerRegistry.instance().addMapLayer(wb)

enter image description here

enter image description here

asked Jan 4, 2015 at 15:21
5
  • I cannot see the image. What kind of layer are you trying to load? Did you try the recipes given by PyQGIS Cookbook? docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/… Commented Jan 4, 2015 at 15:50
  • I tried loading a shapefile. I tried the recipes given in 'The PyQGIS Programmer's Guide'. Commented Jan 4, 2015 at 16:03
  • did you try to refresh the mapcanvas? Commented Jan 4, 2015 at 16:12
  • Yeah i did.Still it doesn't work. Commented Jan 4, 2015 at 16:22
  • Add r prefix before path string: r'C:\Users\....' Commented Apr 12, 2018 at 11:54

2 Answers 2

6

I don't have a Windows OS to test it, but I'm pretty sure the problem is in the path to your ShapeFile. Make sure the path is correct and try with slashes (/) or double back slashes (\\).

answered Jan 4, 2015 at 16:38
0
2

Add following from qgis.core import * and try to run again if still doesn't work

answered Feb 23, 2016 at 13:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.