r.reclass GRASS Reference Manual r.reclass
NAME
r.reclass - Creates a new map layer whose category values
are based upon the user's reclassification of categories in
an existing raster map layer.
(GRASS Raster Program)
SYNOPSIS
r.reclass
r.reclass help
r.reclass input=name output=name [title=name]
DESCRIPTION
r.reclass creates an output map layer based on an input
raster map layer. The output map layer will be a
reclassification of the input map layer based on reclass
rules input to r.reclass, and can be treated in much the
same way that raster files are treated. A title for the
output map layer may be (optionally) specified by the user.
The reclass rules are read from standard input (i.e., from
the keyboard, redirected from a file, or piped through
another program).
The program will be run non-interactively if the user
specifies the name of the raster map layer to be
reclassified, the name of an output layer to hold reclass
rules, and (optionally) the name of a title for the output
map:
r.reclass input=name output=name [title=name]
After the user types in the above information on the command
line, the program will (silently) prompt the user for
reclass rules to be applied to the input map layer
categories. The form of these rules is described in further
detail in the sections on non-interactive program use
reclass rules and examples, below.
Alternately, the user can simply type r.reclass on the
command line, without program arguments. In this case, the
user will be prompted for all needed inputs.
Before using r.reclass one must know the following:
1 The new categories desired; and, which old categories
fit into which new categories.
2 The names of the new categories.
INTERACTIVE PROGRAM USE: EXAMPLE
Suppose we want to reclassify the raster map layer roads,
consisting of five categories, into the three new
GRASS 4.1 U.S. Army CERL 1
r.reclass GRASS Reference Manual r.reclass
categories: paved roads, unpaved roads, and railroad tracks.
The user is asked whether the reclass table is to be
established with each category value initially set to 0, or
with each category value initially set to its own value. A
screen like that shown below then appears, listing the
categories of the roads raster map layer to be reclassified
and prompting the user for the new category values to be
assigned them.
ENTER NEW CATEGORY NUMBERS FOR THESE CATEGORIES
OLD CATEGORY NAME OLD NEW
NUM NUM
no data 0 0__
Hard Surface, 2 lanes 1 0__
Loose Surface, 1 lane 2 0__
Improved Dirt 3 0__
Unimproved Dirt Trail 4 0__
Railroad, single track 5 0__
AFTER COMPLETING ALL ANSWERS, HIT TO CONTINUE
(OR TO CANCEL)
In the following screen the new category values have been
entered beside the appropriate old category names. Cells
assigned category values 2, 3, and 4 in the old raster map
layer are now assigned the new category value 2 in the
reclassed map; cell data formerly assigned to category value
5 in the old raster map map are now assigned the new
category value 3 in the reclassed map.
ENTER NEW CATEGORY NUMBERS FOR THESE CATEGORIES
OLD CATEGORY NAME OLD NEW
NUM NUM
no data 0 0__
Hard Surface, 2 lanes 1 1__
Loose Surface, 1 lane 2 2__
Improved Dirt 3 2__
Unimproved Dirt Trail 4 2__
Railroad, single track 5 3__
AFTER COMPLETING ALL ANSWERS, HIT TO CONTINUE
(OR TO CANCEL)
Hitting the escape key will bring up the following
screen, which prompts the user to enter a new title and
category label for the newly reclassed categories.
GRASS 4.1 U.S. Army CERL 2
r.reclass GRASS Reference Manual r.reclass
ENTER NEW CATEGORY NAMES FOR THESE CATEGORIES
TITLE: Roads Reclassified
CAT NEW CATEGORY NAME
NUM
0 no data
1 Paved Roads
2 Unpaved Roads
3 Railroad, single track
AFTER COMPLETING ALL ANSWERS, HIT TO CONTINUE
(OR TO CANCEL)
Based upon the information supplied by the user in the above
sample screens, the new output map, supporting category,
color, history, and header files are created.
NON-INTERACTIVE PROGRAM USE: RECLASS RULES
In non-interactive program use, the names of an input map,
output map, and output map title are given on the command
line. However, the reclass rules are still read from
standard input (i.e., from the keyboard, redirected from a
file, or piped through another program).
Once the user has specified an input raster map layer,
output map layer name, and (optionally) output map layer
title by typing
r.reclass input=name output=name [title=name]
Each line of input must have the following format:
input_categories=output_category [label]
where the input lines specify the category values in the
input raster map layer to be reclassified to the new
output_category category value. Specification of a label to
be associated with the new output map layer category is
optional. If specified, it is recorded as the category
label for the new category value. The equal sign = is
required. The input_category(ies) may consist of single
category values or a range of such values in the format "low
thru high." The word "thru" must be present.
A line containing only the word end terminates the input.
NON-INTERACTIVE PROGRAM USE: EXAMPLES
The following examples may help clarify the reclass rules.
1 This example reclassifies categories 1, 3 and 5 in the
GRASS 4.1 U.S. Army CERL 3
r.reclass GRASS Reference Manual r.reclass
input raster map layer to category 1 with category label
"poor quality" in the output map layer, and reclassifies
input raster map layer categories 2, 4, and 6 to category
2 with the label "good quality" in the output map layer.
1 3 5 = 1 poor quality
2 4 6 = 2 good quality
2 This example reclassifies input raster map layer
categories 1 thru 10 to output map layer category 1,
input map layer categories 11 thru 20 to output map layer
category 2, and input map layer categories 21 thru 30 to
output map layer category 3, all without labels.
1 thru 10 = 1
11 thru 20 = 2
21 thru 30 = 3
3 Subsequent rules override previous rules. Therefore, the
below example reclassifies input raster map layer
categories 1 thru 19 and 51 thru 100 to category 1 in the
output map layer, input raster map layer categories 20
thru 24 and 26 thru 50 to the output map layer category
2, and input raster map layer category 25 to the output
category 3.
1 thru 100 = 1 poor quality
20 thru 50 = 2 medium quality
25 = 3 good quality
4 The previous example could also have been entered as:
1 thru 19 51 thru 100 = 1 poor quality
20 thru 24 26 thru 50 = 2 medium quality
25 = 3 good quality
or as:
1 thru 19 = 1 poor quality
51 thru 100 = 1
20 thru 24 = 2
26 thru 50 = 2 medium quality
25 = 3 good quality
The final example was given to show how the labels are
handled. If a new category value appears in more than one
rule (as is the case with new category values 1 and 2), the
last label which was specified becomes the label for that
GRASS 4.1 U.S. Army CERL 4
r.reclass GRASS Reference Manual r.reclass
category. In this case the labels are assigned exactly as
in the two previous examples.
NOTES
In fact, the r.reclass program does not generate any new
raster map layers (in the interests of disk space
conservation). Instead, a reclass table is stored which
will be used to reclassify the original raster map layer
each time the new (reclassed) map name is requested. As far
as the user (and programmer) is concerned, that raster map
has been created. Also note that although the user can
generate a r.reclass map which is based on another r.reclass
map, the new r.reclass map map will be stored in GRASS as a
reclass of the original raster map on which the first
reclassed map was based. Therefore, while GRASS allows the
user to provide r.reclass map layer information which is
based on an already reclassified map (for the user's
convenience), no r.reclass map layer (i.e., reclass table)
will ever be stored as a r.reclass of a r.reclass.
To convert a reclass map to a regular raster map layer, set
your geographic region settings to match the settings in the
header for the reclass map (an ASCII file found under the
cellhd directory, or viewable by running r.support) and then
run r.resample.
r.mapcalc can also be used to convert a reclass map to a
regular raster map layer:
r.mapcalc raster_map=reclass_map
where raster_map is the name to be given to the new raster
map, and reclass_map is an existing reclass map.
BEWARE
Because r.reclass generates a table referencing some
original raster map layer rather than creating a reclassed
raster map layer, a r.reclass map layer will no longer be
accessible if the original raster map layer upon which it
was based is later removed.
A r.reclass map is not a true raster map layer. Rather, it
is a table of reclassification values which reference the
input raster map layer. Therefore, users who wish to retain
reclassified map layers must also save the original input
raster map layers from which they were generated.
Category values which are not explicitly reclassified to a
new value by the user will be reclassified to 0.
SEE ALSO
r.resample, r.rescale
GRASS 4.1 U.S. Army CERL 5
r.reclass GRASS Reference Manual r.reclass
AUTHORS
James Westervelt, U.S. Army Construction Engineering
Research Laboratory
Michael Shapiro, U.S. Army Construction Engineering Research
Laboratory
GRASS 4.1 U.S. Army CERL 6