2

I found Exporting composition as image using PyQGIS to export the current view as an image.

The following code works and was accepted as an answer.

c = iface.activeComposers()[0].composition()

image = c.printPageAsRaster(0)

image.save('output.png', 'png')

Sadly, the images produced by this code are not georeferenced, even if I use different image formats.

How is it possible to programmatically export current view as georeferenced image with QGIS?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
EikeMike
  • 1,171
  • 10
  • 24

1 Answers1

3

You could use:

iface.mapCanvas().saveAsImage( "myGeoreferencedView.png" )

It exports both PNG and PNGw files. The latter is known as World file and contains coordinate information.

Germán Carrillo
  • 36,307
  • 5
  • 123
  • 178