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!"

Your Answer

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

Browse other questions tagged or ask your own question.