I am writing Python code to take two vector layers as input add different symbology to it and then export that as a image. The vectors layers have been added to the map canvas but while exporting only the second vector file in the image not both vector file.
import os
w_layer = r"path to first vector layer"
o_layer = r"path to second vector layer"
image_location = r"export image path"
wlayer = QgsVectorLayer(w_layer, "W layer", "ogr")
QgsProject.instance().addMapLayer(wlayer)
wlayer.loadNamedStyle(r"path for qml file to display a particular symbology")
olayer = QgsVectorLayer(o_layer, "o layer", "ogr")
QgsProject.instance().addMapLayer(olayer)
olayer.loadNamedStyle(r"path to qml file to display a particular symbology")
vlayer = iface.addMapLayers(wlayer , olayer)
settings = QgsMapSettings()
settings.setLayers([vlayer])
settings.setBackgroundColor(QColor(255, 255, 255))
settings.setOutputSize(QSize(800, 600))
settings.setExtent(vlayer.extent())
render = QgsMapRendererParallelJob(settings)
def finished():
img = render.renderedImage()
img.save(image_location, "png")
render.finished.connect(finished)
render.start() `
iface.addMapLayers
does not exist (remove it) Sosettings.setLayers([vlayer])
can't work. Usesettings.setLayers([wlayer, olayer])