Unit 07 - QGIS loves GRASS

Let’s step out of the GRASS GIS for a moment. QGIS is a very popular open source GIS package which made a significant progress in the last years. Nowadays it’s used in education, academic environment, but also in commercial settings. The project started originally more or less as a multiplatform browser for geospatial data. This is not a true any more, QGIS made important steps for being an analytic tool. Beside native algoritms QGIS offers also connection to external software packages like SAGA, Orfeo or GRASS GIS. In other words, GRASS tools can be run directly from QGIS enviroment without starting GRASS explicitly.

There are two options how to access GRASS tools from QGIS environment:

  • generic Processing plugin
  • specialized GRASS plugin

Both plugins can be easily activated from Plugins ‣ Manage and Install Plugins.

Let’s focus on our “favorite” GRASS module - i.vi. At first, load into QGIS input data, Jena city region and Sentinel bands (red and near-infrared channels).

../_images/qgis-input-data.png

Fig. 44 Input data loaded in QGIS.

Processing plugin

Processing plugin is a generic toolbox which allows to run processing tools provided by various software packages. Let’s open Processing ‣ Toolbox and search for i.vi GRASS module.

../_images/processing-i-vi.png

Fig. 45 Search for i.vi GRASS module in Processing toolbox.

../_images/processing-i-vi-params.svg

Fig. 46 Set input parameters (red and nir channels). Computation extent can be optionally defined in Advanced parameters section.

Fig. 47 shows how Processing plugin works. First of all a temporary GRASS location is created by g.proj, input data is linked into temporary location by r.external. Then computation can finally starts by running i.vi module. In the last step output data are exported out of GRASS using r.out.gdal. The resultant GeoTiff file is displayed in QGIS map window.

../_images/processing-i-vi-running.png

Fig. 47 Running i.vi tool, significant portion of computation time takes exporting data out of GRASS temporary session.

../_images/processing-result.png

Fig. 48 Resultant NDVI raster displayed in QGIS map window (with better color interpretation than grayscale). No clouds mask involved.

GRASS plugin

GRASS plugin has been designed to support GRASS as a native processing toolbox. This also includes ability to display data stored in GRASS native format (raster and vector maps located in GRASS locations). And, of course, ability to run any GRASS command with full flexibility of GRASS GIS environment. On the other hand, in contrast to Processing plugin, the GRASS plugin requires at least a basic knowledge of GRASS GIS concept. User have to understand concept of locations and mapsets, and control of computational region. In opposite to Processing plugin a data created by GRASS plugin are persistent, so accessible also by GRASS GIS itself.

In order to use GRASS tools, there must be a location and a mapset available to be entered. New location/mapset can be created by Plugins ‣ GRASS ‣ New Mapset. Creating a new mapset using GRASS plugin is a very similar procedure to creating location/mapset in native GRASS GIS environment, see Creating new location (Unit 02). Since there is already GRASS location and mapset prepared from Unit 02 - First steps it can be entered by Plugins ‣ GRASS ‣ Open Mapset.

../_images/grass-open-mapset.png

Fig. 49 Enter existing location and mapset by GRASS plugin.

After entering an existing mapset, the GRASS tools are activated from menu Plugins ‣ GRASS ‣ Open GRASS Tools.

As advanced GRASS users it is clear that before any raster-related computation a desired computational region must be defined. For this task, GRASS plugin offers GUI tool in Region tab. In any case, for more advanced operations can be used g.region module.

../_images/grass-region.svg

Fig. 50 Set computation region from map display. Don’t forget to set correct spatial resolution (for real work it’s better to use g.region with align option).

Simply launch i.vi from Modules tab.

../_images/grass-i-vi.png

Fig. 51 Launch i.vi module from GRASS plugin.

Tip

GRASS modules can be launched from GRASS shell as shows the figure below.

../_images/grass-shell.png

Fig. 52 Start a GRASS Shell.

By adding a flag –ui to the end of command, a native GRASS GUI dialog appears. In this way other GRASS tools like g.gui.gmodeler (see Unit 08 - Modeler) or a whole GRASS GUI by g.gui can started. Yes, it seems schizophrenic a bit to start GRASS GUI from GRASS plugin in QGIS environment. Someone can ask, why don’t you use GRASS directly ;-)

../_images/grass-i-vi-shell.svg

Fig. 53 Launch native GUI dialog for i.vi GRASS module.

Note

NDVI can be alternatively computed using r.mapcalc.

../_images/grass-r-mapcalc.png

Fig. 54 Search r.mapcalc module in GRASS plugin.

GRASS plugin offers a native graphical front-end for map algebra.

../_images/grass-map-calc.png

Fig. 55 Graphical Map Calculator in GRASS plugin.

Resultant output data are stored in the current mapset open by GRASS plugin. Native GRASS data can be directly accessed from QGIS Browse Panel in a standard way as other data sources, see Fig. 56.

../_images/grass-data-browse.png

Fig. 56 Browse GRASS data similarly as other data sources.