2

I am trying to follow PYQGIS documentation for loading a shapefile from inside a script.

http://www.qgis.org/pyqgis-cookbook/intro.html

I was able to set the datasource and run the QgsVectorLayer command from the python console inside QGIS so I am guessing my problem is in the setPrefixPath() portion. Using the 'which qgis' command I got /usr/bin/qgis so that is the path I used. Any help would be appreciated.

from qgis.core import *
import qgis.utils

QgsApplication.setPrefixPath('/usr/bin/qgis', True)
QgsApplication.initQgis()

ds = '/home/user/shapefiles/nodes.shp'

nodes = QgsVectorLayer(ds, 'nodes', 'ogr')
if not nodes.isValid():
    print "Layer failed to load!"
1
  • 1
    For what its worth... gis.stackexchange.com/questions/28077/… Solution was to change... QgsApplication.setPrefixPath('/usr/bin/qgis', True) to... QgsApplication.setPrefixPath('/usr', True)
    – Jeff
    Aug 20, 2013 at 23:54

0

Your Answer

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

Browse other questions tagged or ask your own question.