[Qgis-developer] QgsMapRenderer and DPI problem

Ziegler Stefan Stefan.Ziegler at bd.so.ch
Mon Sep 1 23:13:45 PDT 2014


Hi

I'm trying to save an image from QGIS master with python:

    img = QImage(QSize(width, height), QImage.Format_ARGB32_Premultiplied)
    img.setDotsPerMeterX(dpi / 25.4 * 1000)
    img.setDotsPerMeterY(dpi / 25.4 * 1000)
    
    color = QColor(255,255,255)
    img.fill(color.rgb())
    p = QPainter()
    p.begin(img)
    p.setRenderHint(QPainter.Antialiasing)
    render = QgsMapRenderer()
    render.setLabelingEngine(QgsPalLabeling())
    render.setLayerSet(lst)
    render.setExtent(rect)
    render.setOutputSize(img.size(), dpi)
    render.render(p)
    p.end()
    
    img.save("/tmp/"+filename+".png","png")


It seems that the dpi parameter in render.setOutputSize(img.size(), dpi) is not respected. For any value of dpi the line width is always the same in the output raster. It it respected when using map units for line widths and not milimeters, though. The script was used in an older QGIS version ages ago. So I'm pretty sure it worked once. Did I miss something or is it a bug?

Regards
Stefan 


Freundliche Grüsse 
Stefan Ziegler 
Kantonsgeometer 

Amt für Geoinformation
Amtliche Vermessung 
Rötistrasse 4 
4500 Solothurn 

Telefon +41 32 627 75 96
Telefax +41 32 627 75 98 
stefan.ziegler at bd.so.ch
http://www.so.ch 



More information about the Qgis-developer mailing list