I am working with a Mac OSX El Capitan, QGIS 3.4.5 Madeira and Python 3.6.1.
I have a question which I believe is essentially a python one but applied into QGIS.
I intend to program some algorithms from the Saga tools to run various files. So, for instance I want to clip a raster with a polygon and so I run the following:
processing.run("saga:cliprasterwithpolygon", { 'INPUT' : '/Users/.../wheat_HarvestedAreaHectares.tif',
'OUTPUT' : '/Users/.../wheat.sdat',
'POLYGONS' : '/Users/.../africa_countries.shp' })
The raster files are agricultural data from all the world and I am clipping it to a shape file of the African continent to do some computations afterwards with zonal statistics.
Naturally, I would love to find a way to run this code for several crops. I am imagining something as creating a list with the names of the crops and looping through the code with the name of the crop as a macro.
Something like:
crop = [maize, wheat, rice]
for crop in crops:
processing.run("saga:cliprasterwithpolygon", { 'INPUT' : '/Users/.../`crop'_HarvestedAreaHectares.tif',
'OUTPUT' : '/Users/.../`crop'.sdat',
'POLYGONS' : '/Users/.../africa_countries.shp' })
However, I've read elsewhere that Python does not work with macros, and similar questions around stackexchange does not seem to address this issue directly.
Any hint?