This is a follow on from Importing QGIS Processing in stand-alone python script?
I do not understand yet how to call an algorithm from the processing toolbox in a stand-alone Python script.
According to the Qgis documentation, I should use processing.runalg()
but this doesn't seem to exist in my installation. When I do dir(Processing)
I get:
['__doc__', '__module__', 'actions', 'addAlgListListener', 'addProvider', 'algs', 'contextMenuActions', 'fireAlgsListHasChanged', 'getAlgorithm', 'getAlgorithmFromFullName', 'getObject', 'getProviderFromName', 'initialize', 'listeners', 'loadActions', 'loadAlgorithms', 'loadContextMenuActions', 'loadFromProviders', 'modeler', 'providers', 'removeAlgListListener', 'removeProvider', 'runAlgorithm', 'runandload', 'tr', 'updateAlgsList', 'updateProviders']
Is the Qgis doc outdated or do I have a wrong version of something on my machine?
try:
Processing.runAlgorithm('gdalwarp -overwrite -s_srs EPSG:32642 -t_srs "+proj=tmerc +lat_0=0 +lon_0=74.51666666666667 +k=1 +x_0=3300000 +y_0=14743.5 +ellps=GRS80 +units=m +no_defs" /home/steph/Temp/python_tmp/input/dsm.tif /home/steph/Temp/python_tmp/output/20160813-1225-UAVanalyse/dsm_proj.tif')
except:
print 'ERROR ' + str(sys.exc_info())
Gives me:
ERROR (<type 'exceptions.TypeError'>, TypeError('runAlgorithm() takes at least 2 arguments (1 given)',), <traceback object at 0x7fa47898dbd8>)
But I'm not sure what the second argument should be?
While
try:
Processing.runalg('gdalwarp -overwrite -s_srs EPSG:32642 -t_srs "+proj=tmerc +lat_0=0 +lon_0=74.51666666666667 +k=1 +x_0=3300000 +y_0=14743.5 +ellps=GRS80 +units=m +no_defs" /home/steph/Temp/python_tmp/input/dsm.tif /home/steph/Temp/python_tmp/output/20160813-1225-UAVanalyse/dsm_proj.tif')
except:
print 'ERROR ' + str(sys.exc_info())
Gives me:
ERROR (<type 'exceptions.AttributeError'>, AttributeError("class Processing has no attribute 'runalg'",), <traceback object at 0x7f183586abd8>)
Using Qgis 2.16.1 on Ubuntu Xenial 16.04 LTS