I'm trying to convert a line shapefile to a raster image at QGis, but my attempts have been unsuccessful. I've tried to use Raster/Conversion/Rasterize and SAGA/Grid - gridding/Shapes to grid, but to no avail. Is there any other way to accomplish this?
From GDAL Rasterize Help:
The following would burn all "class A" buildings into the output elevation file, pulling the top elevation from the ROOF_H attribute.
gdal_rasterize -a ROOF_H -where 'class="A"' -l footprints footprints.shp city_dem.tif
I bet that it ain't black but it just looks like black.
This is how the default screen looks like
There are couple of issues here. The first one is that user must select an attribute field even it may not contain any reasonable values to be burned into the raster. The other trouble is that user cannot select output format and options for it. The first issue (if it is an issue) can be avoided by editing the request by hand and use a fixed burn value http://gdal.org/gdal_rasterize.html. The edited request for burning value "200" into the target raster would look like
gdal_rasterize -burn 200 -ts 3000 3000 -l line C:\temp\line.shp C:/temp/line2raster.tif
The effect of using default outputformat gets clear by running gdalinfo for the result:
C:\temp\>gdalinfo line2raster.tif Driver: GTiff/GeoTIFF .... Band 1 Block=3000x1 Type=Float64, ColorInterp=Gray Min=0.000 Max=180.000 Minimum=0.000, Maximum=200.000, Mean=0.731, StdDev=11.447 Metadata: STATISTICS_MAXIMUM=200 STATISTICS_MEAN=0.73090909090909 STATISTICS_MINIMUM=0 STATISTICS_STDDEV=11.446807776165
Oh dear, gdal_rasterize is using type Float64 as default and we burned lines with value 200 which is very close to totally black with this scale. For making the line visible we must adjust QGIS to render the image according to the histogram.
Stretch rendering to min-max and lines will show. However, what you probably want to do is to create an 8-bit tiff instead of Float64 and that can be done by editing the gdal_rasterize command further by adding "-ot byte" parameter. Final command row would look like
gdal_rasterize -burn 200 -ts 3000 3000 -ot byte -l line C:\temp\line.shp C:/temp/line2raster.tif
I would create QGIS feature request: Let user to select burn value and output data type manually. Float64 is a bad default for most users.
Working on QGis version 2.8.2-Wien I mannaged to rasterize a line shapefile using the Treatment > Toolbox > GDAL/OGR > Conversion > Rasterize (vector to raster) script. My GDAL/OGR version is 1.11.2.
Parameters input was quite strait-forward and it returned me a GeoTIFF image. You can choose the number of bite, format,... The code is also generated and you can reuse in a GDAL/OGR console (but I don't really know how).