r.category.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <h2>DESCRIPTION</h2>
  2. <em>r.category</em> prints the category values and labels for the raster map
  3. layer specified by <b>map=</b><em>name</em> to standard output. You can also
  4. use it to set category labels for a raster map.
  5. <p>
  6. The user can specify all needed parameters on the command line, and run the
  7. program non-interactively. If the user does not specify any categories
  8. (e.g., using the optional <b>cats=</b><em>range</em>[,<em>range</em>,...]
  9. argument), then all the category values and labels for the named raster map
  10. layer that occur in the map are printed. The entire <em>map</em> is read
  11. using <em><a href="r.describe.html">r.describe</a></em>, to determine which
  12. categories occur in the <em>map</em>. If a listing of categories is
  13. specified, then the labels for those categories only are printed. The
  14. <em>cats</em> may be specified as single category values, or as ranges of
  15. values. The user may also (optionally) specify that a field separator other
  16. than a space or tab be used to separate the category value from its
  17. corresponding category label in the output, by using the
  18. <b>separator=</b><em>character</em>|<em>space</em>|<em>tab</em> option (see example
  19. below). If no field separator is specified by the user, a tab is used to
  20. separate these fields in the output, by default.
  21. <p>
  22. The output is sent to standard output in the form of one category per line,
  23. with the category value first on the line, then an ASCII TAB character (or
  24. whatever single character or space is specified using the <b>separator</b>
  25. parameter), then the label for the category.
  26. <h2>NOTES</h2>
  27. Any ASCII TAB characters which may be in the label are replaced by spaces.
  28. <p>The output from <em>r.category</em> can be redirected into a file, or piped into
  29. another program.
  30. <h3>Input from a file</h3>
  31. The <b>rules</b> option allows the user to assign category labels from values
  32. found in a file. The label can refer to a single category, range of
  33. categories, floating point value, or a range of floating point values.
  34. The format is given as follows (when separator is set to colon; no white space
  35. must be used after the separator):
  36. <div class="code"><pre>
  37. cat:Label
  38. val1:val2:Label
  39. </pre></div>
  40. If the filename is given as "-", the category labels are read from <tt>stdin</tt>
  41. <h3>Default and dynamic category labels</h3>
  42. Default and dynamic category labels can be created for categories that
  43. are not explicitly labeled.
  44. The coefficient line can be followed by explicit category labels
  45. which override the format label generation.
  46. <div class="code"><pre>
  47. 0:no data
  48. 2: .
  49. 5: . ## explicit category labels
  50. 7: .
  51. </pre></div>
  52. explicit labels can be also of the form:
  53. <div class="code"><pre>
  54. 5.5:5:9 label description
  55. or
  56. 15:30 label description
  57. </pre></div>
  58. <p>In the format line
  59. <ul>
  60. <li><tt>$1</tt> refers to the value <tt>num*5.0+1000</tt> (ie, using the first 2 coefficients)
  61. <li><tt>$2</tt> refers to the value <tt>num*5.0+1005</tt> (ie, using the last 2 coefficients)
  62. </ul>
  63. <tt>$1.2</tt> will print <tt>$1</tt> with 2 decimal places.
  64. <p>Also, the form <tt>$?xxx$yyy$</tt> translates into <tt>yyy</tt> if the category is 1, xxx
  65. otherwise. The <tt>$yyy$</tt> is optional. Thus
  66. <p> <tt>$1 meter$?s</tt>
  67. <p>will become: <br>
  68. <tt>1 meter</tt> (for category 1)<br>
  69. <tt>2 meters</tt> (for category 2), etc.
  70. <p>
  71. <tt>format='Elevation: $1.2 to $2.2 feet' ## Format Statement</tt><br>
  72. <tt>coefficients="5.0,1000,5.0,1005" ## Coefficients</tt>
  73. <p>The format and coefficients above would be used to generate the
  74. following statement in creation of the format appropriate category
  75. string for category "num":
  76. <p>
  77. <tt>sprintf(buff,"Elevation: %.2f to %.2f feet", num*5.0+1000, num*5.0*1005)</tt>
  78. <p>Note: while both the format and coefficient lines must be present
  79. a blank line for the format string will effectively suppress
  80. automatic label generation.
  81. <!--
  82. Note: quant rules of Categories structures are heavily dependant
  83. on the fact that rules are stored in the same order they are entered.
  84. since i-th rule and i-th label are entered at the same time, we
  85. know that i-th rule maps fp range to i, thus we know for sure
  86. that cats.labels[i] corresponds to i-th quant rule
  87. -->
  88. <p>To use a "<tt>$</tt>" in the label without triggering the plural test,
  89. put "<tt>$$</tt>" in the format string.
  90. <p>Use 'single quotes' when using a "<tt>$</tt>" on the command line to
  91. avoid unwanted shell substitution.
  92. <h2>EXAMPLES</h2>
  93. North Carolina sample dataset:
  94. <h3>Printing categories</h3>
  95. <div class="code"><pre>
  96. r.category map=landclass96
  97. 1 developed
  98. 2 agriculture
  99. 3 herbaceous
  100. 4 shrubland
  101. 5 forest
  102. 6 water
  103. 7 sediment
  104. </pre></div>
  105. prints the values and labels associated with all of the categories in the
  106. <em>landclass96</em> raster map layer.
  107. <p>
  108. <div class="code"><pre>
  109. r.category map=landclass96 cats=2,5-7
  110. 2 agriculture
  111. 5 forest
  112. 6 water
  113. 7 sediment
  114. </pre></div>
  115. prints only the category values and labels for <em>landclass96</em> map layer
  116. categories <tt>2</tt> and <tt>5</tt> through <tt>7</tt>.
  117. <p>
  118. <div class="code"><pre>
  119. r.category map=landclass96 cats=3,4 separator=comma
  120. 3,herbaceous
  121. 4,shrubland
  122. </pre></div>
  123. prints the values and labels for <em>landclass96</em> map layer categories
  124. <tt>3</tt> and <tt>4</tt>, but uses "<tt>,</tt>" (instead of a tab)
  125. as the character separating the category values from the category
  126. values in the output.
  127. <h3>Adding categories</h3>
  128. Example for defining new category labels, using a colon as separator:
  129. <div class="code"><pre>
  130. r.category diseasemap separator=":" rules=- &lt;&lt; EOF
  131. 1:potential absence
  132. 2:potential presence
  133. EOF
  134. </pre></div>
  135. This sets the categoy values 1 and 2 to respective text labels.
  136. Alternatively, the rules can be stored in an ASCII text file and loaded
  137. via the <em>rules</em> parameter.
  138. <h2>SEE ALSO</h2>
  139. UNIX Manual entries for <i>awk</i> and <i>sort</i>
  140. <p>
  141. <em>
  142. <a href="d.what.rast.html">d.what.rast</a>,
  143. <a href="r.coin.html">r.coin</a>,
  144. <a href="r.describe.html">r.describe</a>,
  145. <a href="r.support.html">r.support</a>
  146. </em>
  147. <h2>AUTHORS</h2>
  148. Michael Shapiro, U.S. Army Construction Engineering Research Laboratory<br>
  149. Hamish Bowman, University of Otago, New Zealand (label creation options)
  150. <p><i>Last changed: $Date$</i>