123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <h2>DESCRIPTION</h2>
- <em>r.category</em> prints the category values and labels for the raster map
- layer specified by <b>map=</b><em>name</em> to standard output. You can also
- use it to set category labels for a raster map.
- <p>
- The user can specify all needed parameters on the command line, and run the
- program non-interactively. If the user does not specify any categories
- (e.g., using the optional <b>cats=</b><em>range</em>[,<em>range</em>,...]
- argument), then all the category values and labels for the named raster map
- layer that occur in the map are printed. The entire <em>map</em> is read
- using <em><a href="r.describe.html">r.describe</a></em>, to determine which
- categories occur in the <em>map</em>. If a listing of categories is
- specified, then the labels for those categories only are printed. The
- <em>cats</em> may be specified as single category values, or as ranges of
- values. The user may also (optionally) specify that a field separator other
- than a space or tab be used to separate the category value from its
- corresponding category label in the output, by using the
- <b>separator=</b><em>character</em>|<em>space</em>|<em>tab</em> option (see example
- below). If no field separator is specified by the user, a tab is used to
- separate these fields in the output, by default.
- <p>
- The output is sent to standard output in the form of one category per line,
- with the category value first on the line, then an ASCII TAB character (or
- whatever single character or space is specified using the <b>separator</b>
- parameter), then the label for the category.
- <h2>NOTES</h2>
- Any ASCII TAB characters which may be in the label are replaced by spaces.
- <p>The output from <em>r.category</em> can be redirected into a file, or piped into
- another program.
- <h3>Input from a file</h3>
- The <b>rules</b> option allows the user to assign category labels from values
- found in a file. The label can refer to a single category, range of
- categories, floating point value, or a range of floating point values.
- The format is given as follows (when separator is set to colon; no white space
- must be used after the separator):
- <div class="code"><pre>
- cat:Label
- val1:val2:Label
- </pre></div>
- If the filename is given as "-", the category labels are read from <tt>stdin</tt>
- <h3>Default and dynamic category labels</h3>
- Default and dynamic category labels can be created for categories that
- are not explicitly labeled.
- The coefficient line can be followed by explicit category labels
- which override the format label generation.
- <div class="code"><pre>
- 0:no data
- 2: .
- 5: . ## explicit category labels
- 7: .
- </pre></div>
- explicit labels can be also of the form:
- <div class="code"><pre>
- 5.5:5:9 label description
- or
- 15:30 label description
- </pre></div>
- <p>In the format line
- <ul>
- <li><tt>$1</tt> refers to the value <tt>num*5.0+1000</tt> (ie, using the first 2 coefficients)
- <li><tt>$2</tt> refers to the value <tt>num*5.0+1005</tt> (ie, using the last 2 coefficients)
- </ul>
- <tt>$1.2</tt> will print <tt>$1</tt> with 2 decimal places.
- <p>Also, the form <tt>$?xxx$yyy$</tt> translates into <tt>yyy</tt> if the category is 1, xxx
- otherwise. The <tt>$yyy$</tt> is optional. Thus
- <p> <tt>$1 meter$?s</tt>
- <p>will become: <br>
- <tt>1 meter</tt> (for category 1)<br>
- <tt>2 meters</tt> (for category 2), etc.
- <p>
- <tt>format='Elevation: $1.2 to $2.2 feet' ## Format Statement</tt><br>
- <tt>coefficients="5.0,1000,5.0,1005" ## Coefficients</tt>
- <p>The format and coefficients above would be used to generate the
- following statement in creation of the format appropriate category
- string for category "num":
- <p>
- <tt>sprintf(buff,"Elevation: %.2f to %.2f feet", num*5.0+1000, num*5.0*1005)</tt>
- <p>Note: while both the format and coefficient lines must be present
- a blank line for the format string will effectively suppress
- automatic label generation.
- <!--
- Note: quant rules of Categories structures are heavily dependant
- on the fact that rules are stored in the same order they are entered.
- since i-th rule and i-th label are entered at the same time, we
- know that i-th rule maps fp range to i, thus we know for sure
- that cats.labels[i] corresponds to i-th quant rule
- -->
- <p>To use a "<tt>$</tt>" in the label without triggering the plural test,
- put "<tt>$$</tt>" in the format string.
- <p>Use 'single quotes' when using a "<tt>$</tt>" on the command line to
- avoid unwanted shell substitution.
- <h2>EXAMPLES</h2>
- North Carolina sample dataset:
- <h3>Printing categories</h3>
- <div class="code"><pre>
- r.category map=landclass96
- 1 developed
- 2 agriculture
- 3 herbaceous
- 4 shrubland
- 5 forest
- 6 water
- 7 sediment
- </pre></div>
- prints the values and labels associated with all of the categories in the
- <em>landclass96</em> raster map layer.
- <p>
- <div class="code"><pre>
- r.category map=landclass96 cats=2,5-7
- 2 agriculture
- 5 forest
- 6 water
- 7 sediment
- </pre></div>
- prints only the category values and labels for <em>landclass96</em> map layer
- categories <tt>2</tt> and <tt>5</tt> through <tt>7</tt>.
- <p>
- <div class="code"><pre>
- r.category map=landclass96 cats=3,4 separator=comma
- 3,herbaceous
- 4,shrubland
- </pre></div>
- prints the values and labels for <em>landclass96</em> map layer categories
- <tt>3</tt> and <tt>4</tt>, but uses "<tt>,</tt>" (instead of a tab)
- as the character separating the category values from the category
- values in the output.
- <h3>Adding categories</h3>
- Example for defining new category labels, using a colon as separator:
- <div class="code"><pre>
- r.category diseasemap separator=":" rules=- << EOF
- 1:potential absence
- 2:potential presence
- EOF
- </pre></div>
- This sets the categoy values 1 and 2 to respective text labels.
- Alternatively, the rules can be stored in an ASCII text file and loaded
- via the <em>rules</em> parameter.
- <h2>SEE ALSO</h2>
- UNIX Manual entries for <i>awk</i> and <i>sort</i>
- <p>
- <em>
- <a href="d.what.rast.html">d.what.rast</a>,
- <a href="r.coin.html">r.coin</a>,
- <a href="r.describe.html">r.describe</a>,
- <a href="r.support.html">r.support</a>
- </em>
- <h2>AUTHORS</h2>
- Michael Shapiro, U.S. Army Construction Engineering Research Laboratory<br>
- Hamish Bowman, University of Otago, New Zealand (label creation options)
- <p><i>Last changed: $Date$</i>
|