Guest User

Untitled

a guest
Jul 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. my_layer = QgsVectorLayer('Polygon', 'My layer', 'memory')
  2. QgsMapLayerRegistry.instance().addMapLayer(my_layer, False)
  3.  
  4. # I want to place the layer at a specified position in the layer tree.
  5. root_node = QgsProject.instance().layerTreeRoot()
  6. root_node.insertLayer(3, my_layer)
  7.  
  8. label = QgsPalLayerSettings()
  9. label.readFromLayer(my_layer)
  10. label.enabled = True
  11. label.fieldName = '$area'
  12. label.writeToLayer(my_layer)
  13.  
  14. my_layer.setCustomProperty('labeling', 'pal')
  15. my_layer.setCustomProperty('labeling/enabled', 'true')
  16. my_layer.setCustomProperty('labeling/fieldName', '$area')
  17.  
  18. my_layer.triggerRepaint()
  19. iface.mapCanvas().refresh()
  20.  
  21. my_layer.setCustomProperty("labeling/drawLabels", "True")
  22.  
  23. label.drawLabels = True
  24.  
  25. label.isExpression = True
  26.  
  27. label.drawLabels = True
Add Comment
Please, Sign In to add comment