3

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()
5
  • You are trying to access sextante not the console. So I will retitle you question.
    – Nathan W
    Sep 18, 2013 at 10:04
  • What version of QGIS are you running?
    – Nathan W
    Sep 18, 2013 at 10:05
  • I´m using QGIS 1.8 on a Windows 7 machine
    – Martin
    Sep 18, 2013 at 10:44
  • What is the error you are getting?
    – Nathan W
    Sep 18, 2013 at 10:55
  • I still get the error mentioned in a different question: gis.stackexchange.com/questions/68166/…. I understand, that calling Sextante from outside QGIS is not working directly. That´s why I started trying to adress the QGIS python console to run Sextante there.
    – Martin
    Sep 18, 2013 at 11:01

2 Answers 2

1

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.

4
  • Thanks for the information. If I unterstand you right, there is no possibility to use SEXTANTE algorithms outside of QGIS, neither in a python script, nor in a standalone app. I´m waiting eagerly for an implementation then. SEXTANTE could really be an easy to use OS alternative to ArcPy.
    – Martin
    Sep 18, 2013 at 11:19
  • You can you it in a Python script that is run inside QGIS, like a plugin for example, but not in a standalone app.
    – Nathan W
    Sep 18, 2013 at 11:29
  • 1
    I was just having a look at the code and it should be easy enough to fix the code to work outside of the UI. Some of it anyway
    – Nathan W
    Sep 18, 2013 at 11:36
  • It would be really great if the code could be changed without big trouble!! Being able to use Sextante/Qgis Processing in standalone scripts would open up many new possibilities. BTW: Could you post your answer as answer to my other question, too?
    – Martin
    Sep 18, 2013 at 14:18
1

For new users reading this post, 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.

1
  • And the reason for the downvote is...? Jan 15, 2015 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.