R

Today we are proud to announce a major release of the RQGIS package providing an interface between R and QGIS. We have completeley rewritten RQGIS by now using reticulate to establish a tunnel to the Python QGIS API. To make RQGIS even more user-friendly, we have implemented, among others, following features:

set_env now caches its output, so you have to call it only once

find_algorithms now supports regular expressions

run_qgis now accepts R named arguments as input (see example below). The load_output argument is now logical. If TRUE all specified output files will be loaded into R.

RQGIS now supports simple features

For a detailed overview of all changes, please refer to the release news.

Let’s use RQGIS for calculating the slope and the aspect of a digital elevation model. First of all, we have to attach RQGIS and a digital elevation model (dem) to the global environment:

library("RQGIS")
data("dem", package = "RQGIS")

Next, we need to find all paths necessary to run successfully the Python QGIS API. Please note, that the output of set_env will be cached and reused in subsequent function calls. Note also, that set_env is always faster when you indicate the path to your QGIS installation, in my case e.g., set_env(root = "C:/OSGeo4W64"). Secondly, we open a QGIS Python application with open_app.

set_env()
open_app()

Now, that we have established a tunnel to the QGIS Python API, we are ready for some geoprocessing. First, we need a geoalgorithm, that computes the slope and the aspect of a digital elevation model. To find the name of such a geoalgorithm, we use a regular expression which searches for the terms slope and aspect in all available QGIS geoalgorithms.

We will use grass7:r.slope.aspect. To retrieve its function parameters and arguments you can run get_usage("grass7:r.slope.aspect"). Use get_args_man to collect the parameter-argument list including all default values:

params <- get_args_man("grass7:r.slope.aspect")

As with previous RQGIS releases, you can still modify the parameter-argument list and submit it to run_qgis:

But now you can also use R named arguments in run_qgis, i.e. you can specify the geoalgorithms parameters directly in run_qgis (adapted from package rgrass7). Here, we specify the input- and the output-rasters. For all other parameters, default values will automatically be used. For more information on the R named arguments, please refer also to the documentation by running ?run_qgis and/or ?pass_args.

Setting load_output to TRUE automatically loads the resulting QGIS output back into R. Since we have specified two ouput files, the output will be loaded into R as a list (here named out) with two elements: a slope and an aspect raster. However, in the background, QGIS calculates all terrain attributes and derivatives provided by grass7:r.slope.aspect, and saves them to a temporary location. Of course, if you wish you can still access these layers from there.

Before running RQGIS, you need to install third-party software. We wrote a package vignette, which guides you through the installation process of QGIS, GRASS and SAGA on various platforms. To access the vignette, please run:

vignette("install_guide", package = "RQGIS")

For more information on RQGIS and examples how to use RQGIS, please refer to its github page and my blog.

Today we are happy to announce a new version of RQGIS! RQGIS establishes an interface between R and QGIS, i.e. it allows the user to access the more than 1000 QGIS geoalgorithms from within R. The most important news is that you can run again the most recent QGIS releases (>=2.18.2) with RQGIS without having to modify Python source code. This modification became necessary due to a bug introduced in QGIS 2.16 (see here).

This release also fixes several bugs which we detected thanks to user feedback. Please refer to the release news for more detailed information.

Before running RQGIS, you need to install third-party software. To guide you through the installation process of QGIS, GRASS and SAGA on various platforms, we wrote a package vignette. To install RQGIS and to access the vignette, please run:

We are happy to announce the MSCJ-LIFE spring school on Statistical analysis of hyperspectral and high-dimensional remote-sensing data. The spring school will take place in Jena (Germany) at the GIScience department of the Friedrich-Schiller University on March 13-17 2017. We invite participants from a wide range of disciplines interested in high-dimensional (geo-)data manipulation, viszualization and analysis mainly using R. International experts will provide a mixture of theory and hands-on sessions. Here you can find more information about the training school as well as the program. The deadline for applicants is January 31st 2017 (late applications accepted if places remain). Please apply through this link. We would be grateful if you distributed this information to all people potentially interested in this spring school, and are looking forward to welcoming you in Jena this spring!

We proudly announce the release of RQGIS! RQGIS establishes an interface between R and QGIS, i.e. it allows the user to access the more than 1000 QGIS geoalgorithms from within R. To install it, run:

install.packages("RQGIS")

Naturally, you need to install other software (such as QGIS) to run RQGIS properly. Therefore, we wrote a package vignette, which guides you through the installation process of QGIS, GRASS and SAGA on various platforms. To access it, run:

vignette("install_guide", package = "RQGIS")

How to use RQGIS

To introduce RQGIS, we will demonstrate how to calculate the SAGA topographic wetness index. The first step is the creation of a QGIS environment. This is a list containing the paths RQGIS needs to access QGIS. Luckily for us, set_env does this for us. We merely need to specify the root path to the QGIS installation. This is most likely something like C:/OSGeo4W~1 on Windows, /usr on Linux and /usr/local/Cellar on a Mac. If we do not specify a path to the QGIS root folder, set_env tries to figure it out. This, however, might be time-consuming depending on the size of the drives to search.

library("RQGIS")
env <- set_env()

Secondly, we need to find out the name of the function in QGIS which calculates the wetness index:

There are three algorithms containing the words wetness and index in their short description. Here, we choose saga:sagawetnessindex. To retrieve the corresponding function arguments, we use get_args_man. By setting option to TRUE, we indicate that we would like to use the default values, if available:

Of course, we need to specify certain function arguments such as the input (DEM) and output (TWI) arguments. Please note that RQGIS accepts as input argument either the path to a spatial object or a spatial object residing in R. Here, we will use a digital elevation model, which comes with the RQGIS package:

A while ago Arnold explained in his post how to create an inset map using ggplot2. This is great but I have to admit I rarely use ggplot2 in combination with spatial data. Instead I often find myself using the plot functions provided by the raster- and sp-package. To create an inset map with these plot methods, we have to slightly adjust Arnold’s code.

Kurt Menge recently explained in his post how it is possible to use R from within QGIS – the leading and open-software Desktop GIS. This is great but to access the geoalgorithms provided by QGIS you would still have to use Python or the QGIS GUI. So it would come in quite handy, if one could access QGIS geoalgorithms from within R. And that’s exactly what the RQGIS package is doing. This opens up a whole new world of (geo-)statistical geocomputing.

The most notable features of RQGIS are:

RQGIS accesses the Python QGIS API but R users can stay in the familiar R programming environment without having to touch Python.

For the first time, you can access native QGIS algorithms from within R.

QGIS itself integrates many third-party providers. Among these are GDAL, SAGA GIS, GRASS GIS and many more. RQGIS brings you this incredibly resourceful geoprocessing environment to the R console. Though it is a big advantage to be able to access SAGA and GRASS functions using only one package (RQGIS), RSAGA and rgrass7 (spgrass6) are still useful (and great packages by the way). For instance, not all SAGA and GRASS functions are available in QGIS.

RQGIS offers convenience functions. For example, get_args_man mimics the behavior of the QGIS GUI by automatically retrieving all function arguments and corresponding default values for a given function. This makes the usage of RQGIS frequently more user-friendly compared to RSAGA and rgrass7 (spgrass6). But that is just my opinion and you are more than welcome to check it out.

The second convenience function open_help lets the user access the QGIS online help for a specified geoalgorithm. Bar a few exceptions, this already works for all GRASS, QGIS and SAGA functions.

In the last few weeks we have been testing the package (though with a strong focus on GRASS, QGIS and SAGA functionalities). Within the next six weeks, we would like to put RQGIS on CRAN. Until then the R(-GIS) community is more than welcome to install the developer version. On https://github.com/jannes-m/RQGIS you will find a quick tour how to install and use RQGIS. We would appreciate any feedback, and of course you are welcome to contribute to our package.