grass7.html 16 KB

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