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;-text
, CLI with graphical greetings -gtext
, or GUI (-gui
),<GISDBASE>/<LOCATION_NAME>/ <MAPSET>
), or obtained from environment variables (-
).$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.
Precedence of GRASS configuration:
$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"
;GRASS does not work very well with zsh, try export SHELL=/bin/bash
before calling grass
.
GRASS-related shell environment variables: Documentation
GISBASE
, GRASS library (e.g. /usr/lib/grass72
);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.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
;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:
/home/$USER/grassdata/
.Mapset PERMANENT/
is reserved for default cartography, with files PROJ_INFO
, PROJ_UNITS
, PROJ_EPSG
defining projection and DEFAULT_WIND
for default GRASS region.
Mapset structure by data type:
vector/
, vector maps (each may have coor
, dbin
, hist
command history, sidx
, topo
);sqlite/
, attribute tables managed by SQLite;VAR
, database driver and path;cats/
, cell/
, cellhd/
, cell_misc/
, colr/
, fcell/
, hist/
;
WIND
, GRASS region for raster data;grid3/
, 3D raster maps;Command history logs are available within each mapset:
Inside the hist
directory, you will find command logs for each raster layer.
Within the sub-directories vector
, you will find the command logs for each vector layer.
There is also .bash_history
file in the main mapset directory for all commands logs you used during a GRASS session.
GRASS topological vector model:
GRASS raster model:
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. 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.
GRASS Reference Manuals have a complete list of modules: List, Grouped, Graphical.
Module groups not documented: m
, miscellaneous; ps
, PostScript; test
, test;
g
General data management:
g.gisenv
, manage GRASS GIS environment variable.
g.proj
, projection information.
g.region
, computational region (also display region).
g.mapset
, manage current mapset.
g.list
, lists available GRASS database files of a specified type or pattern.
g.gui.dbmgr
, graphical attribute table manager.
g.extension
, manage add-on modules.
g.copy
, copy data files to the current mapset.
d
Graphic output:
d.vect
d.vect.thematic
, display thematic vector map.
d.mon
, start/stop/select graphics display monitors; height of display monitor is larger than screen height (37 px for GUI menu).
d.erase
, cover the active graphics frame with black or a custom color.
d.frame
, manage display frames on a graphics monitor.
d.info
, rectangle/dimensions of screen/frame, geographic coordinates and resolution of frame.
All color tables are stored in $GISBASE/etc/colors/
.
Color table type rules: category values (applicable to data with certain ranges) or percent values (applicable to any data), associated with standard GRASS color names or RGB values.
The "nv" parameter sets color for NULL values; the "default" parameter sets color undefined values (beyond the range of the color rules).
Example rule file with category values associated with standard GRASS color names:
1 red
2 green
3 blue
Example rule file with percent values associated with RGB values:
0% 255:0:0
50% 0:255:0
100% 0:0:255
db
Database integration: SQLite (default DB backend), PostgreSQL, MySQL, ODBC, DBF.
db.connect
, database connection.
db.select
, select value(s) from table.
v
v.in.ogr
, imports vector data in OGR supported formats.
v.proj
, re-projects a vector map from one location to the current location.
v.import
, imports vector data in OGR supported formats and re-projects on the fly.
v.in.osm
(add-on module), imports OpenStreetMap data.
v.transform
, affine transformation (shift, scale and rotate).
v.extract
, selects vector objects from an existing vector map and creates a new map.
v.select
, feature select operations (calling GEOS).
v.overlay
, feature overlay operations.
v.db
, attribute table management.
v.info
, vector map info (metadata, history, attribute columns).
v.colors
, manage color table of a vector map.
v.clean
, topological cleaning.
v.generalize
, simplification, smoothing.
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.to.db
, populates attribute values from vector features.
v.db.update
, updates an attribute column.
r
& 3D Raster r3
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.
Elevation (DEM) 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.
i
i.segment
, unsupervised image classification.
i.pca
, Principal Components Analysis on imagery group.
t
Temporal processing for spatio-temporal data sets (new in GRASS 7).
data types: t.rast
, t.rast3d
, t.vect
(time series aggregation).
animation.
OSGeo wiki page on 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
GRASS as an open source GIS backbone:
PyGRASS
, GRASS 7 API (scripting via GRASS modules, interface to C libraries); PyWPS
, python web processing service (OGC Web Services).rgrass7
); Using GRASS GIS within a R session (call rgrass7::initGRASS()
).