A script I have written to perform a number of tasks on a single input needs amending to work with multiple inputs given an input folder. The working script is this and takes a input raster through some processes to output a shp:
##in_rast=raster
##out_shp=output vector
#Take grid and create extent
out1=processing.runalg('gdalogr:rastercalculator', in_rast,'1',None,'1',None,'1',None,'1',None,'1',None,'1','A>0',None,5,None,None)
#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,out_shp)
I have made a start on updating this to work on multiple inputs but being relativity new to python my understanding of the correct methods to use has reached its limit. The updated script looks as follows, only working and outputting for the first process:
##Input_raster=multiple raster
##result_ras=folder
import os
layers = Input_raster.split(';')
for raster in layers:
result_name = os.path.splitext(os.path.basename(raster)) [0] + "_Extent.tif"
out1=processing.runalg('gdalogr:rastercalculator', raster,'1',None,'1',None,'1',None,'1',None,'1',None,'1','A>0',None,5,None,result_ras + "/" + result_name)
The question is; how can I continue to write the rest of the processes into my script? I am only interested in the output for the final step so all intermediate outputs can be saved as temp. Ultimately I'd like the output to take the name of the original input raster and append _Outline.shp.
for
loop?