This question already has an answer here:

I am running a script from the Python console in QGIS. I have stripped the script down to highlight the problem. Basically, when I render and save an image of a shapefile that is displayed with points they do not appear in the saved image. They will appear in the map canvas (see image below). Interestingly, if I have a vector that I fill (e.g., administrative boundaries) they will be visible in rendered image. Here is a screenshot of the map canvas after running script:

enter image description here

and here is my code:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

#input Layer
lyrPts = QgsVectorLayer("SomeFile.shp", "Qflu", "ogr")

# create image
img = QImage(QSize(8000, 6000), QImage.Format_ARGB32_Premultiplied)

# set image's background color
color = QColor(255, 255, 255)

# create painter
p = QPainter()
render = QgsMapRenderer()

# set layer set
layers = QgsMapLayerRegistry.instance().mapLayers()
lst = layers.keys()

# set extent
rect = QgsRectangle(lyrPts.extent())

# set output size
render.setOutputSize(img.size(), img.logicalDpiX())

# do the rendering

#end rendering

# save image

marked as duplicate by PolyGeo Sep 6 '17 at 22:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


It look like this was an issue with the image being saved before it was rendered. There is a detailed explanation and workaround by @Matthias Kuhn here: Wait for canvas to finish rendering before saving image

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