I am running a script in QGIS which loops around a set of rasters performing a number of different processes ultimately outputting a new raster and a vector per input. At the end of each loop i get the error message 'python.exe has stopped working' but my output is still created and saved in the destination folder.

The script I am using is as follows:

##Input_raster=multiple raster

import os

layers = Input_raster.split(';')
for raster in layers:
    #Names for output
    result_name = os.path.splitext(os.path.basename(raster)) [0] + "_Extent.tif"
    shp_name = os.path.splitext(os.path.basename(raster)) [0] + "_Outline.shp"

    #Take grid and create extent
    out1=processing.runalg('gdalogr:rastercalculator', raster,'1',None,'1',None,'1',None,'1',None,'1',None,'1','A>0',None,5,None,result_shp + "/" + result_name)
    #Ratser extent to polygon
    out2=processing.runalg('gdalogr:polygonize', out1['OUTPUT'],'DN',None)
    #Calculate area m^2 and add to new field 'Area_m2'
    out3=processing.runalg('qgis:fieldcalculator', out2['OUTPUT'],'Area_m2',0,10.0,3.0,True,'$area',None)
    #Select polygons >5m^2 and extract to new shp
    out4=processing.runalg('qgis:extractbyattribute', out3['OUTPUT_LAYER'],'Area_m2',3,'5',None)
    #Fill holes less than 200m^2
    out5=processing.runalg('qgis:fillholes', out4['OUTPUT'],200.0,result_shp + "/" + shp_name)

Is there a reason this might be occurring for each loop?

Do i need to somehow 'close' the input or output at the end of each loop to avoid this happening?

I have now run the same process using QGIS Graphical Modeller and found the same error stopping the process at step 1 GDAL raster calculator. When I view the log the final message given is 'GDAL command output:'

  • This seems to be a common problem when using this tool: trac.osgeo.org/osgeo4w/ticket/466 – AJ Walsh Nov 17 '16 at 11:34
  • I'm having a similar issue. Whenever I run gdal2xyz inside Qgis (64bit, running on windows 7 and Python 2.7.5) it crashes ("python.exe has stopped working"). In my case I was extracting data from a raster in GeoTIFF(which is a product of gdal's conversion from NetCDF) to a CSV file and the operation is apparently successful as the number of lines in the resultant CSV matches the original and the numbers seem coherent with the original TIFF data. It is very annoying and disruptive to press the "close this program" button that pops up at the end of every single one of 122 operations in a batch r – Bontempo Apr 5 '17 at 13:55
  • I have also a similar issue with gdalogr:merge. I try to merge multiple rasters. It merges but it prints me"python.exe has stopped working" – J.Delannoy Jul 10 '17 at 14:02

Browse other questions tagged or ask your own question.