[GIS] Converting vector layer to raster using QGIS

convertqgisrastervector

In qgis in the raster menu there is an item "convert vector to raster".

This behaves strangely – I do not understand how it is supposed to work.

I can select a vector file, an attribute and an output raster. But, for some reason the output file is only accepted if it exists and even if I select an existing raster nothing seems to happen.

Also I do not understand how the program knows what kind of raster to create, what cell-size, projection etc.

How can I convert vector to raster?

Best Answer

Convert Vector to Raster wraps GDAL's gdal_rasterize, which until version 1.8.0, didn't create the output raster. So the cell size, projection, and so on are determined by the raster not the command line options.

It is something of a Catch-22 for sure because GDAL has no easy method of creating an empty image. You can try creating two one-pixel images for the top left and bottom right in a paint program, run gdal_translate on them to georeference them, then create a VRT from those, and finally use gdal_translate to convert from the VRT to a GeoTIFF or similar, but it is a pain for sure!

The better alternative would be to upgrade to GDAL >= 1.8.0 and use the new -tr and -te parameters of gdal_rasterize.

Related Question