[GIS] QGIS python custom properties for labeling

documentationlabelingpyqgisqgis-processing

I have some code that is working great for adding labels to my vector layers:

    layer.setCustomProperty("labeling", "pal")
    layer.setCustomProperty("labeling/enabled", "true")
    layer.setCustomProperty("labeling/fontFamily", "Noto Sans")
    layer.setCustomProperty("labeling/fontSize", "10")
    layer.setCustomProperty("labeling/isExpression", True)
    layer.setCustomProperty("labeling/fieldName", " concat( name_nl, '\\n', name_de )")
    layer.setCustomProperty("labeling/placement", "0")

I found most of the property names, values through searches in forums/web. As you can see the label is a multi-line concatenation of two fields. I would want the text to be left aligned. This is possible in the GUI, but I seem unable to find the property name that is needed for text alignment. There is API documentation about MultiLineAlignment etc. but I cannot figure out what to put extra here, I've tried stuff like:

    layer.setCustomProperty("labeling/multiLineAlignment", "0" )  
    layer.setCustomProperty("labeling/multiLineAlign", "0" )
    layer.setCustomProperty("labeling/alignment", "center" )

with various values, names etc. nothing seems to work for the text alignment. The API docs in http://geoapis.sourcepole.com/qgispyapi/qgspallayersettings#QgsPalLayerSettings.MultiLineAlign

seem to suggest there is something.

Does anyone know that is needed? Or where these property names labeling/xyz are listed in a documentation?

Best Answer

The easiest way to see all the custom properties is to save out a style QML from the GUI and then open it in your favorite text editor and inspect the KML tags.

0 = left, 1 = center, 2 = right alignment.

All you needed was a lowercase L.

layer.setCustomProperty("labeling/multilineAlign", "0" )
Related Question