grass.html 17 KB

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