1

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 "<interactive input>", line 1, in <module>
  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 <ParameterVector>
    FIELD <ParameterTableField from INPUT>
    METHOD <ParameterSelection>
    OUTPUT <OutputVector>

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

underdark
  • 84,148
  • 21
  • 231
  • 413
Martin
  • 1,273
  • 1
  • 12
  • 23

2 Answers2

2

There is a way of running QGIS processing algorithms in standalone PyQGIS scripts. Check answers to Import error for qgis.core when running OSGeo4w shell script and How can I access `processing` with Python?, which provide you with tested examples.

Germán Carrillo
  • 36,307
  • 5
  • 123
  • 178
1

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

Access Sextante (processing) in standalone QGIS app?

Martin
  • 1,273
  • 1
  • 12
  • 23