Raster Categories and Attributes

In the raster data model, cell category numbers can be one of two things: either they are measurements of real-life surface values (light intensity in images, height in digital terrain models, slope, temperature, etc) or they represent classes of categories (scanned maps, land use, soil types, etc). In the first case, labels are not very necessary since the type of map defines the type of values themselves, in the second, they are indispensable in order to document the meaning of the category numbers.

In GRASS, the raster map is stored in a binary file which contains the category numbers for each cell. The category labels are stored in a text file which contains the category numbers with their respective labels. This chapter will look at different aspects of the management of categories.

Viewing category values

The first thing you might wish to do is see which category values are present in your raster file. Here is a list of modules you can use for this purpose:

For more information on statistics and reports, see the chapter called Statistics and Reports.

Changing category values

You have to distinguish between changing the category values of a map and changing the category labels. Actually the first is not really possible without creating a new map, dropping the old one and renaming the new one to the old one's name. You can do the latter directly on a map.

In order to create a new map by changing the category values of an already existing one, you can use the following modules:

For changing the category labels of a raster map, use r.support. Enter 'y' when you get to the question "Edit the category file for [mapname]?". You will get to a screen showing the highest category number. You normally don't want to change that, so just go on by typing ESC-RETURN to enter the category table 'editor'. To go on to the next screen of the editor, type ESC-RETURN again. To finish, just type 'end' at the "Next category" prompt.

You might wish to automate the assigning of labels. Here's an example of how you could use r.stats and r.reclass to assign the total area size in square meters of each category to each cell of that respective category: r.stats -qan in=map | awk '{printf "%d=%d %d sq meters\n", $1, $1, $2}' | r.reclass in=map out=newmap[1]

Notes

[1]

This example was taken from M. Neteler, H. Mitasova, 2002. Open Source GIS: A GRASS GIS Approach, p. 84.