Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a plugin for exporting maps as PNG images. I believe this code was working correctly within 1.6 (but I cannot guarantee I haven't made another change that would have broken it there, too).

Basically, I load a set of base map features and then loop through a set of point layers that get applied and the whole thing is exported as an image. I'm not getting the full canvas at all, but only a single attribute loaded from the base map and nothing from the point layers. (bad result, expected result)

In the process of debugging this, I discovered a curious fact. If I include a QMessageBox.information right before I do the export, it works correctly!

Doesn't work:

    currentImagePath = theExportPath + folder
    currentImageName = attribute.replace(' ', '_') + ".png"
    self.mapCanvas.saveAsImage(currentImagePath + "/" + currentImageName)

Does work:

    currentImagePath = theExportPath + folder
    currentImageName = attribute.replace(' ', '_') + ".png"
    self.mapCanvas.saveAsImage(currentImagePath + "/" + currentImageName) 

I tried to add a simple self.iface.mainWindow() in place of the message box but that didn't do the trick. I'm thinking there is some kind of refresh I could do, too, but I tried mapCanvas.refresh() and mapCanvas.updateMap() and these in combination with mainWindow() but could get nothing to work.

Did this change in 1.8? Any suggestions to make it work? Including the QMessageBox call will get me going but I have to press "OK" for each map to be exported. With all the export combinations, I'd be doing this more than 1000 times!



share|improve this question
upgrade to 1.8. all your previous works will still work on it. keep the old version too for reference. – Ger Feb 22 '13 at 9:30
Hi Gerald, Thanks for the reply. I'm actually running 1.8 and it has this problem. I think this method worked in 1.6 or 1.4 (my notes aren't very good on this topic). I can try the older versions, but I was hoping there was just something I was doing incorrectly. Right now, I'm looking into a self-closing message box. This is definitely a kludge but I think that'd be easier than installing an old version of QGIS (particularly when I'm not sure it will work anyway). Thanks! B – Brian Edmond Feb 22 '13 at 13:43
Anyone have suggestions? I'm probably going to submit this as a bug. – Brian Edmond Feb 26 '13 at 18:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.