I have the following function that I'm trying to use to save an image of a polygon and point layer. When I render just the polygon layer, it works fine, but the point layer will not render for some reason, either on its own or when passed in conjunction to the polygon layer.
def renderImage(layers, name):
for layer in layers:
QgsMapLayerRegistry.instance().addMapLayer(layer)
# create image
img = QImage(QSize(800, 600), QImage.Format_ARGB32_Premultiplied)
# set image's background color
color = QColor(255, 255, 255)
img.fill(color.rgb())
# create painter
p = QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
render = QgsMapRenderer()
# set layer set
lst = [layer.id() for layer in layers] # add ID of every layer
render.setLayerSet(lst)
# set extent
rect = QgsRectangle(render.fullExtent())
rect.scale(1.1)
render.setExtent(rect)
# set output size
render.setOutputSize(img.size(), img.logicalDpiX())
# do the rendering
render.render(p)
p.end()
# save image
img.save(name+".png","png")
Ultimately what I want to do is display the polygon layer and just the labels from the point layer. Unfortunately right now I can't even get the point layer to display at all, and I'm really stuck as to why. I've verified that the layer is being loaded correctly from the .shp file, and right now its renderer is set to SingleSymbolRender. Before the call to the function above I set the symbol for the point layer using the following lines:
symbol = QgsMarkerSymbolV2.createSimple({'name': 'circle', 'color': 'red'})
layer.rendererV2().setSymbol(symbol)
But the saved image when I render just the point layer is a blank white backdrop.
layer.triggerRepaint()