Skip to main content
added 2 characters in body
Source Link
Jochen Schwarze
  • 14.9k
  • 8
  • 54
  • 120

Provided, your project has a layer 'col19_line' you can use

mylayer = QgsProject.instance().mapLayersByName('col19_line')[0]

in QGISPyQGIS 3.

Since various layers may have the same in QGIS, the method mapLayersByName retrieves a list of layers matching the given name and list[0] returns the first element in a list in Python, so assumed that the layer name is unique the above statement will return exacly your layer.

Provided, your project has a layer 'col19_line' you can use

mylayer = QgsProject.instance().mapLayersByName('col19_line')[0]

in QGIS 3.

Since various layers may have the same in QGIS, the method mapLayersByName retrieves a list of layers matching the given name and list[0] returns the first element in a list in Python, so assumed that the layer name is unique the above statement will return exacly your layer.

Provided, your project has a layer 'col19_line' you can use

mylayer = QgsProject.instance().mapLayersByName('col19_line')[0]

in PyQGIS 3.

Since various layers may have the same in QGIS, the method mapLayersByName retrieves a list of layers matching the given name and list[0] returns the first element in a list in Python, so assumed that the layer name is unique the above statement will return exacly your layer.

Source Link
Jochen Schwarze
  • 14.9k
  • 8
  • 54
  • 120

Provided, your project has a layer 'col19_line' you can use

mylayer = QgsProject.instance().mapLayersByName('col19_line')[0]

in QGIS 3.

Since various layers may have the same in QGIS, the method mapLayersByName retrieves a list of layers matching the given name and list[0] returns the first element in a list in Python, so assumed that the layer name is unique the above statement will return exacly your layer.