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

rldhont rldhont at gmail.com
Fri Jan 3 06:52:50 PST 2014


Hi Salvatore,

Thanks! I'm working on a python class to easily publishing process based 
on PyWPS and QGIS-Processing.

I have updated my script exemple :
======================
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os
import inspect

#first qgis
from qgis.core import *
#next PyQt4
from PyQt4.QtCore import *
from PyQt4.QtGui import *

# init QApplication for processing and set the customSettingFolder
#a = QApplication( sys.argv )
QgsApplication( sys.argv, False, "/my/custom/path" )

# supply path to where is your qgis installed
QgsApplication.setPrefixPath("/my/build", True)

# load providers
QgsApplication.initQgis()

p = QgsProject.instance()
p.read( QFileInfo( "/my/project.qgs" ) )
print p.title()

mlr = QgsMapLayerRegistry.instance()

qa = QApplication( sys.argv )
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()

from processing.tools import *
#general.alglist( 'znt' )

#general.alghelp( 'modeler:znt' )

paramalg = []

print "runalg start"
general.runalg( 'process:identifier', *paramalg )
print "runalg end"

# quit
QgsApplication.exitQgis()
#a.exit()
QApplication.exit()
======================

Regards,
René-Luc D'Hont
3Liz

Le 02/01/2014 21:52, Salvatore Larosa a écrit :
> Hi,
>
> I just tested it and works wonderfully!
> I also have tried it as web process for PyWPS and works very well!
>
> Thanks a lot for this!
>
> Best Regards,
> -SL
>
> On Mon, Dec 16, 2013 at 3:46 PM, rldhont <rldhont at gmail.com> wrote:
>
>     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
>
>
>
>
> -- 
> Salvatore Larosa
> linkedIn: http://linkedin.com/in/larosasalvatore
> twitter: @lrssvt
> skype: s.larosa
> IRC: lrssvt on freenode

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140103/03f1adc2/attachment-0001.html>


More information about the Qgis-developer mailing list