• Stars
    star
    196
  • Rank 194,910 (Top 4 %)
  • Language
    R
  • License
    GNU General Publi...
  • Created almost 4 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

R package to use QGIS processing algorithms

qgisprocess

R build status Lifecycle: experimental Codecov test coverage

The goal of qgisprocess is to provide an R interface to the popular and open source desktop geographic information system (GIS) program QGIS. The package is a re-implementation of functionality provided by the archived RQGIS package, which was partially revived in the RQGIS3 package.

Installation

qgisprocess

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("r-spatial/qgisprocess")

QGIS

The qgisprocess package wraps the standalone qgis_process command-line utility, which is available in QGIS >= 3.16.

The package is meant to support current QGIS releases, i.e. both the latest and the long-term release. Although older QGIS releases are not officially supported, it may work since QGIS 3.16. Download instructions for all platforms are available at https://download.qgis.org/.

If a recent version of QGIS isn’t available for your OS, you can use the Geocomputation with R Docker image with QGIS installed (docker pull ghcr.io/geocompx/docker:qgis). See the vignette on ‘getting started’ for more information.

Package configuration

If the automatic configuration fails (or if you have more than one installation and would like to choose which one is used by qgisprocess), you can set options(qgisprocess.path = "path/to/qgis_process"). Specify the qgisprocess.path option in your .Rprofile, to make your choices persistent between sessions. You can run qgis_configure() to reconfigure, or just qgis_configure(use_cached_data = TRUE) to see the gritty details!

library(qgisprocess)
#> Attempting to load the cache ... Success!
#> QGIS version: 3.30.2-'s-Hertogenbosch
#> Having access to 1949 algorithms from 13 QGIS processing providers.
#> Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.

Functionality

Most functions start with the qgis_ prefix, so that functions can be found more easily using tab completion.

The main function is qgis_run_algorithm(algorithm = , ...). It specifies the geoprocessing algorithm to be called with a "provider:algorithm" formatted identifier, e.g. "native:convexhull" or "gdal:hillshade", and it passes the algorithm arguments as R function arguments.

Additional functions are provided to discover available geoprocessing algorithms, retrieve their documentation, handle processing results, manage QGIS plugins, and more.

Spatial layers can be passed to qgis_run_algorithm() as file paths but also as sf, stars, terra or raster objects.

A structured overview of functions is available at https://r-spatial.github.io/qgisprocess/reference/index.html. To get started, read the ‘getting started’ vignette and use the cheat sheets!

Note that R package qgis extends on qgisprocess by providing a separate R function for each geoprocessing algorithm. In addition, it makes the QGIS algorithm documentation available in the corresponding R function documentation.

Example

The following example demonstrates the buffer algorithm in action.

input <- sf::read_sf(system.file("shape/nc.shp", package = "sf"))

result <- qgis_run_algorithm(
  "native:buffer",
  INPUT = input,
  DISTANCE = 1,
  DISSOLVE = TRUE
)
#> Argument `SEGMENTS` is unspecified (using QGIS default value).
#> Using `END_CAP_STYLE = "Round"`
#> Using `JOIN_STYLE = "Round"`
#> Argument `MITER_LIMIT` is unspecified (using QGIS default value).
#> Using `OUTPUT = qgis_tmp_vector()`

result
#> <Result of `qgis_run_algorithm("native:buffer", ...)`>
#> List of 1
#>  $ OUTPUT: 'qgis_outputVector' chr "/tmp/RtmpsCZuzJ/file7d1b75a4d4eb/file7d1b1ab3935f.gpkg"

output_sf <- sf::st_as_sf(result)
plot(sf::st_geometry(output_sf))

You can read the help associated with an algorithm using qgis_show_help().

qgis_show_help("native:buffer")

It may also be useful to run an algorithm in the QGIS GUI and examine the console ‘Input parameters’ to determine how the various input values are translated to string processing arguments:

A list of available algorithms can be found using qgis_algorithms(). When using R interactively, it may be useful to use View(qgis_algorithms()) to search.

qgis_algorithms()
#> # A tibble: 1,949 × 24
#>    provider         provider_title    algorithm     algorithm_id algorithm_title
#>    <chr>            <chr>             <chr>         <chr>        <chr>          
#>  1 3d               QGIS (3D)         3d:tessellate tessellate   Tessellate     
#>  2 cartographytools Cartography tools cartographyt… averagelines Average linest…
#>  3 cartographytools Cartography tools cartographyt… collapsedua… Collapse dual …
#>  4 cartographytools Cartography tools cartographyt… removecross… Remove cross r…
#>  5 cartographytools Cartography tools cartographyt… removeculde… Remove cul-de-…
#>  6 cartographytools Cartography tools cartographyt… removeround… Remove roundab…
#>  7 gdal             GDAL              gdal:aspect   aspect       Aspect         
#>  8 gdal             GDAL              gdal:assignp… assignproje… Assign project…
#>  9 gdal             GDAL              gdal:bufferv… buffervecto… Buffer vectors 
#> 10 gdal             GDAL              gdal:buildvi… buildvirtua… Build virtual …
#> # ℹ 1,939 more rows
#> # ℹ 19 more variables: provider_can_be_activated <lgl>,
#> #   provider_is_active <lgl>, provider_long_name <chr>, provider_version <chr>,
#> #   provider_warning <chr>, can_cancel <lgl>, deprecated <lgl>, group <chr>,
#> #   has_known_issues <lgl>, help_url <chr>, requires_matching_crs <lgl>,
#> #   short_description <chr>, tags <list>, default_raster_file_extension <chr>,
#> #   default_vector_file_extension <chr>, …

Further reading

  • A paper on the original RQGIS package published in the R Journal
  • A discussion options for running QGIS from R that led to this package
  • The pull request in the QGIS repo that led to the development of the qgis_process command-line utility

More Repositories

1

sf

Simple Features for R
R
1,265
star
2

rgee

Google Earth Engine for R
R
650
star
3

stars

Spatiotemporal Arrays, Raster and Vector Data Cubes
R
540
star
4

mapview

Interactive viewing of spatial data in R
JavaScript
503
star
5

leafgl

R package for fast web gl rendering for leaflet
R
261
star
6

mapedit

Interactive editing of spatial data in R
R
216
star
7

RQGIS

RQGIS - integrating R with QGIS
R
189
star
8

gstat

Spatial and spatio-temporal geostatistical modelling, prediction and simulation
C
188
star
9

dtwSat

Time-Weighted Dynamic Time Warping for satellite image time series analysis
R
126
star
10

spdep

Spatial Dependence: Weighting Schemes and Statistics
R
111
star
11

leafpop

Include Tables, Images and Graphs in Leaflet Popups
R
111
star
12

leafem

leaflet extensions for mapview
JavaScript
104
star
13

RQGIS3

R
69
star
14

s2

Spherical Geometry Operators Using the S2 Geometry Library
C++
69
star
15

r-spatial.org

r-spatial.org blog sources
HTML
58
star
16

lwgeom

bindings to the liblwgeom library
C
57
star
17

discuss

a discussion repository: raise issues, or contribute!
54
star
18

sfdbi

DBI interface to sf
R
53
star
19

sftime

time extension to sf objects
R
49
star
20

spatialreg

spatialreg: spatial models estimation and testing
R
41
star
21

rspatial_spark

This is the repo that sparked https://github.com/r-spatial
HTML
36
star
22

cesium

Cesium wrapper to R
R
33
star
23

leafsync

Small Multiples for Leaflet Webmaps
JavaScript
32
star
24

global

R-global: analysing spatial data globally
HTML
31
star
25

classInt

Choose Univariate Class Intervals
R
29
star
26

RPyGeo

Update of RPyGeo package - currently WIP
R
27
star
27

evolution

Preparing CRAN for the retirement of rgdal, rgeos and maptools
TeX
25
star
28

link2GI

Simplify the linking of GIS/RS and CLI tools
R
25
star
29

slideview

Compare Rasters Side by Side with a Slider
R
25
star
30

cubeview

Interactively Explore 3D Raster Data Cubes
JavaScript
24
star
31

leafpm

Leaflet.pm for R Leaflet
R
22
star
32

RSAGA

R
19
star
33

plainview

View Raster Images Interactively on a Plain HTML Canvas
R
13
star
34

task_views

Local copy for editing CRAN Task Views
R
9
star
35

rgeopackage

R package with helper tools in creating or handling GeoPackage files
R
9
star
36

r-spatial.github.io

r-spatial.github.io website
HTML
5
star