I am trying to use the QGIS functions in a stand alone Python script. I'm running Mountain Lion OS, 2.7 Python & the QQGISis 2.0.1 Dufour.
My main problem is that I cannot get started - I cannot load a simple shapefile in order to buffer it. After searching the online resources quite a bit, I actually found that many people had a problem with setting the prefix path, so I ran the QgsApplication.showSettings()
to identify it.
The code I'm running now is:
QgsApplication.setPrefixPath("/Applications/QGIS.app/Contents", True)
QgsApplication.initQgis()
print QgsApplication.showSettings()
#Loading a Layer
layer = QgsVectorLayer('/path/to/shapefile_folder/test.shp', 'test', 'ogr')
if not layer.isValid():
print "The layer failed to load."
#finally I d like to apply a buffer, sth like that maybe?
buffer_Shp = layer.buffer(10, 5)
Here is the result I get:
Application state:
QGIS_PREFIX_PATH env var:
Prefix: /Applications/QGIS.app/Contents
Plugin Path: /Applications/QGIS.app/Contents/../PlugIns/qgis
Package Data Path: /Applications/QGIS.app/Contents/../Resources
Active Theme Name:
Active Theme Path: :/images/themes//
Default Theme Path: :/images/themes/default/
SVG Search Paths: /Applications/QGIS.app/Contents/../Resources/svg/
User DB Path: /Applications/QGIS.app/Contents/../Resources/resources/qgis.db
"The Layer Failed to load" (obviously)
bash_profile (in case that sth is wrong there)
/# Setting PATH for Python 2.7
/# The orginal version is saved in .bash_profile.pysave
/######export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH
/#adding Qgis libs
export DYLD_LIBRARY_PATH=/Applications/QGIS.app/Contents/MacOS/lib/:/Applications/QGIS.app/Contents/Frameworks/
export PYTHONPATH=/Applications/QGIS.app/Contents/Resources/python/
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
/# Added by Canopy installer on 2013-10-06
/# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
/# VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/george/Library/Enthought/Canopy_64bit/User/bin/activate
What the heck am I missing?
No comments:
Post a Comment