-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht4_export_png_4qgis2.py
51 lines (38 loc) · 1.03 KB
/
t4_export_png_4qgis2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
imageType = "png"
pathToFile = "C:/Users/soiqu/Desktop/test_pyQGIS/png/"
# create image
img = QImage(QSize(800,600), QImage.Format_ARGB32_Premultiplied)
# set image's background color
color = QColor(255,255,255)
img.fill(color.rgb())
# create painter
p = QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
renderer = QgsMapRenderer()
# set layer set
lst = []
layers = iface.legendInterface().layers()
for layer in layers:
lst.append(layer.id())
renderer.setLayerSet(lst)
print("Set rendered")
# set extent
rect = QgsRectangle(renderer.fullExtent())
rect.scale(1.1)
renderer.setExtent(rect)
# set output size
renderer.setOutputSize(img.size(), img.logicalDpiX())
print("Prepared to render")
# do the rendering
renderer.render(p)
print("rendered")
p.end()
print("painter ended")
# save image
img.save(pathToFile + 'hahaha' + "." + imageType ,imageType)
#img.save(pathToFile + self.activeLayer.name() + "." + imageType ,imageType)