[Qgis-developer] [Feature][Processing] Headless
rldhont
rldhont at gmail.com
Mon Dec 16 06:46:28 PST 2013
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
More information about the Qgis-developer
mailing list