Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my_layer = QgsVectorLayer('Polygon', 'My layer', 'memory')
- QgsMapLayerRegistry.instance().addMapLayer(my_layer, False)
- # I want to place the layer at a specified position in the layer tree.
- root_node = QgsProject.instance().layerTreeRoot()
- root_node.insertLayer(3, my_layer)
- label = QgsPalLayerSettings()
- label.readFromLayer(my_layer)
- label.enabled = True
- label.fieldName = '$area'
- label.writeToLayer(my_layer)
- my_layer.setCustomProperty('labeling', 'pal')
- my_layer.setCustomProperty('labeling/enabled', 'true')
- my_layer.setCustomProperty('labeling/fieldName', '$area')
- my_layer.triggerRepaint()
- iface.mapCanvas().refresh()
- my_layer.setCustomProperty("labeling/drawLabels", "True")
- label.drawLabels = True
- label.isExpression = True
- label.drawLabels = True
Add Comment
Please, Sign In to add comment