I'm writing a qgis plugin which needs a fixed-distance-buffer algorithm and must add the buffer result to the map layers of the software.

I have the following code:

# these are my import list
import os.path

import qgis.core
# Initialize Qt resources from file resources.py
import resources
import processing
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
from PyQt4.QtGui import QAction, QIcon

and the main part in run() method is:

    # region adding vector layers
    layers = self.iface.legendInterface().layers()
    layer_list = []
    for layer in layers:
        if layer.type() == qgis.core.QgsMapLayer.VectorLayer:
    # region crime inputs and crime instance

    self.cInput = self.dlg.comboBox_input_Crime

after the if statement in run() method:

self.pic = self.cInput.currentIndex()
self.selectedCrime = layers[self.pic]
buff=  processing.runalg('qgis:fixeddistancebuffer', layers[self.pic], 100, 50, False, None)

now when I run my plugin, after a progress bar appears, it shows an error of TypeError: QgsMapLayerRegistry.addMapLayer(QgsMapLayer, bool addToLegend=True): argument 1 has unexpected type 'dict'!

please explain what's the problem?

1 Answer 1


you are trying to load as a layer a vector object called buff. As you can see in the qgis:fixeddistancebuffer doc the output is dictionary with "OUTPUT" entry :


So when you try to load this vector as a layer with


Python returns an exception cause addMapLayer() method is waiting for a QgsMapLayer class which could be a vectorLayer in your case or rasterLayer as well.

so, create a new vectorLayer and populate it with your new shape OUTPUT and push it to your QgsMapLayerRegistry :

buffLyr =  QgsVectorLayer(buff['OUTPUT'], "buffer", "ogr")    
  • the solution above gives this error: 'TypeError: QgsVectorDataProvider.addFeatures(list-of-QgsFeature) -> (bool, list-of-QgsFeature): argument 1 has unexpected type 'list'
    – Ash
    Oct 21, 2017 at 23:09
  • 1
    my fault. because you have only one buff feature, use addfeature instead of addfeatures. I edited the post Oct 22, 2017 at 6:42
  • i'm sorry but it gives : TypeError: QgsVectorLayer.addFeature(QgsFeature, bool alsoUpdateExtent=True): argument 1 has unexpected type 'dict' now.
    – Ash
    Oct 22, 2017 at 8:05
  • 1
    I am sorry cause i didn't test on my side, I learned something that processing algorithm output are dict (as your error show). So i change again the code to feet your need and I tested this time, with a shorter code. according your code is correct this should work now, and I hope you will understand why. Oct 22, 2017 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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