-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreacion_imagenes.py
35 lines (35 loc) · 1.09 KB
/
creacion_imagenes.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
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
#TIPO DE IMAGEN Y DIRECTORIO DE SALIDA
imageType = "jpg"
pathToFile = "E:/CURSO_PYQGIS/"
# CREA Y CONFIGURA LA IMAGEN: SIZE, COLOR FONDO
img = QImage(QSize(800,600), QImage.Format_ARGB32_Premultiplied)
color = QColor(255,255,255)
img.fill(color.rgb())
# CREA EL PAINTER A PARTIR DE LA IMAGEN
p = QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
#CONTENIDOS DE LA IMAGEN:
renderer = QgsMapRenderer()
lst = []
#lista las capas visibles, es iface y se cogen todas las capas
layers = iface.mapCanvas().layers()
for layer in layers:
lst.append(layer.id())
renderer.setLayerSet(lst)
#fija el extent sobre el total de las capas
rect = QgsRectangle(renderer.fullExtent())
rect.scale(1.1)
renderer.setExtent(rect)
#output size
renderer.setOutputSize(img.size(), img.logicalDpiX())
#FIJA LA COMPOSICION FINAL Y CIERRA LA IMAGEN
renderer.render(p)
p.end()
#GENERA Y SALVA IMAGEN
img.save(pathToFile + "mi_primera_imagen" + "." + imageType ,imageType)
print "imagen generada"