I have a transparent raster on top of a hillshade.
I want to Project - Import/Export - Export map to image using PyQGIS:
I need to be able to set extent, scale, dpi and the output needs to be georeferenced.
I have followed PyQGIS: Render (Print/Save) a Layer as an Image to get an output but the output has no coordinate system set.
How can I export the image including this?
img = QImage(QSize(3000, 3000), QImage.Format_ARGB32_Premultiplied)
img.setDotsPerMeterX(1)
img.setDotsPerMeterY(1)
# create map settings
ms = QgsMapSettings()
# create painter
p = QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
# set layers to render
layers = list(reversed([lyr for lyr in QgsProject.instance().mapLayers().values()]))
ms.setLayers(layers)
# set extent
rect = iface.mapCanvas().extent()
rect.scale(1.1)
ms.setExtent(rect)
# set ouptut size
ms.setOutputSize(img.size())
# setup qgis map renderer
render = QgsMapRendererCustomPainterJob(ms, p)
render.start()
render.waitForFinished()
p.end()
# save the image
img.save('/home/bera/Desktop/test_render.png')
print('Done')