I'm trying to use the virtual raster calculator process 'native:virtualrastercalc' using PyQGIS. When using the GUI and exporting the python code :
output_layer = processing.run("native:virtualrastercalc", {'LAYERS'['https://data.geopf.fr/wms-r/wmsSERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&STYLES=normal&FORMAT=image/geotiff&LAYERS=ELEVATION.ELEVATIONGRIDCOVERAGE.HIGHRES&CRS=EPSG:2154&height=784&width=1284&BBOX=650934.392014719,6865793.214447776,652218.0879534119,6866577.504613528'],'EXPRESSION':'"RGEALTI@1"','EXTENT':'650934.392000000,652218.088000000,6865793.214400000,6866577.504600000[EPSG:2154]','CELL_SIZE':1.5,'CRS':QgsCoordinateReferenceSystem('EPSG:2154'),'LAYER_NAME':'RGE ALTI B1'})
The process works fine, but when I try to customize it for my existing code (and existing layer that I stored in a python variable) :
formula = layer_name +"@1"# Set the extent and resolutionoutput_resolution = 1.5 # get number of columns and rows of layer param = { "LAYERS": [layer],"EXPRESSION": f'{formula}',"EXTENT": layer.extent(),"CELL_SIZE": output_resolution,"CRS": layer.crs(),'LAYER_NAME': 'RGE ALTI B1'}output_layer = processing.run("native:virtualrastercalc", param)['OUTPUT'] QgsProject.instance().addMapLayer(output_layer)
"layer" is the python variable where I stored a QgsRasterLayer. "layer_name" is the name of the said layer.
It doesn't work for some reason, the layer is imported but is broken. Any ideas ?