Monday, 7 March 2016

python - How to use SEXTANTE in a script outside QGIS?


I´m trying to do some geoprocessing using the QGIS Sextante plugin outside of the QGIS application (and integrate it with different other libraries like arcpy, etc.).


import sys, os
from PyQt4.QtGui import QApplication
QApplication(sys.argv)
from qgis.core import *
import qgis.utils

sys.path.append("C:/Users/.../.qgis/python/plugins")


import sextante
sextante.core.Sextante.Sextante.initialize()
input = "D:/Python_Test/a.shp"
output = "D:/Python_Test/b.shp"

sextante.runalg("qgis:convexhull",input,None,None,output)
print "Finished!"

Unfortunately the process fails with the following error:


Traceback (most recent call last):

File "", line 1, in
File "C:/Users/.../.qgis/python/plugins\sextante\core\Sextante.py", line 376, in runalg
alg = Sextante.runAlgorithm(algOrName, None, *args)
File "C:/Users/.../.qgis/python/plugins\sextante\core\Sextante.py", line 276, in runAlgorithm
if not param.setValue(args[i]):
File "C:/Users/.../.qgis/python/plugins\sextante\parameters\ParameterVector.py", line 59, in setValue
layers = QGisLayers.getVectorLayers(self.shapetype)
File "C:/Users/.../.qgis/python/plugins\sextante\core\QGisLayers.py", line 79, in getVectorLayers
layers = QGisLayers.iface.legendInterface().layers()
AttributeError: 'NoneType' object has no attribute 'legendInterface'


What am I doing wrong? Sextante seems to be initialized correctly because


sextante.alghelp("qgis:convexhull")

gives me


ALGORITHM: Convex hull
INPUT
FIELD
METHOD
OUTPUT


I´m using Windows 7 Professional 64Bit and the OsGeo4W installation with QGIS 1.8.0 and python 2.7.4.



Answer



The accepted answer to the following question answers this question as well:


Access Sextante (processing) in standalone QGIS app?


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...