<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/rqgis-0-1-0-release/"></div></div><div><a data-url="https://www.r-bloggers.com/rqgis-0-1-0-release/" data-counturl="https://www.r-bloggers.com/rqgis-0-1-0-release/" data-count="horizontal" data-text="RQGIS 0.1.0 release" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://jannesm.wordpress.com/2016/08/15/rqgis-0-1-0-release/"> R – jannesm</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p></p>
<p>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:</p>
<pre><code>install.packages(&quot;RQGIS&quot;)</code></pre>
<p>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:</p>
<pre><code>vignette(&quot;install_guide&quot;, package = &quot;RQGIS&quot;)</code></pre>
<div>
<h2>How to use RQGIS</h2>
<p>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, <code>set_env</code> does this for us. We merely need to specify the root path to the QGIS installation. This is most likely something like <code>C:/OSGeo4W~1</code> on Windows, <code>/usr</code> on Linux and <code>/usr/local/Cellar</code> on a Mac. If we do not specify a path to the QGIS root folder, <code>set_env</code> tries to figure it out. This, however, might be time-consuming depending on the size of the drives to search.</p>
<pre><code>library(&quot;RQGIS&quot;)
env &lt;- set_env()</code></pre>
<p>Secondly, we need to find out the name of the function in QGIS which calculates the wetness index:</p>
<pre><code>find_algorithms(&quot;wetness index&quot;, name_only = TRUE, qgis_env = env)</code></pre>
<pre><code>## [1] &quot;taudem:topographicwetnessindex&quot;  &quot;saga:sagawetnessindex&quot;          
## [3] &quot;saga:topographicwetnessindextwi&quot; &quot;&quot;</code></pre>
<p>There are three algorithms containing the words wetness and index in their short description. Here, we choose <code>saga:sagawetnessindex</code>. To retrieve the corresponding function arguments, we use <code>get_args_man</code>. By setting <code>option</code> to <code>TRUE</code>, we indicate that we would like to use the default values, if available:</p>
<pre><code>args &lt;- get_args_man(alg = &quot;saga:sagawetnessindex&quot;, 
                     options = TRUE,
                     qgis_env = env)
# print the retrieved list
args</code></pre>
<pre><code>## $DEM
## [1] &quot;None&quot;
## 
## $SUCTION
## [1] &quot;10.0&quot;
## 
## $AREA_TYPE
## [1] &quot;0&quot;
## 
## $SLOPE_TYPE
## [1] &quot;0&quot;
## 
## $SLOPE_MIN
## [1] &quot;0.0&quot;
## 
## $SLOPE_OFF
## [1] &quot;0.1&quot;
## 
## $SLOPE_WEIGHT
## [1] &quot;1.0&quot;
## 
## $AREA
## [1] &quot;None&quot;
## 
## $SLOPE
## [1] &quot;None&quot;
## 
## $AREA_MOD
## [1] &quot;None&quot;
## 
## $TWI
## [1] &quot;None&quot;</code></pre>
<p>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:</p>
<pre><code># load data into R
data(&quot;dem&quot;, package = &quot;RQGIS&quot;)
# define input
args$DEM &lt;- dem
# specify output path
args$TWI &lt;- &quot;twi.asc&quot;</code></pre>
<p>Finally, we can access QGIS from within R by supplying <code>run_qgis</code> with the specified arguments as a list. Specifying also the <code>load_output</code>-argument directly loads the QGIS output into R.</p>
<pre><code>twi &lt;- run_qgis(alg = &quot;saga:sagawetnessindex&quot;, 
                params = args, 
                load_output = args$TWI, 
                qgis_env = env)

# visualize the result
library(&quot;raster&quot;)
hs &lt;- hillShade(terrain(dem), terrain(dem, &quot;aspect&quot;), 40, 270)
pal &lt;- RColorBrewer::brewer.pal(6, &quot;Blues&quot;)
spplot(twi, col.regions = pal, alpha.regions = 0.8,
       scales = list(tck = c(1, 0)),               
       colorkey = list(space = &quot;bottom&quot;,
                               width = 1, height = 0.5,
                       axis.line = list(col = &quot;black&quot;)),
       cuts = length(pal) - 1) +
  latticeExtra::as.layer(spplot(hs, col.regions = gray(0:100 / 100)), 
                         under = TRUE)</code></pre>
</div>
<p> </p>
<div>
<p><img alt="twi" class="wp-image-58" src="https://i2.wp.com/jannesm.files.wordpress.com/2016/08/twi.png?fit=456%2C456&ssl=1" data-recalc-dims="1"></p>
<p>For more information on RQGIS, please refer to <a target="_blank" href="https://github.com/jannes-m/RQGIS">https://github.com/jannes-m/RQGIS</a>.</p>
</div>
</div>
<p> </p>
<p></p>
<p> </p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jannesm.wordpress.com/49/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/jannesm.wordpress.com/49/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/rqgis-0-1-0-release/"></div></div><div><a data-url="https://www.r-bloggers.com/rqgis-0-1-0-release/" data-counturl="https://www.r-bloggers.com/rqgis-0-1-0-release/" data-count="vertical" data-text="RQGIS 0.1.0 release" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://jannesm.wordpress.com/2016/08/15/rqgis-0-1-0-release/"> R – jannesm</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/xoUTXL1HHTA"></a></div>