1

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:

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

Does work:

    self.mapCanvas.resize(QSize(394,350))
    self.mapCanvas.zoomToFullExtent()
    QMessageBox.information(self.iface.mainWindow(),"Debug","Break")
    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!

Thanks!

B

3
  • 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 Feb 22 '13 at 13:43
  • Anyone have suggestions? I'm probably going to submit this as a bug. Feb 26 '13 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.