Converting raster to vector by generating center lines?
GRASS GIS is able do this.
You need two steps:
- r.thin
Thins non-null cells that denote linear features in a raster map layer.
- r.to.vect
Converts a raster map into a vector map.
Now it worked for me as @RoVo suggested before. The problem were the no-data values in my input raster. I changed these not with gdal_translate as @AndreJ suggests (in comments of answer above), but with GRASS r.mapcalc. Here the modules that I used:
Replace all no data values:
processing.runalg('grass:r.mapcalculator',
{"amap": gPb_rlayer,
"formula": "if(A>0, 1, null())",
"GRASS_REGION_PARAMETER": "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
"GRASS_REGION_CELLSIZE_PARAMETER": 1,
"outfile": mapcalc})
Thin raster layer to thin non-null cells:
processing.runalg('grass7:r.thin',
{"input": mapcalc,
"GRASS_REGION_PARAMETER": "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
"output": thinned})
Raster to vector conversion:
processing.runalg('grass7:r.to.vect',
{"input": thinned,
"type": 0,
"GRASS_OUTPUT_TYPE_PARAMETER": 2,
"GRASS_REGION_PARAMETER": "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
"output": centerlines})