[Qgis-developer] Render with labels
Ziegler Stefan
Stefan.Ziegler at bd.so.ch
Mon Oct 6 02:40:10 PDT 2014
Hi
I did have some problems with dpi output and qgsmaprenderer. Martin Dobias helped me at the hackfest. Now I’m using qgsmaprendererjob classes and it works with custom dpi and labels:
mapSettings = QgsMapSettings()
mapSettings.setMapUnits(0)
mapSettings.setExtent(rect)
mapSettings.setOutputDpi(DPI)
mapSettings.setOutputSize(QSize(width, height))
mapSettings.setLayers(lst)
mapSettings.setFlags(QgsMapSettings.Antialiasing | QgsMapSettings.UseAdvancedEffects | QgsMapSettings.ForceVectorOutput | QgsMapSettings.DrawLabeling)
img = QImage(QSize(width, height), QImage.Format_RGB32)
#img = QImage(QSize(width, height), QImage.Format_Mono)
img.setDotsPerMeterX(DPI / 25.4 * 1000)
img.setDotsPerMeterY(DPI / 25.4 * 1000)
p = QPainter()
p.begin(img)
mapRenderer = QgsMapRendererCustomPainterJob(mapSettings, p)
mapRenderer.start()
mapRenderer.waitForFinished()
p.end()
img.save("/tmp/"+filename+".png","png")
regards
Stefan
Von: qgis-developer-bounces at lists.osgeo.org [mailto:qgis-developer-bounces at lists.osgeo.org] Im Auftrag von Geo DrinX
Gesendet: Montag, 6. Oktober 2014 11:25
An: Anita Graser
Cc: qgis-developer at lists.osgeo.org
Betreff: Re: [Qgis-developer] Render with labels
Hello,
Sorry if I repeat my question that I sent some time ago, but it seems very relevant to the topic.
I noticed that using the .render() function with pyQgis > 2.2 the labels are not visible.
This is my test source code (taken from my GEarthView plugin):
iface = qgis.utils.iface
mapRenderer = mapCanvas.mapRenderer()
mapRect = mapRenderer.extent()
width = mapRenderer.width()
height = mapRenderer.height()
srs = mapRenderer.destinationCrs()
# create output image and initialize it
image = QImage(QSize(width, height), QImage.Format_ARGB32)
image.fill(0)
#adjust map canvas (renderer) to the image size and render
imagePainter = QPainter(image)
zoom = 1
target_dpi = int(round(zoom * mapRenderer.outputDpi()))
mapRenderer.setOutputSize(QSize(width, height), target_dpi)
mapRenderer.render(imagePainter)
imagePainter.end()
xN = mapRect.xMinimum()
yN = mapRect.yMinimum()
nomePNG = ("TestImage")
input_file = out_folder + "/" + nomePNG + ".png"
image.save(input_file, "png")
So, my question is : how need to change my code to have labels again visible ?
:)
Thank you for any link and answer
Roberto
2014-10-05 22:18 GMT+02:00 Anita Graser <anitagraser at gmx.at<mailto:anitagraser at gmx.at>>:
Am 05.10.2014, 18:54 Uhr, schrieb Larry Shaffer <larrys at dakotacarto.com<mailto:larrys at dakotacarto.com>>:
Here's a small script you can use to test the Python bindings for labeling
Thanks a lot Larry! I'll give it a try!
Feel free to add this to the Cookbook. However, the API for labeling may
change during the 2.7 dev cycle, if rule- and style-based labeling is
introduced.
You mean it will change without breaking it? ;-)
Best wishes,
Anita
--
anitagraser.com<http://anitagraser.com>
_______________________________________________
Qgis-developer mailing list
Qgis-developer at lists.osgeo.org<mailto:Qgis-developer at lists.osgeo.org>
http://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141006/fe1c0b25/attachment-0001.html>
More information about the Qgis-developer
mailing list