[Qgis-developer] [Feature][Processing] Headless

Victor Olaya volayaf at gmail.com
Fri Dec 20 00:42:06 PST 2013


Hi

sorry for the late reply

This looks great to me. I have just merged it and made a minor
cosmetic change to a line of code, but it's great to see that there is
a way of running headless Processing.

More valuable than the pull request is actually the script that you
provide. Where do you think it would be the best place to put it?
Maybe in the PyQGIS cookbook?

One little thing. In these lines:

alg = Processing.getAlgorithm( 'qgis:fixeddistancebuffer' )
general.runalg( 'qgis:fixeddistancebuffer', '/vector/layer/input/uri',
0.1, 5, False, '/vector/layer/output.shp' );

You actually do not need the first one. If you get the algorithm, you
can then run it using the alg object, but the second line should work
without the first one.

Many thanks again for this contribution!

2013/12/16 rldhont <rldhont at gmail.com>:
> Hi dev,
>
> I just created a pull request to run QGIS-Processing headless.
> I have tested it with a qgis and a modeler algorithm.
>
> https://github.com/qgis/QGIS/pull/1031
>
> Review and comments are welcome
>
> To test QGIS Processing algorithm headlessly, you can use this python code
> __________________________________
>
> import sys, os
> import inspect
>
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> from qgis.core import *
>
>
> # supply path to where is your qgis installed
> QgsApplication.setPrefixPath("/path/to/your/qgis/build", True)
>
> # load providers
> QgsApplication.initQgis()
>
> # load a project
> p = QgsProject.instance()
> p.read( QFileInfo( "/path/to/a/project.qgs" ) )
>
> # init QApplication for processing
> a = QApplication( sys.argv )
>
> # init QGIS Processing
> from processing.core.Processing import Processing
> cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
> if cmd_folder not in sys.path:
>     sys.path.insert(0, cmd_folder)
> Processing.initialize()
>
> # import QGIS Processing tools
> from processing.tools import *
>
> # print an algorithms search
> general.alglist( 'buffer')
>
> # print an algorithm help
> general.help( 'qgis:fixeddistancebuffer' )
>
>
> # run an algorithm
> alg = Processing.getAlgorithm( 'qgis:fixeddistancebuffer' )
> general.runalg( 'qgis:fixeddistancebuffer', '/vector/layer/input/uri', 0.1,
> 5, False, '/vector/layer/output.shp' );
>
> # quit
> QgsApplication.exitQgis()
> ____________________________
>
> export
> PYTHONPATH=/path/to/build/share/qgis/python:/path/to/build/share/qgis/python/plugins
> export LD_LIBRARY_PATH=/path/to/build/lib
> python my_scrpit.py
> _____________________________
>
> Regards
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the Qgis-developer mailing list