1

Now the only issue is that in image I am not getting the labels, I have on polygon. Please help in that too Please see above attached screenshots here I need labels –
I have updated QGIS it's version 2.12.1-Lyon but it was making same polygon image it can not show length of polygon line and polygon Sr. No on label. for show label on image required any special code or not

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import *
import time
l = iface.activeLayer()

for a in l.getFeatures():
    attrs = {16: 1}
    l.dataProvider().changeAttributeValues({a.id(): attrs})
    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)
    render = QgsMapRenderer()
    palyr = QgsPalLayerSettings()
    palyr.readFromLayer(l)
    lst = [l.id()]
    render.setLayerSet(lst)
    render.setLabelingEngine(QgsPalLabeling())
    # set extent
    rect = a.geometry().boundingBox()
    rect.scale(1.1)
    composerMap.setNewExtent(rect)
    render.setScale(1)
    render.setOutputSize(img.size(), img.logicalDpiX())
    render.render(p)
    p.end()
    # save image
    img.save("C:/example/Ashwin/%s.jpg" % a['CHALTA_NO'],"jpg")
    attrs = {16: 0}
    l.dataProvider().changeAttributeValues({a.id(): attrs})
    time.sleep(1)

i want to Sr. No and length labels on polygon. Please see below image. i want to like image part 2. enter image description here

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.