I've had lots of problems getting models to run that are exported from other-wise working QGIS graphic models. Searching previous questions, apparently this "save as python" functionality went away in previous versions of QGIS but is back on the v2.18.7 version that I am using on my Mac (OS X Yosemite 10.10.5).
The problem seems to arise whenever I try to either string output of one step into the next, or save output to a file (rather than just temporary output). In all the problem cases I have been able to do operations successfully in the graphic model buildier but these fail when I export to Python and attempt to run them within the QGIS script editor processing framework.
Here's an example: This version works (note that no output is saved):
##Warp2ImagesWORKED=name
##m02=raster
##m01=raster
outputs_GDALOGRWARPREPROJECT_1=processing.runalg('gdalogr:warpreproject', m01,'EPSG:4326','EPSG:32616',None,500.0,0,['-87.75,-83.1, 10.65, 15.1'],'EPSG:4326',1,0,75.0,6.0,1.0,False,0,False,None,None)
outputs_GDALOGRWARPREPROJECT_2=processing.runalg('gdalogr:warpreproject', m02,'EPSG:4326','EPSG:32616',None,500.0,0,['-87.75, -83.1, 10.65, 15.1'],'EPSG:4326',1,0,75.0,6.0,1.0,False,0,False,None,None)
However, when I attempt to save output to a file, it crashes. This is the output from save as python:
##Warp2ImagesCRASH=name
##m02=raster
##m01=raster
##mout=output raster
##mout=output raster
outputs_GDALOGRWARPREPROJECT_1=processing.runalg('gdalogr:warpreproject', m01,'EPSG:4326','EPSG:32616',None,500.0,0,['-87.75,-83.1, 10.65, 15.1'],'EPSG:4326',1,0,75.0,6.0,1.0,False,0,False,None,mout)
outputs_GDALOGRWARPREPROJECT_2=processing.runalg('gdalogr:warpreproject', m02,'EPSG:4326','EPSG:32616',None,500.0,0,['-87.75, -83.1, 10.65, 15.1'],'EPSG:4326',1,0,75.0,6.0,1.0,False,0,False,None,mout)
The processing output this gives is:
2017-06-14T17:40:35 1 Error: Wrong parameter value: ['-87.75,-83.1, 10.65, 15.1'] 2017-06-14T17:40:35 1 Error: Wrong parameter value: ['-87.75, -83.1, 10.65, 15.1'] 2017-06-14T17:40:35 2 Error loading result layer: Traceback (most recent call last): File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/gui/Postprocessing.py", line 75, in handleAlgorithmResults out.name)) File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/tools/dataobjects.py", line 199, in load + '\nCheck the processing framework log to look for errors') RuntimeError: Could not load layer: /var/folders/8y/6924gdvx3jg6k2rz5yrzwz100000gr/T/processinge2fea9e1d32a408384b155e3ab4b6db5/9dbcc9629f5e4191bb177b1b7627186c/mout.tif Check the processing framework log to look for errors 2017-06-14T17:40:35 2 Error loading result layer: Traceback (most recent call last): File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/gui/Postprocessing.py", line 75, in handleAlgorithmResults out.name)) File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/tools/dataobjects.py", line 199, in load + '\nCheck the processing framework log to look for errors') RuntimeError: Could not load layer: /var/folders/8y/6924gdvx3jg6k2rz5yrzwz100000gr/T/processinge2fea9e1d32a408384b155e3ab4b6db5/9dbcc9629f5e4191bb177b1b7627186c/mout.tif Check the processing framework log to look for errors
I do not know what the "processing framework log" is but perhaps it is the one that pops up as you are processing? In any event here is that:
Algorithm Warp2ImagesCRASH starting... Converting outputs Loading resulting layers
The following layers were not correctly generated. mout mout You can check the log messages to find more information about the execution of the algorithm
At first I thought the problem might be the two ##mout with the same names, so I renamed them to mout01 and mout02, respectively, but that yields the same error. I've read that warp in GDAL can be tricky at times, but given that these have worked in graphic model and in python when no output is saved, I don't think that is the cause here.
Is there any way to use the Save As Python to make these operations work?
I have basically nonexistent Python skills- just relying on experience with R and other programing environments and doing really basic editing of generated code.