6

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

  • 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/… – Germán Carrillo Jan 4 '15 at 15:50
  • I tried loading a shapefile. I tried the recipes given in 'The PyQGIS Programmer's Guide'. – User123 Jan 4 '15 at 16:03
  • did you try to refresh the mapcanvas? – underdark Jan 4 '15 at 16:12
  • Yeah i did.Still it doesn't work. – User123 Jan 4 '15 at 16:22
  • Add r prefix before path string: r'C:\Users\....' – Kadir Şahbaz Apr 12 '18 at 11:54
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 (\\).

  • Yeah i tried with (/) and it works.Thanks. – User123 Jan 4 '15 at 16:57
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.