The software I'm using is QGis 3.16.0.

In order for a study project, I need to rasterise a vector layer (polygons) in order to classify certain classes of a certain attribute column with the process "Reclassify by table".

The attribute COVERTYPE consists of eight classes: AGR, BAR, CON, HDW, MIX, SHB, URB and WAT.

I tried to rasterise my vector field using the SAGA Tool "Rasterise". As "Attribute" I chose COVERTYPE, which is the correct one. For my other options please look at this screenshot:

enter image description here

Might there be any wrong settings in my configuration? I'm not that familiar with rasterising just yet...

For my rasterised layer, I just want to have eight different classes as well which I can classify then easily with the raster calculator. How do I know now, after I successfully rasterised my vector layer, which value represents which class?

By looking at the histogramm of my rasterised layer, there should be just eight different pixel values, instead I see many different pixel values, although my attribute covertype just has eight different classes. See also: enter image description here

For your information, during the SAGA Rasterise process, there is the following warning: selected attribute is not numeric; generating unique identifiers instead. See also:

enter image description here

Could that be the problem? Firstly, do I have to give my attributes AGR, BAR, and so on numbers? That wouldn't quite be possible, because I have around 1000 objects...

Is there any other process which is better for my certain purpose? Unfortunately, the process "Rasterise (vector to raster)" doesn't even work, there is no output map.

  • "The software I'm using is the recent version of QGIS": always include the version number. There are at least two "recent" versions: the long term release LTR (3.10) and the newest (3.16), each of them having different point releases, at the moment (2021/01/15) 3.10.14 and 3.16.3 respectively, see: qgis.org/en/site/getinvolved/development/… or on the upper left corner of qgis.org
    – Babel
    Jan 24, 2021 at 12:09

1 Answer 1


Update: How to solve your problem

Inspecting your data, I discovered that there were no less than three (interconnected) problems (instead of one, as assumed previously) using SAGA rasterize. All have to do with the fact that the tool expects a certain kind of numerical input.

You can solve your problem in two ways: use GRASS v.to.rast (see bottom for this) or continue to use SAGA rasterize by apply the following three measures:

  1. Use a numeric field as input categories for rasterize, not a string (details how to create that in the next section)

  2. Use field type integer 64 bit (qlonglong) for this numerical field. Using field type integer (int) as you had in your data did not produce the desired result (it created a diferent raster value for each feature).

  3. Delete other fields from the attributes in integer 64 bit data type. In the file you provided, there was an fid field in integer 64 bit type. Only after deleting the fid (use: Refactor fields), SAGA rasterize runs as expected. However, you must use the temporary layer created by Refactor fields: if you save it as Geopackage file, it will automatically add another fid field.

How to create a numerical input for rasterize

As you guessed, the problem is that QGIS expects a numeric value as input to create raster values. The error message says that instead, for each feature (polygon) it creates another raster value. That is not what you want. Weird enough, SAGA rasterize seems to accept only integer 64 bit input. When the field you define as input has another type, the tool seems to use just another field for input with the "right" datatype, the fid in this case. So be sure to set the correct datatype (see screenshot).

Create a new field, a numeric code for your covertype: AGR=1, BAR=2, CON=3 etc. that you can use as attribute input in the rasterize dialog. Use field calculator with this expression to create an attribute covertype_code.

when  "COVERTYPE" =  'AGR' then 1
when  "COVERTYPE" =  'BAR' then 2
when  "COVERTYPE" =  'CON' then 3
when  "COVERTYPE" =  'HDW' then 4
when  "COVERTYPE" =  'MIX' then 5
when  "COVERTYPE" =  'SHB' then 6
when  "COVERTYPE" =  'URB' then 7
when  "COVERTYPE" =  'WAT' then 8

enter image description here

Alternative solution

However, using the GRASS tool v.to.rast produced the desired result even with the original data you provided (as interger, not integer 64 bit), see screenshot:

enter image description here

  • 1
    QGIS assigns the number you have defined: see my answer: AGR will have raster value 1, BAR raster value 2 and so on. Or did I misunderstand your question? Singleband Pseudocolor would be a good choice (not the only one), you could use the viridis color palette and set the number of classes to 8 (or the number of covertypes you have).
    – Babel
    Jan 24, 2021 at 17:00
  • 1
    See screenshot: i.stack.imgur.com/LGwJX.png - the labels in the map canvas come from the polygon field covertype_code, but you see that the classes correspond to the ones in the raster. I selected pseudocolor. If you select grayscale, 1 (the smallest value) will be black, 8 (the highest value) will be white. If you select Paletted/Unique values, you can assign colors by hand.
    – Babel
    Jan 24, 2021 at 17:15
  • 1
    From the first screenshot it seems as if you had another field than covertype_code as input, however the last screenshot shows otherwise. Can you provide sample data? It's difficult to follow what you did/what went wrong when I use just random data.
    – Babel
    Jan 24, 2021 at 18:08
  • 1
    See updated answer: v.to.rast works. Don't know what's the issue with rasterize - used it today with ca. 150 features, grouped in 8 categories as described in my first answer, worked perfect. With your data, I got the different raster values for each feature - strange.
    – Babel
    Jan 24, 2021 at 20:26
  • 1
    OK, I just successfully run rasterize tool, not sure yet what was the reason, will come back with more information.
    – Babel
    Jan 24, 2021 at 20:36

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.