I am clipping a raster by extents from the python console in QGIS by using the following code :
from processing.tools import *
general.runalg("gdalogr:cliprasterbyextent","E:/Sreeraj/Task/Split/Extract_agri.tif","","-180.0,0.0,0.0,90.0",5,4,75,6,1,False,0,False,"","E:/Sreeraj/Task/Split/output/1.tif")
Here, I am giving extents as minimum_longitude=180.0, minimum_latitude=0.0, maximim_longitude=0.0, and maximum_latitude=90.0.
Now, I want to do a clipping using processing.runalg in QGIS python console, where I will use a for loop for clipping 4 output .tif files as a batch process.
For doing this batch process of clipping, I tried the given below code:
output_location = "E:/Sreeraj/Task/Split/output/"
output file = 1
for long in range(-180,0,5):
longmax = long + 5
for lat in range(0,90,5):
latmax = lat + 5
extents = "long,lat,longmax,latmax"
output = str(output_location) + str(output file) + ".tif"
general.runalg("gdalogr:cliprasterbyextent","E:/Sreeraj/Task Global Data CONVERSION/Split/Extract_agri.TIF","",extents,5,4,75,6,1,False,0,False,"",output)
output file = output file + 1
Unfortunately, I am getting error message as :
"Error: Wrong parameter value: extents"
Instead of directly giving the extent values like "-180.0,0.0,0.0,90.0" inside general.runalg(), how can I give "extents" (if extents = "-180,0,0,90").
I think that the issue is with :
extents = "long,lat,longmax,latmax"
When I do like this :
extents = "-180.0,0.0,0.0,90.0"
general.runalg("gdalogr:cliprasterbyextent","E:/Sreeraj/Task Global Data CONVERSION/Split/Extract_agri.TIF","",extents,5,4,75,6,1,False,0,False,"",output)
then the code is working.
But, if I do like this :
long = -180.0
lat = 0.0
longmax = 0.0
latmax = 90.0
extents = "long,lat,longmax,latmax"
general.runalg("gdalogr:cliprasterbyextent","E:/Sreeraj/Task Global Data CONVERSION/Split/Extract_agri.TIF","",extents,5,4,75,6,1,False,0,False,"",output)
then I am getting the error.
So, clearly, the issue is with :
extents = "longmin,longmax,latmin,latmax"
Please help me to solve this error.