Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a small plugin that needs to be able to select a vector layer programatically based on what layer the user has selected. However I'm not sure how to do so.

I believe I found the two elements I need to make it work: setCurrentLayer and selectedLayer from the QgisLegendInterface, but I'm not certain how they work or how they are implemented, I cannot either find any examples of them other than in the API.

Am I close? Or is there a better/proper form of doing this?

share|improve this question
try to read ..most probably you would be able to answer yourself then – vinayan Mar 7 '13 at 2:55
up vote 1 down vote accepted

You can use the qgis.util.iface object which will give you access to all layers including the current selected layer:

myLayer = qgis.utils.iface.activeLayer()

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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