Warning: Declaration of syntax_plugin_alertbox::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /homepages/38/d684553722/htdocs/clickandbuilds/spatialecology_wiki/lib/plugins/alertbox/syntax.php on line 22
Warning: Declaration of syntax_plugin_alertbox::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /homepages/38/d684553722/htdocs/clickandbuilds/spatialecology_wiki/lib/plugins/alertbox/syntax.php on line 45
Warning: Declaration of syntax_plugin_bliki::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /homepages/38/d684553722/htdocs/clickandbuilds/spatialecology_wiki/lib/plugins/bliki/syntax.php on line 75
Warning: Declaration of syntax_plugin_bliki::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /homepages/38/d684553722/htdocs/clickandbuilds/spatialecology_wiki/lib/plugins/bliki/syntax.php on line 379 wiki:basicgrass7 
The object of this page is to start using Grass and to get familiar with some general GIS operations.
We are going to use a command line approach. This is to enable carrying out stand-alone processes in the future, and understand step by step each function and the options per function which are available.
Let´s start using grass.
Every Grass project has a predefined data structure
GISDBASE - Grass data are stored in a directory referred to as a DATABASE “GISDBASE”. This directory has to be created with mkdir or a file manager, before starting to work with GRASS. Within this DATABASE, the projects are organized by project areas stored in subdirectories called LOCATIONs.
LOCATION - A Location is defined by its coordinate system, map projection and geographical boundaries. The subdirectories and files defining a LOCATION are created automatically when GRASS is started for the first time with a new LOCATION.
MAPSET - Locations can have many MAPSETs. Each MAPSET is a LOCATION's subdirectory. A new MAPSET can be added at GRASS startup.
A common problem of basic users is not really using grass but starting a grass section. The main reason is due to the grass data structure and the way a grass section has to be set up before starting!
To remove a MAPSET, remove it's directory using your file manager or by
rm -rf /path/./mapsettodelete
The wxGUI graphical user interface provides options to rename/remove LOCATIONs and MAPSETs.
There are several ways to use and open Grass. The simplest way is to open a terminal and type:
A second option is to use the Python GUI by typing in the terminal:
the Graphical User Interface GUI will ask you to define the GISDBASE, LOCATION and MAPSET to use. If you want you can
select the Location wizard to create a new location with newest projection parameters or the Create mapset button to create a new mapset inside a pre-existing location.
To enter grass in command line:
grass74 -text ~/ost4sem/grassdb/europe/PERMANENT
Using the above command line we have already entered into the Grass environment with the GISDBASE, LOCATION and MAPSET defined by the ~/ost4sem/grassdb/europe/PCEM path
Once you are running Grass through the bash shell terminal you can always start the graphical user interface with:
g.gui wxpython &
GRASS COMMAND STRUCTURE
class type of command
d.rast: views raster map
d.vect: views vector map
db.select: selects value(s) from table
general file operations
g.rename: renames map
i.smap: image classifier
map creation format
ps.map: map creation in Postscript
raster data processing
r.buffer: buffer around raster features
r.mapcalc: map algebra
raster voxel data processing
r3.mapcalc: volume map algebra
vector data processing
v.overlay: vector map intersections
For detailed instructions on grass command syntax and use, go to the GRASSonline manual or type man and function name. As an example
Grass working environment
The g.gisenv command informs you of your current grass environment settings
If you started grass correctly you should visualize the following lines on your terminal
Running grass through the bash shell terminal allows you to use all command line functionality of both grass and shell. As an example you can type
and visualize all files available in your shell current working directory. This means that all your output files produced by bash command lines functionality will be saved in the current working directory (if not specified differently). Many non-geographical grass output features such as text file reports or images will be saved as well in the current working directory. The GRASS 7.4.0 (europe):~ > inform you are currently working in the home folder. See
for double checking the same information using a bash command instead of the grass g.gisenv command.
It is a good working habit within Grass to set bash shell working directory the same as your GRASS LOCATION folder.
On the terminal you will no longer see
GRASS 7.4.0 (europe):~ >
GRASS 7.4.0 (europe):~/ost4sem/grassdb/europe >
and you will be aware tif your current bash shell working directory match your grass location directory.
We have explained that grass projects can be organised in MAPSETs by users, by themes, by extent or locations, and grouped within the same grass LOCATION. This LOCATION will group several MAPSETS defined by a common projection and is able to access a common set of maps in the PERMANENT MAPSET forlder.
When we work in a specific MAPSET we will have no rights to write or delete maps in a different MAPSET. For doing so you will have to change your working MAPSET directory and then delete or produce new maps.
The g.mapset command allows you to change the Grass working directory and successively generate, delete or modify maps as you wish.
From grass 6.3 only the -c flag creates a new mapset if it doesn't exist.; -l List available mapsets (!)
To list your available maps:
g.list type=vect -p
g.list vect -p
g.list rast -p
The user can add, modify, and delete data layers that exist under his current mapset. Although the user can also access (i.e., use) data that are stored under other mapsets in the same GRASS location, the user can only make permanent changes (create or modify data) located in the current mapset.
Now we can access the fnfpc_crop mapset and eventually copy a map from the PCEMstat mapset to our current mapset directory using the g.copy function:
g.list rast -p
And delete a map with the g.remove command
g.remove -f type=rast name=fnfpc_crop
You can access but not delete or modify a map in a different mapset from your current
g.remove -f type=rast name=fnfpc_crop@PCEMstat
We have to be careful in Grass to understand the possible differences existing in the same MAPSET between the whole extent and resolution of the MAPSET itself, the extent, resolution and geographic location of our working region, and the extent and location of what we are visualising.
In GRASS, a region refers to a geographic area with some defined boundaries, based on a specific map coordinate system and map projection. Grass region definition and details. This crucial Grass setting will allow us to define within MAPSET settings a particular region of work.
Once defined the grass region, grass modules (or programs) will operate within this region. The user can create, modify, and store as many geographic region definitions as desired for any given mapset. However, only one of these geographic region definitions will be current at any given moment, for a specified mapset. GRASS programs that respect the geographic region settings will use the current geographic region settings.
To query your current region settings type
and to reset region settings to their original extent type
-p stands for “print” ; -d stands for default
You can modify your default g. region with a -s flag within the PERMANENT directory.
Now we will define a new study area for the Scandinavia region.
You will visualize the current and newest region settings saved as scandinavia
If you open the GRASS gui
You can visualize the Computational Region in the Display menu by cliking “Show computation Extent” and you will see the Scandinavia area within a red frame.
Back to GRASS if you reset the default grass region
Clipping maps and changing resolution use
g.region allow us to do two basic GIS function: resample and clip.
We would like to have 3 new maps of forest/non-forest percentage clipped and resampled with a different resolution from a forest/non-forest map. The original forest/non-forest map has the European extent and 1km resolution. We need to generate:
Italian extent map at 20km resolution,
Alpine extent map at 10km resolution
Alpine and Carpathians extent map at 5km reslution.
In the europe LOCATION different g.region exists:
The g.region are saved in the following folders and named as follow:
We now resample the g.region at 20km using the res=new_res option and will set 75 x 57 pixels of 20k resolution