i have a tif file which I polygonized using gdal.Polygonize() method. As a result I got a vector layer with millions of polygons and values from 1 to 255 in the attribute table. Although I don't mind such huge number of polygons I would like to merge those which have the same values in the attribute table. Could you tell me if there is a way to do it programmatically using any GDAL/OGR tools?
You're looking for a "Dissolve polygons" tool. QGIS by default offers two implementations, one as part of its internal toolset (QGIS geoalgorithms --> Vector Geometry Tools --> Dissolve ) and one part of the GDAL/OGR toolset (GDAL/OGR --> OGR Geoprocessing --> Dissolve Polygons ). There's one more in the SAGA toolset as well.
All of them differ slightly in the options they offer, but the GDAL/OGR tool is the most "verbose", allowing a lot of customization. So I'd recommend that for most cases.
If you want to use any of these programmatically, I'd recommend using
processing.runalg() to run them properly in your script.