Learn R Programming

RQGIS (version 0.1.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, 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 that you 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.
load_output
Character vector containing paths to (an) output file(s) 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 otherwiese 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 QGIS via Python (QGIS API) using 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 you 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)
# ## End(Not run)

Run the code above in your browser using DataLab