I have the following layout and map item:
layout = project.layoutManager().layoutByName('Test')
map_item = layout.itemById('Map 1')
map_item.zoomToExtent(canvas.extent())
I have the following extract by attribute algorithm:
alg_params = {
'FIELD': 'highway',
'INPUT': outputs['RenameField_roads']['OUTPUT'],
'OPERATOR': 0, # =
'VALUE': 'motorway_link',
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['ExtractByAttributeMotorway_link_osm'] = processing.run('native:extractbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
results['Motorway_link_osm'] = outputs['ExtractByAttributeMotorway_link_osm']['OUTPUT']
For multiple layers I have tried to do something like this, but the export is blank:
temporary_layers = [
results['Motorway_link_osm'],
results['Motorway_osm'],
]
map_item.setLayers(temporary_layers)
As a possible solution, I thought to add a vector layer to the layers panel then export the map, but maybe it is a simpler solution.
I would like to add the temporary output vector layer to the 'Map 1' map item without having to import it to the layer panel in order to automatically export the map.
How can I do this process for this temporary output?
What if I have multiple temporary outputs to add to the map item in order to have them to the exported map?
processing.run()
calls as child algorithms, their outputs will be map layer id strings, notQgsVectorLayer
s, see this answer. You can get a map layer object like:motorway_link_lyr = context.getMapLayer(results['Motorway_link_osm'])
.