Skip to main content

Temporary layer has no attribute '__getitem__' with pyqgis

I used the polygonize tool in order to polygonize a raster layer and it worked well, but now, I would like to save this new vector layer as a temporary layer.

Thanks to the different posts I read, my code is the following :

grid = QgsVectorLayer("Polygon?crs=epsg:4326", 
                      "Grid_"+str(self.id), 
                      "memory")

#grid = self.pabs+"/1_Grids/Grid_"+str(self.id)+".shp" #non temporary layer initially used

layer = self.pabs+"/0_Inputs/LandUse/lu_{}.tif".format(self.id)
processing.runalg('gdalogr:polygonize',layer,"lu_majorit",grid)

When I execute the code in the python console of Qgis I get:

'QgsVectorLayer' object has no attribute '__ getitem__'

I know that you sometimes have this problem with python class but here I don't see where the problem comes from.

I was wondering if it is linked to the fact I create an empty layer ?

I am using QGIS 2.18.10

J.Delannoy
  • 505
  • 2
  • 19