GRASS (Geographic Resources Analysis Support System) is an open source GIS with advanced analysis, modeling, and visualization capabilities. GRASS works as a shell environment or a wxWidgets GUI (using wxPython).

The GRASS main program such as grass (link) or grass72 (version specific Python script) can: -c, create location or mapset (and -e exit); --exec, run a GRASS module or a user shell (sh) /Python (python) script; or start a GRASS CLI -text, CLI with graphical greetings -gtext, or GUI (-gui), with mapset specified (`export GISBASE=/usr/lib/grass72 export PATH=$GISBASE/bin:$GISBASE/scripts:$PATH export LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH # path to GRASS settings file export GISRC=$HOME/.grass7/rc # use process ID (PID) as lock file number export GIS_LOCK=$$--Cleanup-internal-temporary-files%3A--

$GISBASE/etc/clean_temp
rm -rf /tmp/grass6-$USER-$GIS_LOCK
--If-you-change-the-prompt%3A--
PS1_BACKUP=$PS1
export PS1="GRASS> "
# ... do something with GRASS
export PS1=$PS1_BACKUP
---%23%23-API--GRASS-as-an-open-source-GIS-backbone%3A----%2A%2AC%2A%2A-libraries%3A-%5BGRASS-GIS-7-Programmer%27s-Manual%5D%28https%3A//grass.osgeo.org/programming7/%29---%2A%2APython%2A%2A%3A-%60PyGRASS%60%2C-GRASS-7-API-%28scripting-via-GRASS-modules%2C-interface-to-C-libraries%29%3B-%60PyWPS%60%2C-python-web-processing-service-%28OGC-Web-Services%29.---%2A%2AR%2A%2A%3A-Using-R-within-GRASS-GIS-session-%28Start-R-or-RStudio-in-a-GRASS-shell%2C-then-load-%60rgrass7%60%29%3B-Using-GRASS-GIS-within-a-R-session-%28call-%60rgrass7%3A%3AinitGRASS%28%29%60%29.---%2A%2AQGIS%2A%2A%3A-calls-GRASS-either-via-Toolbox-%28direct-connection%29-or-Processing-%28virtual-session%29.---%2A%2AParaView%2A%2A-%28visualization%29--------%F0%9F%8F%B7-%5B%5BCategory%3DGeographic-Information-System##-Configuration--Precedence-of-GRASS-configuration:--1.-Command-line-argument;-1.-Environment-variables-in-current-shell;-1.-GRASS-configuration-files-(under-%60%24HOME/.grass7/%60-for-GRASS-7):-------%60bashrc%60,-%60cshrc%60,-%60zshrc%60,-%60env.bat%60,-GRASS-related-Bash/Csh/Zsh/CMD-environment-variables;-------%60rc%60,-cache-of-GRASS-GIS-environment-(gisenv)-variables,-set-by-%60g.gisenv-set=" rel="nofollow">[/]/] ]`), or obtained from environment variables (`-`). Without any options, the main program will start GRASS with the last settings for the user interface and mapset, cached in `$HOME/.grass7/rc`. Development of GRASS started in 1987 by USA-CERL, a branch of the U.S. Army Corps of Engineers, with initial release in 1984 for Unix. In comparison, Esri's initial product ARC/INFO was released in 1982 as a command line GIS product on minicomputers, and later on UNIX (v5.0) and Windows (v7.1). CERL stopped supporting GRASS in 1995 (v4.1) and the current project leader is Markus Neteler. The current major version GRASS 7 was released in 2015. ## Configuration Precedence of GRASS configuration: 1. Command line argument; 1. Environment variables in current shell; 1. GRASS configuration files (under `$HOME/.grass7/` for GRASS 7): - `bashrc`, `cshrc`, `zshrc`, `env.bat`, GRASS-related Bash/Csh/Zsh/CMD environment variables; - `rc`, cache of GRASS GIS environment (gisenv) variables, set by `g.gisenv set="VARIABLE=VALUE"`; 1. Default value; GRASS does not work very well with zsh, try `export SHELL=/bin/bash` before calling `grass`. GRASS-related **shell environment variables**: [Documentation](https://grass.osgeo.org/grass73/manuals/variables.html) - `GISBASE`, GRASS library; - `GISRC`, file path for GRASS session gisenv values, `$HOME/.grass7/rc` for GRASS 7; - `GRASS_GUI`, type of GRASS user interface; - `GRASS_PYTHON`, default python in GRASS GUI overiding shell `python`; - `GRASS_HTML_BROWSER`, HTML browser for help pages; - `GRASS_ADDON_BASE`, `GRASS_ADDON_PATH`, extra search paths for repository/local add-on modules; - `LOCATION`, full path of default GRASS mapset; - `GISDBASE`, `LOCATION_NAME`, `MAPSET`, default GRASS database/location/mapset; - `GRASS_RENDER_IMMEDIATE`, `GRASS_RENDER_WIDTH`, `GRASS_RENDER_HEIGHT`, `GRASS_RENDER_FRAME`, `GRASS_RENDER_LINE_WIDTH`, `GRASS_RENDER_TEXT_SIZE`, `GRASS_RENDER_FILE`, graphical output; - `GRASS_MESSAGE_FORMAT`, percentage output and message formatting style; - `GRASS_SH`, bourne shell interpreter used to run shell scripts; - `GRASS_BATCH_JOB`, shell script to execute at GRASS launch. In GRASS shell configuration file, you may need to add GRASS modules to PATH: `export PATH=$GISBASE/bin:$GISBASE/scripts:$PATH` (bash). Also export shell environment variable `GISRC`. You may want to change the prompt to distinguish GRASS-launched shell from the launching shell: `export PS1="GRASS> "` (bash). GRASS GIS environment (**gisenv**) variables: - `DEBUG`, debug message level; - `GIS_LOCK`, lock ID to prevent concurrent GRASS use, default to the process id of the start-up shell script; - `OVERWRITE`, allow map overwrite; - `GUI`; - `LOCATION`, `GISDBASE`, `LOCATION_NAME`, `MAPSET`; ## GRASS Database Unlike QGIS, GRASS manages geospatial data under a dedicated directory called a GRASS database. Data in external formats such as Shapefile and GeoTIFF are best maintained in a separate location. GRASS database hierarchy: 1. GRASS **database**: the root directory of GRASS data, often `/home/$USER/grassdata/`. 1. **Location**: a projection. 1. **Mapset**: a thematic group of spatial objects and attribute data; `PERMANENT/` mapset is reserved for default cartography. Mapset structure by data type: 1. vector - `vector/`, vector maps (each may have `coor`, `dbin`, `hist`, `sidx`, `topo`); - `sqlite/`, attribute tables managed by SQLite; 1. raster: `cats/`, `cell/`, `cellhd/`, `cell_misc/`, `colr/`, `fcell/`, `hist/`; - `WIND`, GRASS region for raster data; 1. 3D raster: `grid3/`, 3D raster maps; Figure: GRASS Directory Structure.
Source GRASS topological vector model: - **Topological object**: for example, areas are defined by boundaries and identified (labelled) by centroid. - **Layer**: a group of spatial objects with one **attribute table**. - **Category**: a unique ID for each spatial object within a layer. - **Attribute**: a feature associated with a spatial object identified by its category. GRASS raster model: - Raster region: defined by the extent and resolution of a raster map. - Computational region: defined by region extent and raster resolution; overrides raster region. - Display region: extent of the current map display, independent of computational region and raster region. ## Modules GRASS is set up as a modified shell environment where operations are bundled **modules**: either as standalone executables written in C, or as Python scripts calling them. Near 400 core modules come with the GRASS distribution; user-created add-on modules are [available on its website](https://grass.osgeo.org/download/addons/). Most modules read maps from the GRASS database and write new maps back; other types of outputs are either stored in temporary files or put to the standard streams which can be chained with other programs. Figure: GRASS 7 Architecture. Source GRASS Reference Manuals have a complete list of modules: [List](https://grass.osgeo.org/grass72/manuals/full_index.html), [Grouped](https://grass.osgeo.org/grass72/manuals/index.html), [Graphical](https://grass.osgeo.org/grass72/manuals/graphical_index.html). Module groups not documented: `m`, miscellaneous; `ps`, PostScript; `test`, test; ### General `g` General data management: - `g.gisenv`, manage GRASS GIS environment variable. - `g.proj`, projection information. - `g.region`, computational region. - `g.mapset`, mapset search path. - `g.copy`, copy data files to the current mapset. - `g.extension`, manage add-on modules. ### Vector `v` Topological vector digitizer: - `v.in.ogr`, imports vector data in OGR supported formats. - `v.in.osm` (add-on module), imports OpenStreetMap data. - `v.extract`, selects vector objects from an existing vector map and creates a new map. - `v.proj`, re-projection. - `v.clean`, topological cleaning. - `v.generalize`, simplification, smoothing. - `v.select`, feature select operations (calling GEOS). - `v.overlay`, feature overlay operations. - `v.net`, network analysis (shortest path, subnet allocation, cost isoline, travelling salesman). - `v.rast.stats`, univariate statistics per vector feature based on a raster map. - `v.lrs`, Linear referencing (LRS). - `v.db`, attribute table management. - `v.colors`, color table of a vector map. - `v.transform`, affine transformation (shift, scale and rotate). ### Raster `r` & 3D Raster `r3` Raster processing: - `r.in.gdal`, import raster data of common formats (GeoTIFF). - `r.univar`, univariate analysis. - `r.mapcalc`, map calculation. - `r.surf`, generate surface map. - `r.grow`, grow raster map. - `r.tile`, split a raster map into tiles. - DEM (elevation) analysis: - cost surface: `r.cost`, `r.walk`. - hydrological modelling: `r.watershed`, `r.terraflow`, `r.flow`, `r.drain`, `r.fill`. - sight: `r.viewshed`. - Energy: `r.sun`, `r.sunmask`. Voxel (3D raster) processing: - `r3.stats`, voxel statistics. ### Imagery `i` - `i.segment`, unsupervised image classification. - `i.pca`, Principal Components Analysis on imagery group. ### Temporal `t` With temporal processing, GRASS GIS can handle spatio-temporal data sets. Spatial-temporal data processing: (new in GRASS 7) - data types: `t.rast`, `t.rast3d`, `t.vect` (time series aggregation). - animation ### Database `db` Database integration: SQLite (default DB backend), PostgreSQL, MySQL, ODBC, DBF. - `db.connect`, database connection. - `db.select`, select value(s) from table. ### Display `d` Graphic output: - `d.vect.thematic`, displays thematic vector map. ## Shell Scripting [OSGeo wiki page on GRASS and Shell](https://grasswiki.osgeo.org/wiki/GRASS_and_Shell) You may include the following in shell scripts to set up a GRASS environment:

export GISBASE=/usr/lib/grass72
export PATH=$GISBASE/bin:$GISBASE/scripts:$PATH
export LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH
# path to GRASS settings file
export GISRC=$HOME/.grass7/rc
# use process ID (PID) as lock file number
export GIS_LOCK=$$
Cleanup internal temporary files:
$GISBASE/etc/clean_temp
rm -rf /tmp/grass6-$USER-$GIS_LOCK
If you change the prompt:
PS1_BACKUP=$PS1
export PS1="GRASS> "
# ... do something with GRASS
export PS1=$PS1_BACKUP
## API GRASS as an open source GIS backbone: - **C** libraries: [GRASS GIS 7 Programmer's Manual](https://grass.osgeo.org/programming7/) - **Python**: `PyGRASS`, GRASS 7 API (scripting via GRASS modules, interface to C libraries); `PyWPS`, python web processing service (OGC Web Services). - **R**: Using R within GRASS GIS session (Start R or RStudio in a GRASS shell, then load `rgrass7`); Using GRASS GIS within a R session (call `rgrass7::initGRASS()`). - **QGIS**: calls GRASS either via Toolbox (direct connection) or Processing (virtual session). - **ParaView** (visualization) --- 🏷 [[Category=Geographic Information System