5

If I have a print composer called "ABC", I would like to "tell" its composer that I would like to

  1. update "Map 0" to simulate the "set to map canvas extent" button activation
  2. update certain text labels
  3. activate "export to image"

Thank you.

4

On the topic of print output from pyQGIS: http://www.qgis.org/pyqgis-cookbook/composer.html (Note: master has QgsComposition::loadFromTemplate method, which 1.8 has not).

Basically, in 1.8, you have to create the composition (with map, labels, etc.) from scratch in code anyway. So no updates are needed.

6

Just an update for this question given the QGIS 2 API is a bit better for these things.

Re your 1, if you want to update the maps in a composer, use code such as:

map_item = composition.getComposerItemById('map')
map_item.setMapCanvas(canvas)
map_item.zoomToExtent(canvas.extent())

Re your 2, use:

composition.refreshItems()

Re your 3:- as Underdark suggested, there is example code to export to both images and PDF at the QGIS Python API cookbook:- http://docs.qgis.org/2.8/en/docs/pyqgis_developer_cookbook/composer.html#output-to-a-raster-image

References:- http://kartoza.com/how-to-create-a-qgis-pdf-report-with-a-few-lines-of-python/

Your Answer

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

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