1

I am using PyQGIS to export a map layout like this

exporter = QgsLayoutExporter(layout)
settings = exporter.ImageExportSettings()
settings.dpi = 100
path = 'C:/data/test1.png'
exporter.exportToImage(path, settings)

If I save it as a tiff it is georeferenced but not when saving as a PNG.

Is there a way to export it as a georeferenced PNG, or would I need to add an extra step after the fact? E.g, using gdal translate with the exported tiff.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
JUNGLE
  • 510
  • 2
  • 10
  • 2
    I'm not the greatest authority on raster formats so happy to be told I'm wrong but afaik, png can't store georeference information internally so, if you use gdal_translate to convert a geotiff to png, the srs and geo transform information will be written to the .aux xml file. What you could do is add settings.generateWorldFile = True to your script to write a world file for your png or export to pdf and use settings = exporter.PdfExportSettings() then settings.writeGeoPdf = True – Ben W Jan 21 '22 at 05:29
  • @BenW png can't store it internally, but you can have a world file associated – nmtoken Jan 21 '22 at 09:09
  • https://gis.stackexchange.com/questions/398013/how-to-convert-geotiff-to-png-world-file-in-qgis may give hints – nmtoken Jan 21 '22 at 09:10
  • 1
    Unfortunately a world file has no SRS information included, as @BenW already mentioned. Why do you use PNG instead of TIFF anyway? TIFF format has much more compression options and allows overviews as well. There's only the web that requires JPG or PNG. – christoph Jan 21 '22 at 11:35
  • The software im exporting to can only use PNG. Im dealing with very large images, which is why I didn't want to add an extra step of converting the image to PNG – JUNGLE Jan 23 '22 at 23:34
  • @Ben W using "settings.generateWorldFile = True", achieved what i was after. Thanks! – JUNGLE Jan 23 '22 at 23:37

0 Answers0