29

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?

4 Answers 4

14

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.

1
  • 1
    Thank you, this works. I updated gdal on ubuntu 11.10 (oneiric) to version 1.9 "unstable". Not so easy, see launchpad.net/~ubuntugis/+archive/ubuntugis-unstable .Then I could get the correct commandline-syntax from qgis raster-menu -> convert -> rasterize. On the linux-commandline I added -tr and -te and got the raster without creating an "empty one" first.
    – stn
    Commented Apr 2, 2012 at 23:46
6

you can also use SAGA GIS (also opensource like QGIS) - there is a tool in Modules/Grid/Gridding/Shapes to grid. I am not familiar with GRASS and the raster tools is QGIS are not enough for me, so I use QGIS together with SAGA and it works very well.

4
  • 1
    Checking out saga-gis now. On ubuntu saga version 2.0.8 can be compiled from source (sourceforge.net/projects/saga-gis/files) or version 2.0.7 can be installed as binary from PPA (sourceforge.net/apps/trac/saga-gis/wiki/Binary%20Packages). Apparently most GIS-filetypes have to be imported (see saga-gis-wiki). In that matter QGIS is a bit better because it opens most gis-files natively without conversion. But, if the tools of saga-gis are better that is certainly a good argument for saga-gis.
    – stn
    Commented Apr 3, 2012 at 9:11
  • 1
    First impression: The tools-collection is Huge :-)
    – stn
    Commented Apr 3, 2012 at 9:32
  • 2
    holy crap this thing is hard to install on a mac Commented Dec 26, 2014 at 22:33
  • 1
    You can also access this module through the qgis processing toolbox. Just search shapes to grid.
    – user55937
    Commented Feb 20, 2016 at 15:46
6

There are good answers here and I realize the question is a little old, but just to help with completeness here's another approach. You can also use the v.to.rast.* GRASS modules, which are available through the Processing toolbox in QGIS. It lets you set the raster resolution and extents. enter image description here

2
  • 1
    GRASS GIS 7.0.5 doesn't let me choose the cell size in v.to.rast. My first humble attempts left me with a total of 10 pixels for the vector contour lines of an area of 5 square km. I am guessing I have to create a raster resolution somewhere?
    – Alex
    Commented Apr 4, 2017 at 1:58
  • 1
    When you say it doesn't let you choose a cell size, does the gui not let you enter in a number, or does it just ignore then resolution you entered? Also, are you working in lat long or a projected crs?
    – user55937
    Commented Apr 4, 2017 at 11:55
0

if you are arcgis user you can do this with Feature to Raster tool.

ArcToolbox > Conversion Tools > To Raster > Feature to Raster

from dialog box, do following instructions.

The vector dataset
The field to assign values to features
The output raster name and location
The cell size for the output raster dataset

i hope it helps you

1
  • 1
    Yes, I know. Unfortunately no arcgis available here, too expensive for me :-) GRASS has these functions too, but I find QGIS sooo much easier to handle.
    – stn
    Commented Apr 2, 2012 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.