I'm building a plugin in QGIS, one of its part is processing algorithm: intersection. I want to save the result as memory layer, and then work on it. Following code was working fine, nothing changed (I changed nothing), and: boom! it stopped working. The problem is in the 2nd line:

processing.runandload("qgis:intersection",selectedLayer,selectedLayer_2, "memory:temp_layer")
layer = QgsMapLayerRegistry.instance().mapLayersByName("memory:temp_layer")[0]

The memory layer is created (I can see it in QGIS) but I can't define 'layer'. I'm getting an error:

IndexError: list index out of range.

Why? :(

  • Ok, that's weird... Plugin works on different computer. I tested it on 4 computers, it was working on 2 of them, on the other 2 there was the same error.
    – antonio
    Mar 14, 2016 at 7:54
  • 1
    From where do you launch your code (inside Qgis or outside) (in the python Qgis console)?
    – SIGIS
    Mar 14, 2016 at 10:38
  • I edit the mainplugin.py code in code editor, save edits, reload plugin with reloader. So I guess the correct answer is that I launch it from outside.
    – antonio
    Mar 15, 2016 at 14:01

1 Answer 1


I suspect this is probably dependent on the Processing plugin version for each of those computers. Your following line checks the list of loaded layers and will only define layer if a layer has the name memory:temp_layer.

layer = QgsMapLayerRegistry.instance().mapLayersByName("memory:temp_layer")[0]

In the older versions of the Processing plugin, you can define the name of the memory layer "memory:any_name". The line above will work.

In the latest versions, the default name of the tool is used instead (e.g. "Intersection"). The line above will not work.

I would suggest checking the Processing plugin for each of your computers and updating it to the latest version (currently at 2.12.2) from the toolbar:

Plugins > Manage and Install Plugins...

And use the following line instead:

layer = QgsMapLayerRegistry.instance().mapLayersByName("Intersection")[0]
  • 1
    Thanks. I checked the version of Processing plugin and it was 2.12.99 while 'the available version is 2.12.2'. The information in plugin manager was: 'Installed version is NEWER than version available in official repository.' Well, that's interesting.I also did recommended changes in code and it works.
    – antonio
    Mar 15, 2016 at 14:08
  • @antonio - Haha that is interesting! Weird little glitch I guess but glad you got it working =)
    – Joseph
    Mar 15, 2016 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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