6

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.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Apr 15, 2019 at 1:56

1 Answer 1

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 ?

answered Mar 13, 2023 at 21:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.