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.
My code from various posts 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
None
parameter as output which will save the result as a temporary layer:processing.runalg('gdalogr:polygonize',layer,"lu_majorit",None)
. Or to load it immediately:processing.runandload('gdalogr:polygonize',layer,"lu_majorit",None)
.