I am trying to perform a simple raster calculator that takes input rasters and outputs a new raster with a constant value where values exceed a specified number in the input.
This is part of of a QGIS script and currently works using GDAL raster calculator. However I am having issues where python stops working when running the script using GDAL RC. Therefore i'd like to adjust my script to use the SAGA GIS equivalent to perform the same process:
processing.runalg('gdalogr:rastercalculator', raster,'1',None,'1',None,'1',None,'1',None,'1',None,'1','A>0',None,5,None,OutRaster)
My question is how can I change the line above in my script to perform the same calculation using the SAGA raster calculator? That is how can I write the expression which will output a new raster with a constant value where the input raster exceeds 0.
Best Answer
processing.runalg('saga:rastercalculator', raster,[],'A>0',False,7,OutRaster)
Explanation
'saga:rastercalculator'
Calls the algorithm.raster
Your input raster[]
Additional input rasters as array (empty in your case)'A>0'
The query to runFalse
Use NoData (True or False)7
The Output Data TypeOutRaster
Your output rasterEdit:
Also take a look at Joseph's previous answer to this related question.