Geographic Information Systems Asked on August 17, 2021
Is there a way to change display name of layer without changing layer name ? The field ‘displayed as’ is disabled and based on the field ‘layer name’.
You need to use the layer id
to call a specific layer instead of the layer name
. Changing the name
does not change the id
:
project = qgis.core.QgsProject.instance()
tree = project.layerTreeRoot().children()
layer = tree[0].layer()
print(f'type={type(layer)}') # type=<class 'qgis._core.QgsVectorLayer'>
print(f'id={layer.id()}') # id=New_scratch_layer_83348484_7916_4fe4_a137_2b98949ba488
print(f'name={layer.name()}') # name=New scratch layer
layer.setName('new name')
print(f'id={layer.id()}') # id=New_scratch_layer_83348484_7916_4fe4_a137_2b98949ba488
print(f'name={layer.name()}') # name=new name
Correct answer by Comrade Che on August 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP