Sextante is addressable via python using the QGIS python console (unfortunately not from outside QGIS). I´m writing a standalone app and want to include Sextante geoprocessing functionality. In QGIS python console this is working perfectly. Is it possible to address the console from an outside python script (standalone app)?
My code so far:
import sys, os
from PyQt4.QtGui import QApplication, QAction, QMainWindow
from PyQt4.QtCore import SIGNAL, Qt, QString
app = QApplication(sys.argv)
from qgis.core import *
import qgis.utils
import qgis.gui
QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis")
QgsApplication.initQgis()
sys.path.append("C:/Users/.../.qgis/python/plugins")
sys.path.append("C:/OSGeo4W/apps/qgis/python/plugins")
sys.path.append("C:/Users/.../.qgis/python/plugins/sextante")
import sextante
sextante.core.Sextante.Sextante.initialize()
map = qgis.gui.QgsMapCanvas()
layer = QgsVectorLayer("D:/Python_Test/a.shp",'a','ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer)
map.setExtent(layer.extent())
map.setLayerSet( [ qgis.gui.QgsMapCanvasLayer(layer) ] )
output = "D:/Python_Test/b.shp"
sextante.runalg("qgis:convexhull",layer,None,None,output)
QgsApplication.exitQgis()
Answer
Currently this is not possible. SEXTATNE has not been designed to run outside of the QGIS GUI yet. The error you are getting is related to variable iface
that is not created when running from from a standalone app.
iface
is created by QGIS when running the full app in order to allow you to access methods on the current instance of QGIS.
So the answer is: Planned. Not implemented.
No comments:
Post a Comment