Great tutorial!! Here is the final script developed in this video img = QImage(QSize(800,800), QImage.Format_ARGB32_Premultiplied) #set backgroundcolor color = QColor(255,255,255,255) img.fill(color.rgba()) #create painter p= QPainter() p.begin(img) p.setRenderHint(QPainter.Antialiasing) #the mapsettings ms= QgsMapSettings() ms.setBackgroundColor(color) #set layers to render layer = QgsProject().instance().mapLayersByName('214') ms.setLayers([layer[0]]) #set Extent rect = QgsRectangle(ms.fullExtent()) ms.setExtent(rect) #size of output image ms.setOutputSize(img.size()) #render map render = QgsMapRendererCustomPainterJob(ms, p) render.start() render.waitForFinished() p.end() #save the image img.save('C:/Users/Desktop/krishna/render.png')
How could one take this code and set the extents using a 2nd layer such as a shapefile I call "mask"? Can I just refer to the layer's name or must I get the actual extents from the layer first? Tried many was to use ms.setExtent() but with no success....help!
Great tutorial!! Here is the final script developed in this video
img = QImage(QSize(800,800), QImage.Format_ARGB32_Premultiplied)
#set backgroundcolor
color = QColor(255,255,255,255)
img.fill(color.rgba())
#create painter
p= QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
#the mapsettings
ms= QgsMapSettings()
ms.setBackgroundColor(color)
#set layers to render
layer = QgsProject().instance().mapLayersByName('214')
ms.setLayers([layer[0]])
#set Extent
rect = QgsRectangle(ms.fullExtent())
ms.setExtent(rect)
#size of output image
ms.setOutputSize(img.size())
#render map
render = QgsMapRendererCustomPainterJob(ms, p)
render.start()
render.waitForFinished()
p.end()
#save the image
img.save('C:/Users/Desktop/krishna/render.png')
How could one take this code and set the extents using a 2nd layer such as a shapefile I call "mask"? Can I just refer to the layer's name or must I get the actual extents from the layer first? Tried many was to use ms.setExtent() but with no success....help!
how to export by changing only the display scales?
How can I export multiple layers (with different names?) Or is there a way to export whole groups?
You can do what I've done here, just remove the current layer, add the new layer, and save it with a different name.
@@geospatialschool A for cycle could be a possibility?
@@nos540 Did you get the answer for this?