[GIS] Rasterizing polyline data with QGIS/GDAL: custom line width

gdallineqgisraster

I need to make a raster from a polyline shapefile. However, when I use gdal_rasterize (either directly or through QGIS), all my lines are drawn one pixel wide, while I need them to be drawn with the stroke weight of 3. I've examined the documentation at http://www.gdal.org/gdal_rasterize.html, but couldn't find a parameter to do so.

I have in mind some workarounds, but is there a simpler way to do so? My workarounds are:
– render a raster 9 times smaller and blow it up
– write a script that reads the raster and outputs a 3×3 block into another raster whenever it reads a non-zero pixel

Best Answer

Hope this one helps.

Use GDAL rasterize to conver polyline to raster, then it is possible to run r.neighbors with a 3 (by 3) sized neighbourhood. see also in this post.

This is my result on some lines drew on WGS84. This is only a snapshot but the method works for all featurs and/or raster cells. Original polyline colored yellow, in black are the polyline to raster result. Then layered underneeth in red is the last raster with a 3 pixel "buffer".

example

It quite similar to the workaround you have suggested, but enable you to drop scripting and use GRASS tool instead. I find it to be most intuitive way to handle such a problem.