1

This question already has an answer here:

i am trying to iterate over a large list of features and making a screenshot of the selected feature. My problem is that it seems to be a delay between the refreshing of the canvas and the taking of the screenshot. In other words, the screenshot taken does not correspond to feature i but to feature i-1, sometimes i have several identical screenshots. Is it possible to explicitely wait until the rendering is done by the mapCanvas before calling the saveAsImage method?

This is globally the code that i am using to do this task.

 for i in range(n):
  layer.select(i)
  iface.actionZoomToSelected().trigger()
  qgis.utils.iface.mapCanvas().zoomScale(1000)
  iface.mapCanvas().refresh() 
  imgname = '_'.join(['','object',str(i)])
  imgname = ''.join([imgname,'.png'])
  iface.mapCanvas().saveAsImage(imgname)

marked as duplicate by mgri, Andre Silva, Mapperz Mar 10 '17 at 22:36

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.

  • have you tried the Atlas functionality in the map composer? That effectively does the same thing, and you get more control over the cartography. Tutorial can be found here – Steven Kay Jul 21 '15 at 15:13
  • 2
    Not sure of my answer but ... did u try to paste your "capture code" in the mapCanvasRefreshed() signal of the MapCanvas ? Tell me if it helps ... – snaileater Jul 21 '15 at 19:34
  • @snaileater i already tried that but qgis freezes. – andres troya Jul 22 '15 at 15:55
  • @StevenKay i didn't know about this feature, i will check it out. As a temporary solution i used an older version of qgis in which my actual code seems to work as i expect. – andres troya Jul 22 '15 at 15:56

Browse other questions tagged or ask your own question.