<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-release-1-0-0/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://jannesm.wordpress.com/2017/05/26/rqgis-release-1-0-0/"> R – jannesm</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>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 <a target="_blank" rel="nofollow" href="https://github.com/rstudio/reticulate">reticulate</a> to establish a tunnel to the Python QGIS API. To make RQGIS even more user-friendly, we have implemented, among others, following features:</p>
<ul>
<li><code>set_env</code> now caches its output, so you have to call it only once</li>
<li><code>find_algorithms</code> now supports regular expressions</li>
<li><code>run_qgis</code> now accepts R named arguments as input (see example below). The <code>load_output</code> argument is now logical. If <code>TRUE</code> all specified output files will be loaded into R.</li>
<li>RQGIS now supports simple features</li>
</ul>
<p>For a detailed overview of all changes, please refer to the <a target="_blank" rel="nofollow" href="https://github.com/jannes-m/RQGIS/releases/tag/v0.2.0">release news</a>.</p>
<p><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="https://jannesm.files.wordpress.com/2016/06/r_qgis_puzzle.png" data-orig-size="1169,813" data-image-title="r_qgis_puzzle" class="wp-image-18" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="18" data-permalink="https://jannesm.wordpress.com/2016/06/23/integrating-r-with-qgis/r_qgis_puzzle/" alt="r_qgis_puzzle" data-medium-file="https://jannesm.files.wordpress.com/2016/06/r_qgis_puzzle.png?w=300&amp;h=209&amp;fit=300%2C209&amp;resize=300%2C209" data-large-file="https://jannesm.files.wordpress.com/2016/06/r_qgis_puzzle.png?w=676" data-image-meta="{" src="https://jannesm.files.wordpress.com/2016/06/r_qgis_puzzle.png?w=300&h=209&fit=300%2C209&resize=300%2C209"></p>
<p>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:</p>
<pre><code>library(&quot;RQGIS&quot;)
data(&quot;dem&quot;, package = &quot;RQGIS&quot;)</code></pre>
<p>Next, we need to find all paths necessary to run successfully the Python QGIS API. Please note, that the output of <code>set_env</code> will be cached and reused in subsequent function calls. Note also, that <code>set_env</code> is always faster when you indicate the path to your QGIS installation, in my case e.g., <code>set_env(root = &quot;C:/OSGeo4W64&quot;)</code>. Secondly, we open a QGIS Python application with <code>open_app</code>.</p>
<pre><code>set_env()
open_app()</code></pre>
<p>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 <code>slope</code> and <code>aspect</code> in all available QGIS geoalgorithms.</p>
<pre><code>find_algorithms(&quot;slope(.+)?aspect&quot;)</code></pre>
<pre><code>## [1] &quot;r.slope.aspect - Generates raster layers of slope, aspect, curvatures and partial derivatives from a elevation raster layer.--->grass7:r.slope.aspect&quot;
## [2] &quot;Slope, aspect, curvature----------------------------->saga:slopeaspectcurvature&quot;                                                                      
## [3] &quot;r.slope.aspect - Generates raster layers of slope, aspect, curvatures and partial derivatives from a elevation raster layer.--->grass:r.slope.aspect&quot;</code></pre>
<p>We will use <code>grass7:r.slope.aspect</code>. To retrieve its function parameters and arguments you can run <code>get_usage(&quot;grass7:r.slope.aspect&quot;)</code>. Use <code>get_args_man</code> to collect the parameter-argument list including all default values:</p>
<pre><code>params &lt;- get_args_man(&quot;grass7:r.slope.aspect&quot;)</code></pre>
<p>As with previous RQGIS releases, you can still modify the parameter-argument list and submit it to <code>run_qgis</code>:</p>
<pre><code>params$elevation &lt;- dem
params$slope &lt;- &quot;slope.tif&quot;
params$aspect &lt;- &quot;aspect.tif&quot;
run_qgis(alg = &quot;grass7:r.slope.aspect&quot;, params = params)</code></pre>
<p>But now you can also use R named arguments in <code>run_qgis</code>, 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 <code>?run_qgis</code> and/or <code>?pass_args</code>.</p>
<pre><code>out &lt;- run_qgis(alg = &quot;grass7:r.slope.aspect&quot;, elevation = dem, 
                slope = &quot;slope.tif&quot;, aspect = &quot;aspect.tif&quot;, 
                load_output = TRUE)</code></pre>
<pre><code>## $slope
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\RtmpmsSSA4/slope.tif&quot;
## 
## $aspect
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\RtmpmsSSA4/aspect.tif&quot;
## 
## $dxy
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\ac7b8544e8194dd1a1b8710e6091f1f3\\dxy.tif&quot;
## 
## $dxx
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\1576d9dc93434a578b3aeb16bedb17a2\\dxx.tif&quot;
## 
## $tcurvature
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\afea27676cc049faaa8526a486f13f70\\tcurvature.tif&quot;
## 
## $dx
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\2d71fd26b1aa4868a5cdfd0d7ad47a0c\\dx.tif&quot;
## 
## $dy
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\458f38f6c71947d3a37532e4bc6a6a53\\dy.tif&quot;
## 
## $pcurvature
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\80ad6fa1843d4d3a92ed0b4c6a39dcfa\\pcurvature.tif&quot;
## 
## $dyy
## [1] &quot;C:\\Users\\pi37pat\\AppData\\Local\\Temp\\processing5bb46293bfb243f092a57ce9cf50348b\\6c52d235c8614a719954f1f744e3fef1\\dyy.tif&quot;</code></pre>
<p>Setting <code>load_output</code> to <code>TRUE</code> 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 <code>out</code>) with two elements: a slope and an aspect raster. However, in the background, QGIS calculates all terrain attributes and derivatives provided by <code>grass7:r.slope.aspect</code>, and saves them to a temporary location. Of course, if you wish you can still access these layers from there.</p>
<p>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:</p>
<pre><code>vignette(&quot;install_guide&quot;, package = &quot;RQGIS&quot;)</code></pre>
<p>For more information on RQGIS and examples how to use RQGIS, please refer to its <a target="_blank" rel="nofollow" href="https://github.com/jannes-m/RQGIS">github page</a> and my <a target="_blank" rel="nofollow" href="https://jannesm.wordpress.com/category/r/">blog</a>.</p>
</div>
<p></p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jannesm.wordpress.com/95/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/jannesm.wordpress.com/95/" 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>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/2017/05/26/rqgis-release-1-0-0/"> 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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/p6Pp3KJMCbs"></a></div>