grass.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <!-- meta page description: GRASS startup program -->
  2. <h2>SYNOPSIS</h2>
  3. <b>grass</b> [<b>-h</b> | <b>-help</b> | <b>--help</b>] [<b>-v</b> | <b>--version</b>] |
  4. [<b>-c</b> | <b>-c geofile</b> | <b>-c EPSG:code[:datum_trans]</b>] | <b>-e</b> | <b>-f</b> |
  5. [<b>--text</b> | <b>--gtext</b> | <b>--gui</b>] | <b>--config</b> |
  6. [<b>--tmp-location</b> | <b>--tmp-mapset</b>]
  7. [[[<b>&lt;GISDBASE&gt;/</b>]<b>&lt;LOCATION&gt;/</b>]
  8. <b>&lt;MAPSET&gt;</b>]
  9. [<b>--exec EXECUTABLE</b>]
  10. <h3>Flags:</h3>
  11. <dl>
  12. <dt><b>-h</b> | <b>-help</b> | <b>--help</b>
  13. <dd> Prints a brief usage message and exits
  14. <dt><b>-v</b> | <b>--version</b>
  15. <dd> Prints the version of GRASS and exits
  16. <dt><b>-c</b>
  17. <dd> Creates new GRASS unprojected location in specified GISDBASE
  18. <dt><b>-c geofile</b>
  19. <dd> Creates new GRASS projected location in specified GISDBASE based on georeferenced file
  20. <dt><b>-c EPSG:code</b>
  21. <dd> Creates new GRASS projected location in specified GISDBASE with given EPSG code
  22. <dt><b>-c EPSG:code:datum_trans</b>
  23. <dd> Creates new GRASS projected location in specified GISDBASE with given EPSG code and datum transform parameters
  24. <dt><b>-e</b>
  25. <dd> Exit after creation of location or mapset. Only with <b>-c</b> flag
  26. <dt><b>-f</b>
  27. <dd> Forces removal of .gislock if exists (use with care!). Only with --text flag
  28. <dt><b>--text</b>
  29. <dd> Indicates that Text-based User Interface should be used (skip welcome screen)
  30. <dt><b>--gtext</b>
  31. <dd> Indicates that Text-based User Interface should be used (show welcome screen)
  32. <dt><b>--gui</b>
  33. <dd> Indicates that Graphical User Interface
  34. (<em><a href="wxGUI.html">wxGUI</a></em>) should be used
  35. <dt><b>--config</b>
  36. <dd> Prints GRASS configuration parameters (options: arch, build, compiler, date, path, revision, svn_revision, version)
  37. <dt><b>--exec EXECUTABLE</b>
  38. <dd> Execute GRASS module or script. The provided executable will be executed in a GRASS GIS non-interactive session.
  39. <dt><b>--tmp-location</b>
  40. <dd> Run using a temporary location which is created based on the given
  41. coordinate reference system and deleted at the end of the execution
  42. (use with the --exec flag).
  43. The active mapset will be the PERMANENT mapset.
  44. <dt><b>--tmp-mapset</b>
  45. <dd> Run using a temporary mapset which is created in the specified
  46. location and deleted at the end of the execution
  47. (use with the --exec flag).
  48. </dl>
  49. <h3>Parameters:</h3>
  50. <dl>
  51. <dt><b>GISDBASE</b>
  52. <dd> Initial database directory which should be a fully qualified path
  53. (e.g., <tt>/usr/local/share/grassdata</tt>)
  54. <dt><b>LOCATION</b>
  55. <dd> Initial location directory which is a subdirectory of GISDBASE
  56. <dt><b>MAPSET</b>
  57. <dd> Initial mapset directory which is a subdirectory of LOCATION
  58. </dl>
  59. <i>Note</i>: These parameters must be specified in one of the
  60. following ways:
  61. <div class="code"><pre>
  62. MAPSET
  63. LOCATION/MAPSET
  64. GISDBASE/LOCATION/MAPSET
  65. </pre></div>
  66. <h2>DESCRIPTION</h2>
  67. <p>This command is used to launch GRASS GIS. It will parse the command
  68. line arguments and then initialize GRASS for the user. Since GRASS
  69. modules require a specific environment, this program must be called
  70. before any other GRASS module can run. The command line arguments are
  71. optional and provide the user with a method to indicate the desired
  72. user interface, as well as the desired mapset to work on.
  73. <p>The startup program will remember both the desired user interface
  74. and mapset. Thus, the next time the user runs GRASS, typing
  75. <em>grass</em> (without any options) will start GRASS with the
  76. previous settings for the user interface and mapset selected.
  77. <p>If you specify a graphical user interface (<b>--gui</b>)
  78. the <em>grass</em> program will try to verify that the system you
  79. specified exists and that you can access it successfully. If any of
  80. these checks fail then <em>grass</em> will automatically switch back
  81. to the text user interface mode.
  82. <h2>FLAGS</h2>
  83. The flag <b>--config option</b> prints GRASS GIS configuration and
  84. version parameters, with the options:
  85. <ul>
  86. <li><b>arch</b>: system architecture (e.g., <tt>x86_64-pc-linux-gnu</tt>)</li>
  87. <li><b>build</b>: (e.g., <tt>./configure --with-cxx --enable-largefile --with-proj [...]</tt>)</li>
  88. <li><b>compiler</b>: (e.g., <tt>gcc</tt>)</li>
  89. <li><b>date</b>: (e.g., <tt>Tue Mar 31 20:34:57 2020 +0200</tt>)</li>
  90. <li><b>path</b>: (e.g., <tt>/usr/lib64/grass</tt>)</li>
  91. <li><b>revision</b>: (e.g., <tt>745ee7ec9</tt>)</li>
  92. <li><b>svn_revision</b>: (e.g., <tt>062bffc8</tt>)</li>
  93. <li><b>version</b>: (e.g., <tt>8.0.0dev</tt>)</li>
  94. </ul>
  95. <h2>SAMPLE DATA</h2>
  96. The GRASS GIS project provides several free sample geospatial datasets
  97. as ready-to-use locations. They are available to download at
  98. <a href="https://grass.osgeo.org/download/sample-data/">https://grass.osgeo.org/download/sample-data/</a>.
  99. The "North Carolina data set" is a modern package of geospatial data from
  100. North Carolina (USA), and it includes raster, vector, LiDAR and satellite
  101. data. This is the most extensively used data set in the documentation and
  102. the examples throughout the user manual pages are based upon it.
  103. <h2>ENVIRONMENT VARIABLES</h2>
  104. A number of environment variables are available at GRASS startup to
  105. assist with automation and customization. Most users will not need to
  106. bother with these.
  107. <p>In addition to these shell environment variables GRASS maintains a
  108. number of GIS environment variables in the <tt>$HOME/.grass8/rc</tt>
  109. file. User changes to this file will be read during the next startup
  110. of GRASS. If this file becomes corrupted the user may edit it by hand
  111. or remove it to start afresh. See the list
  112. of <em><a href="variables.html">implemented GRASS variables</a></em>
  113. for more information. The rest of this help page will only consider
  114. shell environment variables.
  115. <p>Note that you will need to set these variables using the
  116. appropriate method required for the UNIX shell that you use (e.g. in a
  117. Bash shell you must <tt>export</tt> the variables for them to
  118. propagate).
  119. <h3>User Interface Environment Variable</h3>
  120. <p>The <em>grass</em> program will check for the existence of an
  121. environment variable called GRASS_GUI which indicates the type of user
  122. interface for GRASS to use. If this variable is not set
  123. when <em>grass</em> is run, then it will be created and then saved
  124. in the <tt>$HOME/.grass8/rc</tt> file for the next time GRASS is
  125. run. It can be set to <tt>text</tt>, <tt>gtext</tt> or <tt>gui</tt>.
  126. <p>There is an order of precedence in the way <em>grass</em>
  127. determines the user interface to use. The following is the hierarchy
  128. from highest precedence to lowest.
  129. <ol>
  130. <li>Command line argument
  131. <li>Environment variable GRASS_GUI
  132. <li>Value set in <tt>$HOME/.grass8/rc</tt> (GUI)
  133. <li>Default value - <tt>gui</tt>
  134. </ol>
  135. <h3>Python Environment Variables</h3>
  136. <p>If you choose to use <em><a href="wxGUI.html">wxGUI</a></em>
  137. interface, then the GRASS_PYTHON environment variable can be used to
  138. override your system default <tt>python</tt> command.
  139. <p>Suppose for example your system has Python 3.6 installed and you
  140. install a personal version of the Python 3.8 binaries
  141. under <tt>$HOME/bin</tt>. You can use the above variables to have
  142. GRASS use the Python 3.8 binaries instead.
  143. <div class="code"><pre>
  144. GRASS_PYTHON=python3.8
  145. </pre></div>
  146. <h3>Addon Path to Extra User Scripts</h3>
  147. This environment variable allows the user to extend the GRASS program
  148. search paths to include locally developed/installed GRASS modules or
  149. user scripts.
  150. <div class="code"><pre>
  151. GRASS_ADDON_PATH=/usr/mytools
  152. GRASS_ADDON_PATH=/usr/mytools:/usr/local/othertools
  153. </pre></div>
  154. <p>In this example above path(s) would be added to the standard GRASS path
  155. environment.
  156. <h3>Addon Base for Extra Local GRASS Addon Modules</h3>
  157. This environment variable allows the user to extend the GRASS program
  158. search paths to include locally installed
  159. (see <em><a href="g.extension.html">g.extension</a></em> for details)
  160. <a href="https://grasswiki.osgeo.org/wiki/GRASS_AddOns">GRASS Addon</a>
  161. modules which are not distributed with the standard GRASS release.
  162. <div class="code"><pre>
  163. GRASS_ADDON_BASE=/usr/grass-addons
  164. </pre></div>
  165. <p>In this example above path would be added to the standard GRASS
  166. path environment.
  167. <p>If not defined by user, this variable is set by GRASS startup program
  168. to <tt>$HOME/.grass8/addons</tt> on GNU/Linux
  169. and <tt>%APPDATA%\Roaming\GRASS8\addons</tt> on MS Windows.
  170. <h3>HTML Browser Variable</h3>
  171. The GRASS_HTML_BROWSER environment variable allows the user to set the
  172. HTML web browser to use for displaying help pages.
  173. <h3>Running non-interactive batch jobs</h3>
  174. If the GRASS_BATCH_JOB environment variable is set to the <i>full</i>
  175. path and filename of a shell script then GRASS will be launched in a
  176. non-interactive way and the script will be run. The script itself can
  177. be interactive if that is what the user requires. When it is finished
  178. GRASS will automatically exit using the exit-success code given by the
  179. script. The script file must have its executable bit set.
  180. <h2>EXAMPLES</h2>
  181. <p>The following are some examples of how you could start GRASS
  182. <dl>
  183. <dt><b>grass</b>
  184. <dd> Start GRASS using the default user interface. The user will be
  185. prompted to choose the appropriate location and mapset.
  186. <dt><b>grass --gui</b>
  187. <dd> Start GRASS using the graphical user interface. The user will be
  188. prompted to choose the appropriate location and mapset.
  189. <dt><b>grass --text</b>
  190. <dd> Start GRASS using the text-based user interface. Appropriate
  191. location and mapset must be set by environmental variables (see
  192. examples below) otherwise taken from the last GRASS session.</dd>
  193. <dt><b>grass --gtext</b>
  194. <dd> Start GRASS using the text-based user interface. The user will be
  195. prompted to choose the appropriate location and mapset.
  196. <dt><b>grass $HOME/grassdata/spearfish70/user1</b>
  197. <dd> Start GRASS using the default user interface and automatically
  198. launch into the given mapset, bypassing the mapset selection menu.
  199. <dt><b>grass --gui -</b>
  200. <dd> Start GRASS using the graphical user interface and try to
  201. obtain the location and mapset from environment variables.
  202. <dt><b>grass -c EPSG:4326 $HOME/grassdata/mylocation</b>
  203. <dd> Creates a new GRASS location with EPSG code 4326 (latitude-longitude, WGS84)
  204. in the specified GISDBASE
  205. <dt><b>grass -c EPSG:5514:3 $HOME/grassdata/mylocation</b>
  206. <dd> Creates a new GRASS location with EPSG code 5514 (S-JTSK / Krovak
  207. East North - SJTSK) with datum transformation parameters used in
  208. Czech Republic in the specified GISDBASE
  209. <dt><b>grass -c XY $HOME/grassdata/gnomonic --exec g.proj -c proj4='+proj=gnom +lat_0=90 +lon_0=-50'</b>
  210. <dd> Creates a new GRASS location from PROJ definition string
  211. (here: <a href="https://proj4.org/operations/projections/gnom.html">gnomonic</a>)
  212. in the specified GISDBASE
  213. <dt><b>grass -c myvector.shp $HOME/grassdata/mylocation</b>
  214. <dd> Creates a new GRASS location based on georeferenced Shapefile
  215. <dt><b>grass -c myraster.tif $HOME/grassdata/mylocation</b>
  216. <dd> Creates a new GRASS location based on georeferenced GeoTIFF file
  217. </dl>
  218. <h3>Batch jobs with the exec interface</h3>
  219. <!--
  220. Data created with:
  221. r.out.gdal input=elevation output=elevation.tiff
  222. r.out.gdal input=basin_50K output=basins.tiff
  223. Region issues ignored.
  224. -->
  225. Creating a new Location based on a geodata file's projection (<b>-c</b>)
  226. and exit (<b>-e</b>) immediately:
  227. <div class="code"><pre>
  228. grass -c elevation.tiff -e /path/to/grassdata/test1/
  229. </pre></div>
  230. Linking external raster data to PERMANENT Mapset:
  231. <div class="code"><pre>
  232. grass /path/to/grassdata/test1/PERMANENT/ --exec r.external input=basins.tiff output=basins
  233. grass /path/to/grassdata/test1/PERMANENT/ --exec r.external input=elevation.tiff output=elevation
  234. </pre></div>
  235. Get statistics for one raster map:
  236. <div class="code"><pre>
  237. grass /path/to/grassdata/test1/PERMANENT/ --exec r.univar map=elevation
  238. </pre></div>
  239. Compare the rasters visually:
  240. <div class="code"><pre>
  241. grass /path/to/grassdata/test1/PERMANENT/ --exec g.gui.mapswipe first=elevation second=basins
  242. </pre></div>
  243. <h4>Execution of shell and Python scripts instead of single commands</h4>
  244. A sequence of commands can be bundled in a script and executed using the
  245. exec interface.
  246. <p>
  247. <b>Shell script example:</b> the command to execute a shell script might be:
  248. <div class="code"><pre>
  249. grass /path/to/grassdata/test1/PERMANENT/ --exec sh test.sh
  250. </pre></div>
  251. A very simple bash script ("test.sh") may look like this:
  252. <div class="code"><pre>
  253. #!/bin/bash
  254. g.region -p
  255. g.list type=raster
  256. r.info elevation
  257. </pre></div>
  258. <p>
  259. <b>Python script example:</b> the command to execute a Python script might be:
  260. <div class="code"><pre>
  261. grass /path/to/grassdata/test1/PERMANENT/ --exec python test.py
  262. </pre></div>
  263. A very simple Python script ("test.py") may look like this:
  264. <div class="code"><pre>
  265. #!/usr/bin/env python3
  266. # import GRASS Python bindings (see also pygrass)
  267. import grass.script as gs
  268. import grass.script.setup as gsetup
  269. gs.message('Current GRASS GIS 8 environment:')
  270. print(gs.gisenv())
  271. gs.message('Available raster maps:')
  272. for raster in gs.list_strings(type='raster'):
  273. print(raster)
  274. gs.message('Available vector maps:')
  275. for vector in gs.list_strings(type='vector'):
  276. print(vector)
  277. </pre></div>
  278. <h4>Using temporary location</h4>
  279. Creating a new temporary location based on a georeferenced file's
  280. projection coordinate reference system (CRS) and simultaneously starting
  281. computation in a shell script:
  282. <div class="code"><pre>
  283. grass --tmp-location elevation.tiff --exec test.sh
  284. </pre></div>
  285. The same, but using an EPSG code and a Python script:
  286. <div class="code"><pre>
  287. grass --tmp-location EPSG:3358 --exec test.py
  288. </pre></div>
  289. Finally, for special cases, we can create an XY location without any CRS:
  290. <div class="code"><pre>
  291. grass --tmp-location XY --exec test.py
  292. </pre></div>
  293. Temporary location is automatically deleted after computation,
  294. so the script is expected to export, link or otherwise preserve the
  295. output data before ending.
  296. <p>
  297. A single command can be also executed, e.g. to examine properties of the
  298. temporary location:
  299. <div class="code"><pre>
  300. grass --tmp-location EPSG:3358 --exec g.proj -p
  301. </pre></div>
  302. A temporary XY location with single command is useful, e.g. to show
  303. help text of a module:
  304. <div class="code"><pre>
  305. grass --tmp-location XY --exec r.neighbors --help
  306. </pre></div>
  307. <h4>Using temporary mapset</h4>
  308. <p>
  309. A single command can be executed, e.g., to examine properties of a
  310. location (here using the NC SPM sample location):
  311. <div class="code"><pre>
  312. grass --tmp-mapset /path/to/grassdata/nc_spm_08/ --exec g.proj -p
  313. </pre></div>
  314. Computation in a Python script can be executed in the same way:
  315. <div class="code"><pre>
  316. grass --tmp-mapset /path/to/grassdata/nc_spm_08/ --exec processing.py
  317. </pre></div>
  318. Additional parameters are just passed to the script, so we can run the
  319. script with different sets of parameters (here 5, 8 and 3, 9) in
  320. different temporary mapsets which is good for parallel processing.
  321. <div class="code"><pre>
  322. grass --tmp-mapset /path/to/grassdata/nc_spm_08/ --exec processing.py 5 8
  323. grass --tmp-mapset /path/to/grassdata/nc_spm_08/ --exec processing.py 3 9
  324. </pre></div>
  325. The same applies to Bash scripts (and other scripts supported on you
  326. platform):
  327. <div class="code"><pre>
  328. grass --tmp-mapset /path/to/grassdata/nc_spm_08/ --exec processing.sh 5 8
  329. </pre></div>
  330. The temporary mapset is automatically deleted after computation,
  331. so the script is expected to export, link or otherwise preserve the
  332. output data before ending.
  333. <h4>Troubleshooting</h4>
  334. Importantly, to avoid an <tt>"[Errno 8] Exec format error"</tt> there must be a
  335. <a href="https://en.wikipedia.org/wiki/Shebang_%28Unix%29">shebang</a> line at the top of
  336. the script (like <tt>#!/bin/sh</tt>, <tt>#!/bin/bash</tt>, or <tt>#!/usr/bin/env python3</tt>)
  337. indicating which interpreter to be used for the script. The script file must
  338. have its executable bit set.
  339. <h2>CAVEAT</h2>
  340. If you start GRASS using the <em><a href="wxGUI.html">wxGUI</a></em>
  341. interface you must have a <tt>python</tt> command in your $PATH
  342. variable. That is, the command must be named
  343. <tt>python</tt> and not something like <tt>python3.6</tt>. Rarely some
  344. Python installations do not create a <tt>python</tt> command. In these
  345. cases you can override <tt>python</tt> by GRASS_PYTHON environmental
  346. variable.
  347. <p>Furthermore, if you have more than one version of Python installed,
  348. make sure that the version you want to use with GRASS is set by
  349. GRASS_PYTHON environmental variable.
  350. <h2>SEE ALSO</h2>
  351. List of <a href="variables.html">GRASS environment variables</a>
  352. <p>
  353. <a href="https://grass.osgeo.org">GRASS GIS Web site</a><br>
  354. <a href="https://grasswiki.osgeo.org/wiki/">GRASS GIS User Wiki</a><br>
  355. <a href="https://github.com/OSGeo/grass/issues">GRASS GIS Bug Tracker</a><br>
  356. <a href="https://grass.osgeo.org/programming8/">GRASS GIS 8 Programmer's Manual</a>
  357. <h2>AUTHORS (of this page)</h2>
  358. Justin Hickey<br>
  359. Markus Neteler<br>
  360. Hamish Bowman<br>
  361. Martin Landa, Czech Technical University in Prague, Czech Republic
  362. <!--
  363. <p>
  364. <i>Last changed: $Date$</i>
  365. -->