Skip to main content
Tweeted twitter.com/StackGIS/status/885712805319426048
deleted 19 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

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, myMy 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

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

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

edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
improving code format
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82
Loading
Source Link
J.Delannoy
  • 505
  • 2
  • 19
Loading