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