[Qgis-developer] Render with labels

Larry Shaffer larrys at dakotacarto.com
Sun Oct 5 09:54:26 PDT 2014


Hi Anita,

On Sun, Oct 5, 2014 at 9:45 AM, Anita Graser <anitagraser at gmx.at> wrote:

> Hi,
>
> I'm trying to use one of the examples from the PyQGIS Cookbook to render a
> map at custom resolution:
>
> http://docs.qgis.org/testing/en/docs/pyqgis_developer_
> cookbook/composer.html#simple-rendering
>
> While the layers render fine, no labels are drawn. Do you know how I can
> add labels to the output?
>
> I tried
>
> render.setLabelingEngine(QgsPalLabeling())
>
> but no luck.
>

Here's a small script you can use to test the Python bindings for labeling
[0]. It is intended to be run from within the PyQGIS console's script
editor, and uses the Spatialite db for labeling unit tests, called '
pal_features_v3.sqlite' [1].

Setup:

* Load the 'background' layer
* Load the 'point' layer on top of 'background'
* Select the 'point' layer in the legend
* Open script in console's editor and run it

When script is run, you should end up with something like this [2],
probably with different fill color for 'background'.

See the Python labeling test suite for more examples, from
'test_qgspallabeling_*.py' [3], specifically the
'test_qgspallabeling_tests.py' file.

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.

[0] https://gist.github.com/dakcarto/33115cd569e17b9419c0
[1] https://github.com/qgis/QGIS/tree/master/tests/testdata/labeling
[2] http://drive.dakotacarto.com/qgis/labeling_py-api.png
[3] https://github.com/qgis/QGIS/tree/master/tests/src/python

Regards,

Larry Shaffer
Dakota Cartography
Black Hills, South Dakota


>
> Thanks and best wishes,
> Anita
>
>
> --
> anitagraser.com
> _______________________________________________
> Qgis-developer mailing list
> 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/20141005/dd349087/attachment.html>


More information about the Qgis-developer mailing list