Skip to main content
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

I am writing a python script to label features (lines). However I can't figure out:

  1. how to get the script to turn on the buffer

  2. how to get the script to apply the changes. When I currently run it, it changes everything in the properties (except the buffer) but I still have to hit ok before QGIS applies it to the map.

.

layer = iface.activeLayer()
layer.setCustomProperty("labeling/fieldName", "Length" )
layer.setCustomProperty("labeling/placement", QgsPalLayerSettings.Horizontal)
layer.setCustomProperty("labeling/predefinedPointPosition", QgsPalLayerSettings.BottomRight)
layer.setCustomProperty("labeling/fontSize","10" )
layer.setCustomProperty("labeling/buffer",QgsPalLayerSettings.BufferDraw)
layer.setCustomProperty("labeling/enabled","true" )
layer.triggerRepaint()

I have had a look at one similar question but I cannot seem to figure it out: Labeling line features using PyQGIS?Labeling line features using PyQGIS?

Once I get this to work I want to transform it into a batch-script by adding some lines like:

for layer in QgsMapLayerRegistry.instance().mapLayers().values():

I am writing a python script to label features (lines). However I can't figure out:

  1. how to get the script to turn on the buffer

  2. how to get the script to apply the changes. When I currently run it, it changes everything in the properties (except the buffer) but I still have to hit ok before QGIS applies it to the map.

.

layer = iface.activeLayer()
layer.setCustomProperty("labeling/fieldName", "Length" )
layer.setCustomProperty("labeling/placement", QgsPalLayerSettings.Horizontal)
layer.setCustomProperty("labeling/predefinedPointPosition", QgsPalLayerSettings.BottomRight)
layer.setCustomProperty("labeling/fontSize","10" )
layer.setCustomProperty("labeling/buffer",QgsPalLayerSettings.BufferDraw)
layer.setCustomProperty("labeling/enabled","true" )
layer.triggerRepaint()

I have had a look at one similar question but I cannot seem to figure it out: Labeling line features using PyQGIS?

Once I get this to work I want to transform it into a batch-script by adding some lines like:

for layer in QgsMapLayerRegistry.instance().mapLayers().values():

I am writing a python script to label features (lines). However I can't figure out:

  1. how to get the script to turn on the buffer

  2. how to get the script to apply the changes. When I currently run it, it changes everything in the properties (except the buffer) but I still have to hit ok before QGIS applies it to the map.

.

layer = iface.activeLayer()
layer.setCustomProperty("labeling/fieldName", "Length" )
layer.setCustomProperty("labeling/placement", QgsPalLayerSettings.Horizontal)
layer.setCustomProperty("labeling/predefinedPointPosition", QgsPalLayerSettings.BottomRight)
layer.setCustomProperty("labeling/fontSize","10" )
layer.setCustomProperty("labeling/buffer",QgsPalLayerSettings.BufferDraw)
layer.setCustomProperty("labeling/enabled","true" )
layer.triggerRepaint()

I have had a look at one similar question but I cannot seem to figure it out: Labeling line features using PyQGIS?

Once I get this to work I want to transform it into a batch-script by adding some lines like:

for layer in QgsMapLayerRegistry.instance().mapLayers().values():
edited title
Link
underdark
  • 84.5k
  • 22
  • 233
  • 415

How to batch label features using Python (Qgis)PyQGIS?

Tweeted twitter.com/StackGIS/status/817691548292939776
Source Link

How to batch label features using Python (Qgis)

I am writing a python script to label features (lines). However I can't figure out:

  1. how to get the script to turn on the buffer

  2. how to get the script to apply the changes. When I currently run it, it changes everything in the properties (except the buffer) but I still have to hit ok before QGIS applies it to the map.

.

layer = iface.activeLayer()
layer.setCustomProperty("labeling/fieldName", "Length" )
layer.setCustomProperty("labeling/placement", QgsPalLayerSettings.Horizontal)
layer.setCustomProperty("labeling/predefinedPointPosition", QgsPalLayerSettings.BottomRight)
layer.setCustomProperty("labeling/fontSize","10" )
layer.setCustomProperty("labeling/buffer",QgsPalLayerSettings.BufferDraw)
layer.setCustomProperty("labeling/enabled","true" )
layer.triggerRepaint()

I have had a look at one similar question but I cannot seem to figure it out: Labeling line features using PyQGIS?

Once I get this to work I want to transform it into a batch-script by adding some lines like:

for layer in QgsMapLayerRegistry.instance().mapLayers().values():