grass7.html 15 KB

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