7

How do I get the layer by name using PyQGIS 3?

2
11

If you are sure there is one layer named LAYER_NAME, the shortest way:

layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

In that way, you can get a layer in a group layer.

print(layer)
# OUT: <qgis._core.QgsVectorLayer object at ...>
0
7
listLayers=QgsProject.instance().mapLayersByName('layername')

Retrieve a list of matching registered layers by layer name.

Not the answer you're looking for? Browse other questions tagged or ask your own question.