[Qgis-user] How to run SEXTANTE algorithms outside of QGIS Python console?

Martin Lacayo mlacayo at stanford.edu
Wed May 15 09:06:44 PDT 2013


Hi Paolo,

I just disabled digest mode, but hopefully this will be part of the same thread.

My question is more specifically about SEXTANTE, if there is a better
forum for this please let me know.

My question is how to run SEXTANTE algorithms outside of QGIS Python
console. Is this possible? The closest answer I found was on
StackExchange here:

http://gis.stackexchange.com/questions/28701/how-to-run-sextante-algorithms-outside-of-qgis-python-console

The code provided runs, but when I add a call to sextante.runalg it
raises an error related to iface, which seems to be something from
QgisInterface.instance(). Specifically I get an AttributeError because
iface == None. Another related post indicated that this kind of error
is because the code is being run outside of QGIS and therefore there
is no iface that could be referenced. In the code there is a commented
out line that looks like a QGIS instance is wanted, but it wasn't
working. Any suggestions?

What would be most helpful is if someone could modify the code to
include a single SEXTANTE call that executes any algorithm, preferable
one from GRASS.

Thank you.

Here is the code:

import sys
from PyQt4.QtGui import QApplication
from sextante.core.Sextante import Sextante

def main():
    """ main function or something """
    # as per http://qgis.org/pyqgis-cookbook/intro.html#using-pyqgis-in-custom-application
    from qgis.core import *
    import qgis.utils

    app = QApplication(sys.argv)
    # supply path to where is your qgis installed
    QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
    # load providers
    QgsApplication.initQgis()
    # how???
    # qgis.utils.iface = QgisInterface.instance()
    Sextante.initialize()
    run_script(qgis.utils.iface)

def run_script(iface):
    """ this shall be called from Script Runner"""
    Sextante.alglist()
    Sextante.alghelp("saga:slopeaspectcurvature")

if __name__=="__main__":
    main()



-Martin

> Date: Wed, 15 May 2013 08:06:57 +0200
> From: Paolo Cavallini <cavallini at faunalia.it>
> To: qgis-user at lists.osgeo.org
> Subject: Re: [Qgis-user] How to run SEXTANTE algorithms outside of
>         QGIS Python console?
> Message-ID: <51932601.9080705 at faunalia.it>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Il 14/05/2013 23:04, Martin Lacayo ha scritto:
>
>> Our software (naturalcapitalproject.org) is developed on Linux but
>> packaged for Windows.
>
> Hi Martin,
> could you please let us know more about this?
> I do not see any reference to QGIS.
> All the best.
> - --
> Paolo Cavallini - Faunalia
> www.faunalia.eu
> Full contact details at www.faunalia.eu/pc
> Nuovi corsi QGIS e PostGIS: http://www.faunalia.it/calendario
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAlGTJgEACgkQ/NedwLUzIr60JgCeMZzOh+96CESwhbjdKFZ9Hlg4
> BycAnicpMj4TZosMXotgIg9Xo+luGxtu
> =j3ao
> -----END PGP SIGNATURE-----
>
>



More information about the Qgis-user mailing list