r.compress.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <h2>DESCRIPTION</h2>
  2. <em>r.compress</em> can be used to compress or decompress raster maps.
  3. Additionally, it prints information about the compression method and
  4. data type of the input raster map(s).
  5. <p>
  6. All raster maps (those imported for the first time and those newly
  7. generated) are compressed by default using the ZLIB compression
  8. method (see below). Related no data files (i.e.: NULL files), if
  9. present, are not compressed by default unless a specific environment
  10. variable is set (<tt>GRASS_COMPRESS_NULLS</tt>, see below).
  11. <p>
  12. During compression or re-compression, <em>r.compress</em> compresses
  13. raster maps using the method specified by means of the environment
  14. variable <tt>GRASS_COMPRESSOR</tt>. The default compression method is
  15. ZLIB's "deflate" algorithm (LZ77-based). Raster maps that contain very
  16. little information (such as boundary, geology, soils and land use maps)
  17. can be greatly reduced in size. Some raster maps are shrunk to roughly
  18. 1% of their original sizes.
  19. All newly generated raster maps are automatically stored as compressed
  20. data with varying methods depending on the raster format (i.e.,
  21. CELL: integer; FCELL: single precision; DCELL: double precision; see
  22. below). All GRASS GIS modules are able to read both compressed and
  23. uncompressed raster maps.
  24. <!-- too old and RLE only example
  25. <p>
  26. As an example, the Spearfish data base raster map layer
  27. <em>owner</em> was originally a size of 26600 bytes. After
  28. it was RLE compressed, the raster map became only 1249 bytes
  29. (25351 bytes smaller).
  30. -->
  31. <p>
  32. Raster maps that are already compressed might be compressed again,
  33. either by setting a different method with <tt>GRASS_COMPRESSOR</tt>
  34. (RLE, ZLIB, LZ4, BZIP2) or, for the case of ZLIB compression, by
  35. changing the compression level with the environment variable
  36. <tt>GRASS_ZLIB_LEVEL</tt>.
  37. <p>
  38. Compressed raster maps may be decompressed using <em>r.compress</em> to
  39. return them to their original format, using the <b>-u</b> flag. If a
  40. raster map was already decompressed and the <b>-u</b> flag is set, the
  41. module simply informs the user that the map is already decompressed and
  42. exits.
  43. <p>
  44. Information about the compression method and data type of the input
  45. raster map(s) can be printed in shell style with the <b>-g</b> flag. In
  46. this case, the module prints to <tt>stdout</tt> one line per input map
  47. with the fields &quot;input map name&quot;, &quot;data type&quot;,
  48. &quot;name of data compression method&quot;, &quot;NULL file
  49. compression&quot; separated by the pipe character. NULL file
  50. compression is indicated with &quot;YES&quot; or &quot;NO&quot;.
  51. <h3>TERMINOLOGY</h3>
  52. <ul>
  53. <li> INTEGER map (CELL data type): a raster map of INTEGER type (whole
  54. numbers only)</li>
  55. <li> FLOAT map (FCELL data type): a raster map of FLOAT type (4 bytes,
  56. 7-9 digits precision)</li>
  57. <li> DOUBLE map (DCELL data type): a raster map of DOUBLE type (8 bytes,
  58. 15-17 digits precision)</li>
  59. <li> NULL: represents "no data" in raster maps; to be distinguished from
  60. 0 (zero) data value</li>
  61. </ul>
  62. <h3>OVERVIEW OF AVAILABLE COMPRESSION ALGORITHMS</h3>
  63. The following compression methods are available (set by
  64. <tt>export GRASS_COMPRESSOR=<em>method</em></tt>):
  65. <ul>
  66. <li><tt>NONE</tt> (uncompressed)</li>
  67. <li><tt>RLE</tt> (generic Run-Length Encoding of single bytes; deprecated)</li>
  68. <li><tt>ZLIB</tt> (DEFLATE, good speed and compression - <b>default compression</b>)
  69. <ul>
  70. <li>with zlib compression levels (<tt>export GRASS_ZLIB_LEVEL=X</tt>): -1..9
  71. (-1 is default which corresponds to ZLIB level 6)</li>
  72. <li>note: <tt>export GRASS_ZLIB_LEVEL=0</tt> is equal to copying the data
  73. as-is from source to destination</li>
  74. </ul>
  75. </li>
  76. <li><tt>LZ4</tt> (fastest, low compression)</li>
  77. <li><tt>BZIP2</tt> (slowest, high compression)</li>
  78. </ul>
  79. Important: the NULL file compression must be explicitly turned on with
  80. <tt>export GRASS_COMPRESS_NULLS=1</tt> - such raster maps can then only
  81. be opened with GRASS GIS 7.2.0 or later. NULL file compression can be
  82. managed with <b>r.null -z</b>.
  83. <h3>COMPRESSION ALGORITHM DETAILS</h3>
  84. <!-- keep in sync with raster/rasterintro.html -->
  85. All GRASS GIS raster map types are by default ZLIB compressed, i.e. using
  86. ZLIB's deflate algorithm. Through the environment variable
  87. <tt>GRASS_COMPRESSOR</tt> the compression method can be set to RLE, ZLIB,
  88. LZ4, or BZIP2.
  89. <p>
  90. Integer (CELL type) raster maps can be compressed with RLE if
  91. the environment variable <tt>GRASS_INT_ZLIB</tt> exists and is set to value
  92. 0. However, this is not recommended.
  93. <p>
  94. Floating point (FCELL, DCELL) raster maps never use RLE compression;
  95. they are either compressed with ZLIB, LZ4, BZIP2 or are uncompressed.
  96. <!-- BTW, why not having an option "method" and another one "level"
  97. instead of the environment variables? Is it too complicated?
  98. -->
  99. <dl>
  100. <dt><strong>RLE</strong></dt>
  101. <dd><b>DEPRECATED</b> Run-Length Encoding, poor compression ratio but
  102. fast. It is kept for backwards compatibility to read raster maps
  103. created with GRASS 6. It is only used for raster maps of type CELL.
  104. FCELL and DCELL maps are never and have never been compressed with RLE.
  105. </dd>
  106. <dt><strong>ZLIB</strong></dt>
  107. <dd>ZLIB's deflate is the default compression method for all raster
  108. maps. GRASS GIS 7 uses by default 1 as ZLIB compression level which is the
  109. best compromise between speed and compression ratio, also when
  110. compared to other available compression methods. Valid levels are in
  111. the range [1, 9] and can be set with the environment variable
  112. <tt>GRASS_ZLIB_LEVEL</tt>.</dd>
  113. <dt><strong>LZ4</strong></dt>
  114. <dd>LZ4 is a very fast compression method, about as fast as no
  115. compression. Decompression is also very fast. The compression ratio is
  116. generally higher than for RLE but worse than for ZLIB. LZ4 is
  117. recommended if disk space is not a limiting factor.</dd>
  118. <dt><strong>BZIP2</strong></dt>
  119. <dd>BZIP2 can provide compression ratios much higher than the other
  120. methods, but only for large raster maps (&gt; 10000 columns). For large
  121. raster maps, disk space consumption can be reduced by 30 - 50% when
  122. using BZIP2 instead of ZLIB's deflate. BZIP2 is the slowest compression
  123. and decompression method. However, if reading from / writing to a
  124. storage device is the limiting factor, BZIP2 compression can speed up
  125. raster map processing. Be aware that for smaller raster maps, BZIP2
  126. compression ratio can be worse than other compression methods.</dd>
  127. </dl>
  128. <h2>NOTES</h2>
  129. <h3>Compression method number scheme</h3>
  130. The used compression method is encoded with numbers. In the internal
  131. <tt>cellhd</tt> file, the value for "compressed" is 1 for RLE, 2
  132. for ZLIB, 3 for LZ4, and 4 for BZIP2.
  133. <p>
  134. Obviously, decompression is controlled by the raster map's compression,
  135. not by the environment variable.
  136. <h3>Formats</h3>
  137. Conceptually, a raster data file consists of rows of cells, with each
  138. row containing the same number of cells. A cell consists of one or more
  139. bytes. For CELL maps, the number of bytes per cell depends on the
  140. category values stored in the cell. Category values in the range 0-255
  141. require 1 byte per cell, while category values in the range 256-65535
  142. require 2 bytes, and category values in the range above 65535 require 3
  143. (or more) bytes per cell.
  144. <p>
  145. FCELL maps always have 4 bytes per cell and DCELL maps always have 8
  146. bytes per cell.
  147. <p>
  148. Since GRASS GIS 7.0.0, the default compression method for
  149. Integer (CELL) raster maps is ZLIB and no longer RLE.
  150. <h3>ZLIB compression levels</h3>
  151. If the environment variable <tt>GRASS_ZLIB_LEVEL</tt> exists and
  152. its value can be parsed as an integer, it determines the compression
  153. level used when newly generated raster maps are compressed using ZLIB
  154. compression. This applies to all raster map types (CELL, FCELL, DCELL).
  155. <p>
  156. <!-- TODO: check with implementation in lib/gis/gisinit.c line 128 -->
  157. If the variable does not exist, or the value cannot be parsed as an
  158. integer, ZLIB's compression level 1 will be used.
  159. <h2>EXAMPLES</h2>
  160. Printing of current compression state:
  161. <div class="code"><pre>
  162. r.compress compressed_no -p
  163. &lt;compressed_no&gt; (method 0: NONE). Data type: &lt;CELL&gt;
  164. </pre></div>
  165. <p>
  166. Applying RLE compression to a copy of the uncompressed map (not recommended!):
  167. <div class="code"><pre>
  168. # compression of map using the deprecated RLE compression
  169. g.copy raster=compressed_no,compressed_RLE
  170. export GRASS_INT_ZLIB=0 # RLE
  171. r.compress compressed_RLE
  172. r.compress compressed_RLE -p
  173. &lt;compressed_RLE&gt; is compressed (method 1: RLE). Data type: &lt;CELL&gt;
  174. unset GRASS_INT_ZLIB
  175. </pre></div>
  176. <p>
  177. Applying ZLIB compression to a copy of the uncompressed map:
  178. <div class="code"><pre>
  179. # compression of map using ZLIB compression
  180. g.copy raster=compressed_no,compressed_ZLIB
  181. export GRASS_INT_ZLIB=1 # ZLIB
  182. r.compress compressed_ZLIB
  183. r.compress compressed_ZLIB -p
  184. &lt;compressed_ZLIB&gt; is compressed (method 2: ZLIB). Data type: &lt;CELL&gt;
  185. unset GRASS_INT_ZLIB
  186. </pre></div>
  187. <p>
  188. Applying BZIP2 compression to a copy of the ZLIB-compressed map:
  189. <div class="code"><pre>
  190. # compression of map using BZIP2 compression
  191. g.copy raster=compressed_ZLIB,compressed_BZIP2
  192. export GRASS_COMPRESSOR=BZIP2 # BZIP2
  193. r.compress compressed_BZIP2
  194. r.compress compressed_BZIP2 -p
  195. &lt;compressed_BZIP2&gt; is compressed (method 4: BZIP2). Data type: &lt;CELL&gt;
  196. unset GRASS_COMPRESSOR
  197. </pre></div>
  198. <h2>SEE ALSO</h2>
  199. <em>
  200. <a href="r.info.html">r.info</a>,
  201. <a href="r.null.html">r.null</a>,
  202. <a href="r.support.html">r.support</a>
  203. </em>
  204. <h2>AUTHORS</h2>
  205. James Westervelt,<br>
  206. Michael Shapiro,<br>
  207. U.S. Army Construction Engineering Research Laboratory<br>
  208. Markus Metz
  209. <p><i>Last changed: $Date$</i>