I am looking more for general advice since the code I would have to post here would be rather long.
In a nutshell I create cost rasters from starting points along a street network (grass7:r.cost), reclassify them according to their distance values (gdal:rastercalculator) and would like to add up all resulting rasters.
The last part is the problem. I have tried to add all at once, which could be thousands, so no surprise it's not working. I tried a hundred different ways, this is my most promising try, which of course, does not work:
accumulated_raster = None while rasters: current_batch = rasters[:5] if accumulated_raster: expression = f'"{accumulated_raster}" +'+'+'.join([f'"{raster}"' for raster in current_batch]) else: expression = '+'.join([f'"{raster}"' for raster in current_batch]) params = {'LAYERS': rasters,'EXPRESSION': expression,'OUTPUT': 'memory:sum_raster' } feedback.pushInfo(f"current expression: {params['EXPRESSION']}") try: sum_result = processing.run('native:rastercalc', params) except Exception as e: feedback.reportError(f"Exception occurred: {e}") accumulated_raster = sum_result['OUTPUT'] rasters = rasters[5:] summed_raster_layer = QgsRasterLayer(sum_result['OUTPUT'], "Summed Raster") QgsProject.instance().addMapLayer(summed_raster_layer)