g.region.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <h2>DESCRIPTION</h2>
  2. The <em>g.region</em> module allows the user to manage the
  3. settings of the current geographic region. These regional
  4. boundaries can be set by the user directly and/or set from
  5. a region definition file (stored under the
  6. <kbd>windows</kbd> directory in the user's current
  7. mapset). The user can create, modify, and store as many
  8. geographic region definitions as desired for any given
  9. mapset. However, only one of these geographic region
  10. definitions will be current at any given moment, for a
  11. specified mapset; i.e., GRASS programs that respect the
  12. geographic region settings will use the current geographic
  13. region settings.
  14. <h2>DEFINITIONS</h2>
  15. <dl>
  16. <dt><b>Region:</b>
  17. <dd>In GRASS, a <em>region</em> refers to a geographic area
  18. with some defined boundaries, based on a specific map
  19. coordinate system and map projection. Each region also has
  20. associated with it the specific east-west and north-south
  21. resolutions of its smallest units (rectangular units called
  22. "cells").
  23. <p>
  24. The region's boundaries are given as the northernmost,
  25. southernmost, easternmost, and westernmost points that
  26. define its extent (cell edges). The north and south boundaries
  27. are commonly called <em>northings</em>, while the east and west
  28. boundaries are called <em>eastings</em>.
  29. <p>
  30. The region's cell resolution defines the size of the
  31. smallest piece of data recognized (imported, analyzed,
  32. displayed, stored, etc.) by GRASS modules affected by the
  33. current region settings. The north-south and east-west cell
  34. resolutions need not be the same, thus allowing non-square
  35. data cells to exist.
  36. <p>Typically all raster and display modules are affected by the current
  37. region settings, but not vector modules.
  38. Some special modules diverge from this rule, for example raster import
  39. modules and <em>v.in.region</em>.
  40. <dt><b>Default Region:</b>
  41. <dd>Each GRASS LOCATION has a fixed
  42. geographic region, called the default geographic region
  43. (stored in the region file <kbd>DEFAULT_WIND</kbd> under
  44. the special mapset <kbd>PERMANENT</kbd>), that defines the
  45. extent of the data base. While this provides a starting
  46. point for defining new geographic regions, user-defined
  47. geographic regions need not fall within this geographic
  48. region. The current region can be reset to the default region
  49. with the <b>-d</b> flag. The default region is initially set
  50. when the location is first created and can be reset using the
  51. <b>-s</b> flag.
  52. <dt><b>Current Region:</b>
  53. <dd>Each mapset has a current geographic region. This
  54. region defines the geographic area in which all GRASS
  55. displays and raster analyses will be done. Raster data will be
  56. resampled, if necessary, to meet the cell resolutions of
  57. the current geographic region setting.
  58. <dt><b>Saved Regions:</b>
  59. <dd>Each GRASS MAPSET may contain any number of
  60. pre-defined, and named, geographic regions. These region
  61. definitions are stored in the user's current mapset
  62. location under the <kbd>windows</kbd> directory (also
  63. referred to as the user's saved region definitions).
  64. Any of these pre-defined geographic regions
  65. may be selected, by name, to become the current geographic
  66. region. Users may also access saved region definitions
  67. stored under other mapsets in the current location, if
  68. these mapsets are included in the user's mapset search
  69. path or the '@' operator is used (<tt>region_name@mapset</tt>).
  70. </dl>
  71. <h2>NOTES</h2>
  72. After all updates have been applied, the current region's
  73. southern and western boundaries are (silently) adjusted so
  74. that the north/south distance is a multiple of the
  75. north/south resolution and that the east/west distance is a
  76. multiple of the east/west resolution.
  77. <p>With the <b>-a</b> flag all four boundaries are adjusted
  78. to be even multiples of the resolution, aligning the region to the
  79. resolution supplied by the user. The default is to
  80. align the region resolution to match the region boundaries.
  81. <p>The <b>-m</b> flag will report the region resolution in meters. The
  82. resolution is calculated by averaging the resolution at the region
  83. boundaries. This resolution is calculated by dividing the geodesic
  84. distance in meters at the boundary by the number of rows or columns.
  85. For example the east / west resolution (ewres) is determined from an
  86. average of the geodesic distances at the North and South boundaries
  87. divided by the number of columns.
  88. <!-- add'l info. include?
  89. Print the region resolution in meters (from geodesic). With no other
  90. flags the default output format is shell stype (-g). The region resolution
  91. represents the center of the map. The resolutions are calculated at the four
  92. outside edges, then the two NS edges are averaged and the two EW edges are
  93. averaged, the results finally printed.
  94. -->
  95. <p>The <b>-p</b> (or <b>-g</b>) option is recognized
  96. last. This means that all changes are applied to the
  97. region settings before printing occurs.
  98. <p>The <b>-g</b> flag prints the current region settings in shell script style.
  99. This format can be given back to <em>g.region</em> on its command line.
  100. This may also be used to save region settings as shell environment variables
  101. with the UNIX eval command, "<tt>eval `g.region -g`</tt>".
  102. <p>With <b>-u</b> flag current region is not updated even if one or more
  103. options for changing region is used (<b>res=</b>, <b>raster=</b>, etc).
  104. This can be used for example to print modified region values for further use
  105. without actually modifying the current region.
  106. Similarly, <b>-o</b> flag forces to update current region file even when e.g., only
  107. printing was specified. Flag <b>-o</b> was added in GRASS GIS version 8 to simulate
  108. <em>g.region</em> behavior in prior versions when current region file was
  109. always updated unless <b>-u</b> was specified.
  110. <h3>Additional parameter information:</h3>
  111. <dl>
  112. <dt><b>zoom=</b><em>name</em>
  113. <dd>Shrink current region settings to the smallest region
  114. encompassing all non-NULL data in the named raster map
  115. layer that fall inside the user's current region. In this
  116. way you can tightly zoom in on isolated clumps within a
  117. bigger map.
  118. <p>If the user also includes the <b>raster=</b><em>name</em>
  119. option on the command line, <b>zoom=</b><em>name</em> will
  120. set the current region settings to the smallest region
  121. encompassing all non-NULL data in the named <b>zoom</b> map
  122. that fall inside the region stated in the cell header for
  123. the named <b>raster</b> map.
  124. <dt><b>align=</b><em>name</em>
  125. <dd>Set the current resolution equal to that of the named
  126. raster map, and align the current region to a row and
  127. column edge in the named map. Alignment only moves the
  128. existing region edges outward to the edges of the next
  129. nearest cell in the named raster map - not to the named
  130. map's edges. To perform the latter function, use the
  131. <b>raster=</b><em>name</em> option.
  132. </dl>
  133. <h2>EXAMPLES</h2>
  134. <h3>Printing extent and raster resolution in 2D and 3D</h3>
  135. <dl>
  136. <dt><span class="code"><tt>
  137. g.region -p
  138. </tt></span>
  139. <dd> This will print the current region in the format:
  140. <div class="code"><pre>
  141. projection: 1 (UTM)
  142. zone: 13
  143. datum: nad27
  144. ellipsoid: clark66
  145. north: 4928000
  146. south: 4914000
  147. west: 590000
  148. east: 609000
  149. nsres: 20
  150. ewres: 20
  151. rows: 700
  152. cols: 950
  153. </pre></div>
  154. <p>
  155. <dt><span class="code"><tt>
  156. g.region -p3
  157. </tt></span>
  158. <dd> This will print the current region and the 3D region (used for voxels)
  159. in the format:
  160. <div class="code"><pre>
  161. projection: 1 (UTM)
  162. zone: 13
  163. datum: nad27
  164. ellipsoid: clark66
  165. north: 4928000
  166. south: 4914000
  167. west: 590000
  168. east: 609000
  169. top: 1.00000000
  170. bottom: 0.00000000
  171. nsres: 20
  172. nsres3: 20
  173. ewres: 20
  174. ewres3: 20
  175. tbres: 1
  176. rows: 700
  177. rows3: 700
  178. cols: 950
  179. cols3: 950
  180. depths: 1
  181. </pre></div>
  182. <p>
  183. <dt><span class="code"><tt>
  184. g.region -g
  185. </tt></span>
  186. <dd> The <b>-g</b> option prints the region in the
  187. following script style (key=value) format:
  188. <div class="code"><pre>
  189. n=4928000
  190. s=4914000
  191. w=590000
  192. e=609000
  193. nsres=20
  194. ewres=20
  195. rows=700
  196. cols=950
  197. </pre></div>
  198. <p>
  199. <dt><span class="code"><tt>
  200. g.region -bg
  201. </tt></span>
  202. <dd> The <b>-bg</b> option prints the region in the
  203. following script style (key=value) format plus the
  204. boundary box in latitude-longitude/WGS84:
  205. <div class="code"><pre>
  206. n=4928000
  207. s=4914000
  208. w=590000
  209. e=609000
  210. nsres=20
  211. ewres=20
  212. rows=700
  213. cols=950
  214. LL_W=-103.87080682
  215. LL_E=-103.62942884
  216. LL_N=44.50164277
  217. LL_S=44.37302019
  218. </pre></div>
  219. <p>
  220. <dt><span class="code"><tt>
  221. g.region -l
  222. </tt></span>
  223. <dd> The <b>-l</b> option prints the region in the
  224. following format:
  225. <div class="code"><pre>
  226. long: -103.86789484 lat: 44.50165890 (north/west corner)
  227. long: -103.62895703 lat: 44.49904013 (north/east corner)
  228. long: -103.63190061 lat: 44.37303558 (south/east corner)
  229. long: -103.87032572 lat: 44.37564292 (south/west corner)
  230. rows: 700
  231. cols: 950
  232. Center longitude: 103:44:59.170374W [-103.74977]
  233. Center latitude: 44:26:14.439781N [44.43734]
  234. </pre></div>
  235. <p>
  236. <dt><span class="code"><tt>
  237. g.region -pm
  238. </tt></span>
  239. <dd> This will print the current region in the format
  240. (latitude-longitude location):
  241. <div class="code"><pre>
  242. projection: 3 (Latitude-Longitude)
  243. zone: 0
  244. ellipsoid: wgs84
  245. north: 90N
  246. south: 40N
  247. west: 20W
  248. east: 20E
  249. nsres: 928.73944902
  250. ewres: 352.74269109
  251. rows: 6000
  252. cols: 4800
  253. </pre></div>
  254. Note that the resolution is here reported in meters, not decimal degrees.
  255. </dl>
  256. <h3>Changing extent and raster resolution using values</h3>
  257. <dl>
  258. <dt><span class="code"><tt>
  259. g.region n=7360100 e=699000
  260. </tt></span>
  261. <dd> will reset the northing and easting for the current
  262. region, but leave the south edge, west edge, and the region
  263. cell resolutions unchanged.
  264. <p>
  265. <dt><span class="code"><tt>
  266. g.region n=51:36:05N e=10:10:05E s=51:29:55N w=9:59:55E res=0:00:01
  267. </tt></span>
  268. <dd> will reset the northing, easting, southing, westing and resolution
  269. for the current region, here in DMS latitude-longitude style
  270. (decimal degrees and degrees with decimal minutes can also be used).
  271. <p>
  272. <dt><span class="code"><tt>
  273. g.region -dp s=698000
  274. </tt></span>
  275. <dd> will set the current region from the default region
  276. for the GRASS data base location, reset the south edge to
  277. 698000, and then print the result.
  278. <p>
  279. <dt><span class="code"><tt>
  280. g.region n=n+1000 w=w-500
  281. </tt></span>
  282. <dd> The n=<em>value</em> may also be specified as a
  283. function of its current value: n=n+<em>value</em>
  284. increases the current northing, while n=n-<em>value</em>
  285. decreases it. This is also true for s=<em>value</em>,
  286. e=<em>value</em>, and w=<em>value</em>. In this example
  287. the current region's northern boundary is extended by 1000
  288. units and the current region's western boundary is
  289. decreased by 500 units.
  290. <p>
  291. <dt><span class="code"><tt>
  292. g.region n=s+1000 e=w+1000
  293. </tt></span>
  294. <dd> This form allows the user to set the region boundary
  295. values relative to one another. Here, the northern
  296. boundary coordinate is set equal to 1000 units larger than
  297. the southern boundary's coordinate value, and the eastern
  298. boundary's coordinate value is set equal to 1000 units
  299. larger than the western boundary's coordinate value. The
  300. corresponding forms s=n-<em>value</em> and
  301. <p>
  302. w=e-<em>value</em> may be used to set the values of the
  303. region's southern and western boundaries, relative to the
  304. northern and eastern boundary values.
  305. </dl>
  306. <h3>Changing extent and raster resolution using maps</h3>
  307. <dl>
  308. <dt><span class="code"><tt>
  309. g.region raster=soils
  310. </tt></span>
  311. <dd> This form will make the current region settings
  312. exactly the same as those given in the cell header file for
  313. the raster map layer <em>soils</em>.
  314. <p>
  315. <dt><span class="code"><tt>
  316. g.region raster=soils zoom=soils
  317. </tt></span>
  318. <dd> This form will first look up the cell header file for
  319. the raster map layer <em>soils</em>, use this as the
  320. current region setting, and then shrink the region down to
  321. the smallest region which still encompasses all non-NULL
  322. data in the map layer <em>soils</em>. Note that if the
  323. parameter <em>raster=soils</em> were not specified, the
  324. zoom would shrink to encompass all non-NULL data values in
  325. the soils map that were located within the <i>current region</i>
  326. settings.
  327. <p>
  328. <dt><span class="code"><tt>
  329. g.region -up raster=soils
  330. </tt></span>
  331. <dd> The <b>-u</b> option suppresses the re-setting of the
  332. current region definition. This can be useful when it is
  333. desired to only extract region information. In this case,
  334. the cell header file for the soils map layer is printed
  335. without changing the current region settings.
  336. <p>
  337. <dt><span class="code"><tt>
  338. g.region -up zoom=soils save=soils
  339. </tt></span>
  340. <dd> This will zoom into the smallest region which
  341. encompasses all non-NULL soils data values, and save the
  342. new region settings in a file to be called <em>soils</em>
  343. and stored under the <kbd>windows</kbd> directory in the
  344. user's current mapset. The current region settings are not
  345. changed.
  346. </dl>
  347. <h3>Changing extent and raster resolution in 3D</h3>
  348. <dl>
  349. <dt><span class="code"><tt>
  350. g.region b=0 t=3000 tbres=200 res3=100
  351. g.region -p3
  352. </tt></span>
  353. <dd> This will define the 3D region for voxel computations.
  354. In this example a volume with bottom (0m) to top (3000m)
  355. at horizontal resolution (100m) and vertical resolution (200m)
  356. is defined.
  357. </dl>
  358. <h3>Using g.region in a shell in combination with OGR</h3>
  359. <!-- why not 'v.in.ogr spatial=' ?? -->
  360. Extracting a spatial subset of the external vector map
  361. <tt>soils.shp</tt> into new external vector map <tt>soils_cut.shp</tt>
  362. using the OGR <em>ogr2ogr</em> tool:<br>
  363. <div class="code"><pre>
  364. eval `g.region -g`
  365. ogr2ogr -spat $w $s $e $n soils_cut.shp soils.shp
  366. </pre></div>
  367. This requires that the location/SHAPE file projection match.
  368. <h3>Using g.region in a shell in combination with GDAL</h3>
  369. Extracting a spatial subset of the external raster map
  370. <tt>p016r035_7t20020524_z17_nn30.tif</tt> into new external raster
  371. map <tt>p016r035_7t20020524_nc_spm_wake_nn30.tif</tt> using the GDAL
  372. <em>gdalwarp</em> tool:<br>
  373. <div class="code"><pre>
  374. eval `g.region -g`
  375. gdalwarp -t_srs "`g.proj -wf`" -te $w $s $e $n \
  376. p016r035_7t20020524_z17_nn30.tif \
  377. p016r035_7t20020524_nc_spm_wake_nn30.tif
  378. </pre></div>
  379. Here the input raster map does not have to match the location
  380. projection since it is reprojected on the fly.
  381. <h2>SEE ALSO</h2>
  382. <em>
  383. <a href="g.access.html">g.access</a>,
  384. <a href="g.mapsets.html">g.mapsets</a>,
  385. <a href="g.proj.html">g.proj</a>
  386. <br>
  387. Environment variables: <a href="variables.html#internal">GRASS_REGION and WIND_OVERRIDE</a>
  388. </em>
  389. <h2>AUTHOR</h2>
  390. Michael Shapiro,
  391. U.S.Army Construction Engineering
  392. Research Laboratory