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?

1 Answer 1

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.

3
  • But not the crs, though maybe there is a gdal aux created as well?
    – mdsumner
    Commented May 23, 2016 at 13:28
  • Nope, only two files are generated. You can choose among several formats like TIF or TIFF, but you'll only get the raster and its corresponding World file. Commented May 23, 2016 at 13:50
  • I requested GTiff some years ago, they may be ready for this now? It's a real lost opp
    – mdsumner
    Commented May 23, 2016 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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