rasterintro.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <!-- meta page description: Raster data processing in GRASS GIS -->
  2. <!-- meta page index: raster -->
  3. <h3>Raster maps in general</h3>
  4. A "raster map" is a data layer consisting of a gridded array of cells.
  5. It has a certain number of rows and columns, with a data point (or null
  6. value indicator) in each cell. These may exist as a 2D grid or as a 3D
  7. cube made up of many smaller cubes, i.e. a stack of 2D grids.
  8. <p>
  9. The geographic boundaries of the raster map are described by the north,
  10. south, east, and west fields. These values describe the lines which bound
  11. the map at its edges. These lines do NOT pass through the center of the
  12. grid cells at the edge of the map, but along the edge of the map itself.
  13. i.e. the geographic extent of the map is described by the outer bounds of
  14. all cells within the map.
  15. <p>
  16. As a general rule in GRASS GIS:
  17. <ol>
  18. <li> Raster output maps have their bounds and resolution equal to those
  19. of the current computational region.
  20. <li> Raster input maps are automatically cropped/padded and rescaled
  21. (using nearest-neighbour resampling) to match the current region.
  22. <li> Raster input maps are automatically masked if a raster map named
  23. MASK exists. The MASK is only applied when <i>reading</i> maps
  24. from the disk.
  25. </ol>
  26. There are a few exceptions to this:
  27. <tt>r.in.*</tt> programs read the data cell-for-cell, with no resampling. When
  28. reading non-georeferenced data, the imported map will usually have its
  29. lower-left corner at (0,0) in the location's coordinate system; the user
  30. needs to use <a href="r.region.html">r.region</a> to "place" the imported map.
  31. <p>
  32. Some programs which need to perform specific types of resampling (e.g.
  33. <a href="r.resamp.rst.html">r.resamp.rst</a>) read the input maps at
  34. their original resolution then do the resampling themselves.
  35. <p>
  36. <a href="r.proj.html">r.proj</a> has to deal with two regions (source
  37. and destination) simultaneously; both will have an impact upon the
  38. final result.
  39. <h3>Raster import and export</h3>
  40. The module <a href="r.in.gdal.html">r.in.gdal</a> offers a common
  41. interface for many different raster formats. Additionally, it also
  42. offers options such as on-the-fly location creation or extension of
  43. the default region to match the extent of the imported raster map.
  44. For special cases, other import modules are available. The full map
  45. is always imported.
  46. <p>
  47. For importing scanned maps, the user will need to create a
  48. x,y-location, scan the map in the desired resolution and save it into
  49. an appropriate raster format (e.g. tiff, jpeg, png, pbm) and then use
  50. <a href="r.in.gdal.html">r.in.gdal</a> to import it. Based on
  51. reference points the scanned map can be recified to obtain geocoded
  52. data.
  53. <p>
  54. Raster maps are exported with <a href="r.out.gdal.html">r.out.gdal</a>
  55. into common formats. Also <a href="r.out.bin.html">r.out.bin</a>,
  56. <a href="r.out.vtk.html">r.out.vtk</a>, <a href="r.out.ascii.html">r.out.ascii</a>
  57. and other export modules are available. They export the data according
  58. to the current region settings. If those differ from the original map,
  59. the map is resampled on the fly (nearest neighbor algorithm). In other
  60. words, the output will have as many rows and columns as the current region.
  61. To export maps with various grid spacings (e.g, 500x500 or 200x500), you
  62. can just change the region resolution with <a href="g.region.html">g.region</a>
  63. and then export the map. The resampling is done with nearest neighbor
  64. algorithm in this case. If you want some other form of resampling,
  65. first change the region, then explicitly resample the map with e.g.
  66. <a href="r.resamp.interp.html">r.resamp.interp</a> or
  67. <a href="r.resamp.stats.html">r.resamp.stats</a>, then export the
  68. resampled map.
  69. <p>
  70. GRASS GIS raster map exchange between different locations (same projection)
  71. can be done in a lossless way using the <a href="r.pack.html">r.pack</a>
  72. and <a href="r.unpack.html">r.unpack</a> modules.
  73. <h3>Metadata</h3>
  74. The <a href="r.info.html">r.info</a> module displays general information
  75. about a map such as region extent, data range, data type, creation history,
  76. and other metadata.
  77. Metadata such as map title, units, vertical datum etc. can be updated
  78. with <a href="r.support.html">r.support</a>. Timestamps are managed
  79. with <a href="r.timestamp.html">r.timestamp</a>. Region extent and
  80. resolution are mangaged with <a href="r.region.html">r.region</a>.
  81. <h3>Raster map operations</h3>
  82. <h4>Resampling methods and interpolation methods</h4>
  83. GRASS raster map processing is always performed in the current region
  84. settings (see <a href="g.region.html">g.region</a>), i.e. the current
  85. region extent and current raster resolution is used. If the resolution
  86. differs from that of the input raster map(s), on-the-fly resampling is
  87. performed (nearest neighbor resampling). If this is not desired, the
  88. input map(s) has/have to be resampled beforehand with one of the dedicated
  89. modules.
  90. <p>
  91. The built-in nearest-neighbour resampling of raster data calculates
  92. the centre of each region cell, and takes the value of the raster cell
  93. in which that point falls.
  94. <p>
  95. If the point falls exactly upon a grid line, the exact result will be
  96. determined by the direction of any rounding error. One consequence of
  97. this is that downsampling by a factor which is an even integer will
  98. always sample exactly on the boundary between cells, meaning that the
  99. result is ill-defined.
  100. <p>
  101. The following modules are available for reinterpolation of "filled"
  102. raster maps (continuous data) to a different resolution:
  103. <ul>
  104. <li><a href="r.resample.html">r.resample</a> uses the built-in resampling,
  105. so it should produce identical results as the on-the-fly resampling done
  106. via the raster import modules.</li>
  107. <li><a href="r.resamp.interp.html">r.resamp.interp</a> Resampling with
  108. nearest neighbor, bilinear, and bicubic method: <b>method=nearest</b> uses the
  109. same algorithm as <a href="r.resample.html">r.resample</a>, but not the same
  110. code, so it may not produce identical results in cases which are decided
  111. by the rounding of floating-point numbers.
  112. <br>
  113. For <a href="r.resamp.interp.html">r.resamp.interp</a> <b>method=bilinear</b>
  114. and <b>method=bicubic</b>, the raster values are treated as samples at each
  115. raster cell's centre, defining a piecewise-continuous surface. The resulting
  116. raster values are obtained by sampling the surface at each region cell's centre.
  117. As the algorithm only interpolates, and doesn't extrapolate, a margin of 0.5
  118. (for bilinear) or 1.5 (for bicubic) cells is lost from the extent of the original
  119. raster. Any samples taken within this margin will be null.</li>
  120. <li><a href="r.resamp.rst.html">r.resamp.rst</a> Regularized Spline with Tension
  121. (RST) interpolation 2D: Behaves similarly, i.e. it computes a surface assuming
  122. that the values are samples at each raster cell's centre, and samples the surface
  123. at each region cell's centre.</li>
  124. <li><a href="r.resamp.bspline.html">r.resamp.bspline</a> Bicubic or bilinear
  125. spline interpolation with Tykhonov regularization.</li>
  126. <li>For <a href="r.resamp.stats.html">r.resamp.stats</a> without <b>-w</b>, the value of
  127. each region cell is the chosen aggregate of the values from all of the raster
  128. cells whose centres fall within the bounds of the region cell.
  129. <br>
  130. With <b>-w</b>, the samples are weighted according to the proportion of the
  131. raster cell which falls within the bounds of the region cell, so the
  132. result is normally unaffected by rounding error (a minuscule difference
  133. in the position of the boundary results in the addition or subtraction of
  134. a sample weighted by a minuscule factor; also, The min and max aggregates
  135. can't use weights, so <b>-w</b> has no effect for those).</li>
  136. <li> <a href="r.fillnulls.html">r.fillnulls</a> for Regularized Spline with Tension (RST)
  137. interpolation 2D for hole filling (e.g., SRTM DEM)</li>
  138. </ul>
  139. <p>
  140. Furthermore, there are modules available for reinterpolation of "sparse"
  141. (scattered points or lines) maps:
  142. <ul>
  143. <li> Inverse distance weighted average (IDW) interpolation
  144. (<a href="r.surf.idw.html">r.surf.idw</a>)</li>
  145. <li> Interpolating from contour lines (<a href="r.contour.html">r.contour</a>)</li>
  146. <li> Various vector modules for interpolation</li>
  147. </ul>
  148. For Lidar and similar data, <a href="r.in.lidar.html">r.in.lidar</a> and <a href="r.in.xyz.html">r.in.xyz</a>
  149. support loading and binning of ungridded x,y,z ASCII data into a new raster map.
  150. The user may choose from a variety of statistical methods in creating the new raster map.
  151. <p>
  152. Otherwise, for interpolation of scattered data, use the <em>v.surf.*</em> set of
  153. modules.
  154. <h4>Raster MASKs</h4>
  155. If a raster map named "MASK" exists, most GRASS raster modules will operate
  156. only on data falling inside the masked area, and treat any data falling
  157. outside of the mask as if its value were NULL. The mask is only applied
  158. when <em>reading</em> an existing GRASS raster map, for example when used
  159. in a module as an input map.
  160. <p>
  161. The mask is read as an integer map. If MASK is actually a
  162. floating-point map, the values will be converted to integers using the
  163. map's quantisation rules (this defaults to round-to-nearest, but can
  164. be changed with r.quant).
  165. <p>
  166. (see <a href="r.mask.html">r.mask</a>)
  167. <h3>Raster map statistics</h3>
  168. A couple of commands are available to calculate local statistics
  169. (<a href="r.neighbors.html">r.neighbors</a>), and global statistics
  170. (<a href="r.statistics.html">r.statistics</a>, <a href="r.surf.area.html">r.surf.area</a>).
  171. Profiles and transects can be generated
  172. (<a href="d.profile.html">d.profile</a>, <a href="r.profile.html">r.profile</a>,
  173. <a href="r.transect.html">r.transect</a>) as well as histograms
  174. (<a href="d.histogram.html">d.histogram</a>) and polar diagrams
  175. (<a href="d.polar.html">d.polar</a>).
  176. Univariate statistics (<a href="r.univar.html">r.univar</a>) and
  177. reports are also available (<a href="r.report.html">r.report</a>,<a
  178. href="r.stats.html">r.stats</a>, <a href="r.volume.html">r.volume</a>).
  179. <h3>Raster map algebra and aggregation</h3>
  180. The <a href="r.mapcalc.html">r.mapcalc</a> command provides raster map
  181. algebra methods.
  182. The <a href="r.resamp.stats.html">r.resamp.stats</a> command resamples raster
  183. map layers using various aggregation methods, the <a href="r.statistics.html">r.statistics</a>
  184. command aggregates one map based on a second map.
  185. <a href="r.resamp.interp.html">r.resamp.interp</a> resamples raster map
  186. layers using interpolation.
  187. <h3>Regression analysis</h3>
  188. Both linear (<a href="r.regression.line.html">r.regression.line</a>) and
  189. multiple regression (<a href="r.regression.multi.html">r.regression.multi</a>)
  190. are supported.
  191. <h3>Hydrologic modeling toolbox</h3>
  192. Watershed modeling related modules are
  193. <a href="r.basins.fill.html">r.basins.fill</a>,
  194. <a href="r.water.outlet.html">r.water.outlet</a>,
  195. <a href="r.watershed.html">r.watershed</a>, and
  196. <a href="r.terraflow.html">r.terraflow</a>.
  197. Water flow related modules are
  198. <a href="r.carve.html">r.carve</a>,
  199. <a href="r.drain.html">r.drain</a>,
  200. <a href="r.fill.dir.html">r.fill.dir</a>,
  201. <a href="r.fillnulls.html">r.fillnulls</a>,
  202. <a href="r.flow.html">r.flow</a>, and
  203. <a href="r.topidx.html">r.topidx</a>.
  204. Flooding can be simulated with <a href="r.lake.html">r.lake</a>.
  205. Hydrologic simulation model are available as
  206. <a href="r.sim.sediment.html">r.sim.sediment</a>,
  207. <a href="r.sim.water.html">r.sim.water</a>, and
  208. <a href="r.topmodel.html">r.topmodel</a>.
  209. <h3>Raster format</h3>
  210. In GRASS GIS, raster data can be stored as 2D or 3D grids.
  211. <h4>2D raster maps</h4>
  212. 2D rasters support three data types (for technical details, please refer
  213. to the Wiki article
  214. <a href="https://grasswiki.osgeo.org/wiki/GRASS_raster_semantics">GRASS raster semantics</a>):
  215. <ul>
  216. <li>32bit signed integer (CELL),</li>
  217. <li>single-precision floating-point (FCELL), and</li>
  218. <li>double-precision floating-point (DCELL).
  219. </ul>
  220. In most GRASS GIS resources, 2D raster maps are usually called "raster" maps.
  221. <h4>3D raster maps</h4>
  222. The 3D raster map type is usually called "3D raster" but other names like
  223. "RASTER3D", "voxel", "volume", "GRID3D" or "3d cell" are yet common.
  224. 3D rasters support only single- and double-precision floating-point.
  225. 3D raster's single-precision data type is most often called "float",
  226. and the double-precision one "double".
  227. <h4>No-data management and data portability</h4>
  228. GRASS GIS distinguishes NULL and zero. When working with NULL data, it
  229. is important to know that operations on NULL cells lead to NULL cells.
  230. <p>
  231. The GRASS GIS raster format is architecture independent and portable between
  232. 32bit and 64bit machines.
  233. <h3>Raster compression</h3>
  234. <!-- keep in sync with raster/r.compress/r.compress.html -->
  235. All GRASS GIS raster map types are by default ZLIB compressed, i.e. using
  236. ZLIB's deflate algorithm. Through the environment variable
  237. <tt>GRASS_COMPRESSOR</tt> the compression method can be set to RLE, ZLIB,
  238. LZ4, or BZIP2.
  239. <p>
  240. Important: the NULL file compression must be explicitly turned on with
  241. <tt>export GRASS_COMPRESS_NULLS=1</tt> - such raster maps can then only
  242. be opened with GRASS GIS 7.2.0 or later. NULL file compression can be
  243. managed with <b>r.null -z</b>.
  244. <p>
  245. Integer (CELL type) raster maps can be compressed with RLE if
  246. the environment variable <tt>GRASS_INT_ZLIB</tt> exists and is set to value
  247. 0. However, this is not recommended.
  248. <p>
  249. Floating point (FCELL, DCELL) raster maps never use RLE compression;
  250. they are either compressed with ZLIB, LZ4, BZIP2 or are uncompressed.
  251. <dl>
  252. <dt><strong>RLE</strong></dt>
  253. <dd><b>DEPRECATED</b> Run-Length Encoding, poor compression ratio but
  254. fast. It is kept for backwards compatibility to read raster maps
  255. created with GRASS 6. It is only used for raster maps of type CELL.
  256. FCELL and DCELL maps are never and have never been compressed with RLE.
  257. </dd>
  258. <dt><strong>ZLIB</strong></dt>
  259. <dd>ZLIB's deflate is the default compression method for all raster
  260. maps. GRASS GIS 7 uses by default 1 as ZLIB compression level which is the
  261. best compromise between speed and compression ratio, also when
  262. compared to other available compression methods. Valid levels are in
  263. the range [1, 9] and can be set with the environment variable
  264. <tt>GRASS_ZLIB_LEVEL</tt>.</dd>
  265. <dt><strong>LZ4</strong></dt>
  266. <dd>LZ4 is a very fast compression method, about as fast as no
  267. compression. Decompression is also very fast. The compression ratio is
  268. generally higher than for RLE but worse than for ZLIB. LZ4 is
  269. recommended if disk space is not a limiting factor.</dd>
  270. <dt><strong>BZIP2</strong></dt>
  271. <dd>BZIP2 can provide compression ratios much higher than the other
  272. methods, but only for large raster maps (&gt; 10000 columns). For large
  273. raster maps, disk space consumption can be reduced by 30 - 50% when
  274. using BZIP2 instead of ZLIB's deflate. BZIP2 is the slowest compression
  275. and decompression method. However, if reading from / writing to a
  276. storage device is the limiting factor, BZIP2 compression can speed up
  277. raster map processing. Be aware that for smaller raster maps, BZIP2
  278. compression ratio can be worse than other compression methods.</dd>
  279. </dl>
  280. <p>
  281. In the internal cellhd file, the value for "compressed" is 1 for RLE, 2
  282. for ZLIB, 3 for LZ4, and 4 for BZIP2.
  283. <p>
  284. Obviously, decompression is controlled by the raster map's compression,
  285. not the environment variable.
  286. <h3>See also</h3>
  287. <ul>
  288. <li><a href="raster3dintro.html">Introduction into 3D raster data (voxel) processing</a></li>
  289. <li><a href="vectorintro.html">Introduction into vector data processing</a></li>
  290. <li><a href="imageryintro.html">Introduction into image processing</a></li>
  291. <li><a href="temporalintro.html">Introduction into temporal data processing</a></li>
  292. <li><a href="databaseintro.html">Database management</a></li>
  293. <li><a href="projectionintro.html">Projections and spatial transformations</a></li>
  294. </ul>