1

I need to do a lot of pictures at different points from vector layer on each. And the picture (.jpg / .png) must be signed and so on - then the layout is best suited. Now I do a picture on a map posted on the points (and even get .png) how to create a layout with the data or work from the layout and apply it using a filter python?

My code:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import qgis.utils
layer = iface.activeLayer()
layer.setSubsetString('')
iter = layer.getFeatures()
for feature in iter:
    name_dot = feature['name']
    saving = "C:/project_qgis/"+"%s"%name_dot+".png"
    print saving
    layer.setSubsetString('"name"=\'%s\'' % name_dot) 
    mapRenderer = iface.mapCanvas().mapRenderer()
    c = QgsComposition(mapRenderer)
    c.setPlotStyle(QgsComposition.Print)
    x, y = 0, 0
    w = c.paperWidth()
    h = c.paperHeight()
    composerMap = QgsComposerMap(c, x ,y, w, h)
    c.addItem(composerMap)
    dpi = c.printResolution()
    dpmm = dpi / 25.4
    width = int(dpmm *w)
    height = int(dpmm *h)
    image = QImage(QSize(width, height), QImage.Format_ARGB32)
    image.setDotsPerMeterX(dpmm * 1000)
    image.setDotsPerMeterY(dpmm * 1000)
    image.fill(0)
    imagePainter = QPainter(image)
    sourceArea = QRectF(0, 0, w, h)
    targetArea = QRectF(0, 0, width, height)
    c.render(imagePainter, targetArea, sourceArea)
    imagePainter.end()
    image.save("%s" %saving, "png")

In fact, the biggest problem is the size of the image, scale, degree grid and the label on the finished picture that can be done during layout...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.