Using QGIS processing tools in standalone script?

The arguments are:

runAlgorithm(algOrName, onFinish, *args, **kwargs)

Set the onFinish argument to None (i.e. no post-processing)

However, by the looks of it you are just wanting to run GDAL Warp. May I suggest you go for a simpler approach for any of the GDAL functions? QGIS is a wrapper around GDAL so for a stand-alone process why involve QGIS at all? Cut out the middle-man and use the GDAL bindings directly in Python. This is not only simpler, it is also more portable. Bundled in GDAL (and therefore QGIS) you will find a standalone exe version of GDAL Warp (and others) ready to go and that may be all you need.

In a standard install, you'll find the GDAL Python libraries and standalone exe files in the bin folder (e.g. C:/OSGeo4W64/bin on my machine). On a machine without QGIS you can install the GDAL bindings from here (I recommend the GISInternals site for Windows). You only need to do this is you move your code to a machine without QGIS of course. Numpy and SciPy are also similarly available and usable without the QGIS wrapper.

In the case of GDAL Warp (or any of the GDAL exe processes) you can call the exe as a subprocess from Python or use it directly on the commandline.


I'm not completely sure but when I run processing tools from a standalone script, I call general.runalg("qgis:...") but this probably depends how you set up your paths and imports. Also, since you're using processing, you may need to call gdalogr:warpreproject (when you run this inside QGIS, you can see the various parameters required) instead of gdalwarp.

So perhaps try running:

general.runalg("gdalogr:warpreproject", "/home/steph/Temp/python_tmp/input/dsm.tif", "EPSG:32642", "+proj=tmerc +lat_0=0 +lon_0=74.51666666666667 +k=1 +x_0=3300000 +y_0=14743.5 +ellps=GRS80 +units=m +no_defs", -9999, 0, 0, 0, 0, 1, 1, 3, False, 0, False, "", "/home/steph/Temp/python_tmp/output/20160813-1225-UAVanalyse/dsm_proj.tif")