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 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, you can run GRASS tools from QGIS without starting GRASS explicitly.

There 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, we load into QGIS input data, Jena city region and Sentinel bands (red and near-infrared channels).

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

Fig. 46 Input data loaded in QGIS.

Processing plugin

Processing plugin is a generic toolbox which allows to use 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. 47 Search for i.vi GRASS module in Processing toolbox.

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

Fig. 48 Set input parameters, don’t forget about computation region.

Fig. 50 nicely shows how Processing plugin is working. First of all a temporal GRASS location is created by g.proj, then input data are linking into this location by r.external. Then computation can finally starts by running i.vi. In the last step output data are exported outside of GRASS using r.out.gdal. The resultant GTIFF file can be displayed in QGIS map window.

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

Fig. 49 Running tool, most of time takes exporting data outside of GRASS temporal session.

../_images/processing-result.png

Fig. 50 Resultant NDVI raster displayed to QGIS map window (with better color interpretation than grayscale).

Note

We skipped masking cloud mask areas. There is a room for improvements ;-)

GRASS plugin

GRASS plugin has been designed to support GRASS as processing toolbox in more straightforward way. 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 environment. On the other hand, in contrast to Processing plugin, the GRASS plugin requires at least basic knowledge of GRASS GIS. User have to understand concept of locations and mapset, and control computational region. Data created by GRASS plugin are persistent and accessible also by GRASS itself.

GRASS plugin behaves similarly to GRASS itself. In order to use GRASS tools, there must be location and mapset to be entered. New location/mapset can be created by Plugins ‣ GRASS ‣ New Mapset. Creating new mapsets in GRASS plugin is a very similar procedure to creating location/mapset in native GRASS environment, see Creating new location (Unit 02). As we already have GRASS location and mapset prepared from Unit 02 - First steps, we can easily open it by Plugins ‣ GRASS ‣ Open Mapset.

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

Fig. 51 Open existing location and mapset by GRASS plugin.

After opening mapset, the GRASS tools are activated and accessible from menu Plugins ‣ GRASS ‣ Open GRASS Tools.

As advanced GRASS users, we know that before any computation 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 GRASS module.

../_images/grass-region.svg

Fig. 52 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).

Unfortunately i.vi GRASS module is not available in GRASS plugin. We can try to compute NDVI index using r.mapcalc, and well-known map algebra technique.

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

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

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

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

Fig. 54 Graphical Map Calculator in GRASS plugin.

For those who don’t like this tool there is another possibility. To launch i.vi from GRASS Shell.

../_images/grass-shell.png

Fig. 55 GRASS Shell.

Tip

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

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

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

In any case, output data are stored in current mapset open by GRASS plugin. And GRASS data can be directly accessed by QGIS Browse panel in standard way as other data sources, see Fig. 57.

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

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