I'm trying to polygonize 2 band raster(which was previously reclassified) and put values of each band into seperate attribute table column. Both bands overlap each other perfectly.
This piece of code works perfectly for 1 band rasters:
shapeFile = "shape1.shp" driver = ogr.GetDriverByName("ESRI Shapefile") outDS = driver.CreateDataSource(shapeFile) outLayer = outDS.CreateLayer("lyr1", srs) f1 = ogr.FieldDefn('DN', ogr.OFTInteger) f2 = ogr.FieldDefn('DIF', ogr.OFTInteger) outLayer.CreateField(f1) outLayer.CreateField(f2) gdal.Polygonize(raster.dataset.GetRasterBand(1), rasterMask, outLayer, 0, , callback=None ) #gdal.Polygonize(raster.dataset.GetRasterBand(2), rasterMask, outLayer, 1, , callback=None )
However the commented piece of code where I try to put pixel values of 2nd band into the 'DIF' field doesn't work (and it's field index is 1, I've checked that).
The Polygnize function doesn't seem to have an option for multiple band rasters and I'm not sure if calling it 2 times in a row is even a good idea.
I was thinking of polygonizing each band to a different shapefile and then somehow merging those shapefiles to match each field value but I'm not even sure if that's possible.
How should I proceed?