Regarding the 'Label every part of multi-features' check box located in the 'Labels // Rendering // Feature Options' layer properties UI...

Can this be done with pyQGIS?

These two commands enable the labeling, and allow color/font/etc. to work fine.

self.contourLayer.setCustomProperty("labeling", "pal")
self.contourLayer.setCustomProperty("labeling/enabled", "true")

Tests with these three commands do not enable multi-feature labels.

self.contourLayer.setCustomProperty("labeling/displayAll", "true")
self.contourLayer.setCustomProperty("labeling/labelPerPart", "true")
  • 1
    self.contourLayer.setCustomProperty("labeling/labelPerPart", "true") should do the trick. – Germán Carrillo Jul 14 '16 at 18:14
  • That command-line doesn't seem to work (see OP examples) – Katalpa Jul 14 '16 at 18:25
  • @GermanCarrillo: Does the command line mentioned ('labelPerPart'), reflect settings exhibited in the Layer Properties UI? To confirm that this doesn't function, when opening the layer where said command is applied via pyQgis doesn't have the related box checked ('Label every part of multi-features')... – Katalpa Jul 14 '16 at 22:00
  • Yes, as soon as I run such line, I get the checkbox toggled in the properties dialog. I'm using QGIS 2.14.2, which QGIS version are you using? – Germán Carrillo Jul 15 '16 at 2:02
  • The version which doesn't seem to work is 2.14.3, but I am looking into possible problems with the plugins script which calls on this function. – Katalpa Jul 15 '16 at 15:23

The following PyQGIS line should do the trick:

self.contourLayer.setCustomProperty("labeling/labelPerPart", "true")

As soon as you run such line, you should get the 'Label every part of multi-features' checkbox toggled in the properties dialog. I'm using QGIS 2.14.2.

  • As a confidant, this posting spawned reanalysis of the original script to reveal a troublesome try: block which faulted prior to the correctly suggested command. Works great now. Thanks @GermanCarrillo. – Katalpa Jul 15 '16 at 18:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.