I am using QGIS raster calc as below. Now I am saving it as a tiff. But is there a way that I can save it as a memory layer?

I want to refer to that resulting memory layer and polygonize it, and upload it to postgis server. Because I am building a plugin so I don't want user to specify a folder to save the tif.

layer = QgsRasterLayer(path_of_image, 'input')
name = layer.name()
resultinglayer = QgsRasterCalculatorEntry()
resultinglayer.ref = name + "@1"
resultinglayer.raster = layer
resultinglayer.bandNumber = 1
entries = [resultinglayer]
calc = QgsRasterCalculator('(%s@1)*0' % name, 
  • 1
    Are you opposed to using a raster calculator from the Processing plugin?
    – Joseph
    Commented Jan 27, 2017 at 10:12
  • that one doesnt seem to let me band 1 * 0, does it? Commented Jan 28, 2017 at 7:56
  • Not so sure but atleast you found a workaround :)
    – Joseph
    Commented Jan 30, 2017 at 10:07

1 Answer 1


I just found a workaround, may not be the best way, it gets the environment variable and find the temporary path

import os
temp_path = os.environ['TEMP']

then just save the output in that temp_path.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.