{"word_count": 151, "character_count": 1247}
Get the current layerOften, you'll have to perform operations on the active layer.Before performing these operations, you first have to identify it and get it.Once you have it, you can perform all the operations you'll want.In the following lines, i've included print statements so as to check the content of my variables.&#62;&#62;&#62;mc=iface.getMapCanvas()&#62;&#62;&#62; mycurrentlayer=mc.currentLayer()&#62;&#62;&#62; print mycurrentlayer.getLayerID()lakes20090310215511168&#62;&#62;&#62; print mycurrentlayer.name()lakesFirts of all, put the canvas in the variable mc.&#62;&#62;&#62;mc=iface.getMapCanvas()Once you have your canvas, get its current layer called mycurrentlayer.&#62;&#62;&#62; mycurrentlayer=mc.currentLayer()You can see some methods have been applied to the layer:the method getLayerID()the method name()The layer name is only useful when displayed.The layer id is often used whe performing operations on the layer.Get a layer according according to its position in the legend&#62;&#62;&#62; mc=iface.getMapCanvas()&#62;&#62;&#62; myfirstlayer=mc.getZpos(1)The method getZpos allows you to get a layer according to its position in the legend.This kind of routine is often used when you need to get layers with their indexes