How do I save GDAL processing output rasters to a temporary layer? Using 'memory:'
for vector processes works fine, but I couldn't get it to work for GDAL processes.
output_rast = self.parameterAsOutputLayer(parameters,self.OUTPUTR,context)
if True:
magnitude_rast = processing.run("gdal:rasterize", {
'INPUT':buffer_extent,
'BURN': magnitude,
'UNITS': 1,
'WIDTH': 1.0,
'HEIGHT': 1.0,
'EXTENT': buffer_extent,
'OUTPUT': 'memory:'
}, context=context, feedback=feedback)['OUTPUT']
if True:
source_rast = processing.run("gdal:rasterize", {
'INPUT':parameters['SOURCE'],
'BURN': 100,
'UNITS': 1,
'WIDTH': 1.0,
'HEIGHT': 1.0,
'EXTENT': buffer_extent,
'OUTPUT': 'memory:'
}, context=context, feedback=feedback)['OUTPUT']
if True:
proximity_rast = processing.run("gdal:proximity", {
'INPUT':source_rast,
'BAND': 1,
'VALUES': 100,
'UNITS': 0,
'DATA_TYPE': 5,
'OUTPUT': output_rast
}, context=context, feedback=feedback)['OUTPUT']
return {self.OUTPUTR: output_rast}
I've also tried using None
for the output parameter as recommended here but I get an incorrect parameter value error.
1 Answer 1
You can use "OUTPUT": QgsProcessing.TEMPORARY_OUTPUT
but this will "just" write the data to a file in your operating system's temporary directory. This is not necessarily stored in volatile memory (RAM).
I am not aware of an easy way to make GDAL Processing algorithms store their output in a RAM-backed location. Maybe one could use https://gdal.org/drivers/raster/mem.html ?