Learn R Programming

RQGIS (version 0.2.0)

run_qgis: Interface to QGIS commands

Description

run_qgis calls QGIS algorithms from within R while passing the corresponding function arguments.

Usage

run_qgis(alg = NULL, params = NULL, check_params = TRUE,
  show_msg = TRUE, load_output = NULL, qgis_env = set_env())

Arguments

alg

Name of the GIS function to be used (see find_algorithms).

params

A list of geoalgorithm function arguments that should be used in conjunction with the selected (Q)GIS function (see get_args_man). Please make sure to provide all function arguments in the correct order. To make sure this is the case, it is recommended to use the convenience function get_args_man.

check_params

If TRUE (default), it will be checked if all geoalgorithm function arguments were provided in the correct order.

show_msg

Logical, if TRUE, Python messages that occured during the algorithm execution will be shown.

load_output

Character vector containing paths to (an) output file(s) in order to load the QGIS output directly into R (optional). If load_output consists of more than one element, a list will be returned. See the example section for more details.

qgis_env

Environment containing all the paths to run the QGIS API. For more information, refer to set_env.

Value

If not otherwise specified, the function saves the QGIS generated output files in a temporary folder. Optionally, function parameter load_output loads spatial QGIS output (vector and raster data) into R.

Details

This workhorse function calls the QGIS Python API through the command line. Specifically, it calls processing.runalg.

Examples

Run this code
# NOT RUN {
# set the environment
my_env <- set_env()
# find out how a function is called
find_algorithms(search_term = "add", qgis_env = my_env)
# specify parameters
params <- get_args_man("saga:addcoordinatestopoints", qgis_env = my_env)
# load random_points - a SpatialPointsDataFrame
data(random_points, package = "RQGIS")
params$INPUT <- random_points
# Here I specify a SpatialPointsDataFrame as input, but one could also
# specify the path to a spatial object file (e.g., shapefile), e.g.;
# params$INPUT <- "random_points.shp"
params$OUTPUT <- "output.shp"
# Run the QGIS API and load its output into R
run_qgis(alg = "saga:addcoordinatestopoints",
         params = params,
         load_output = params$OUTPUT,
         qgis_env = my_env)
# }

Run the code above in your browser using DataLab