Title: | Use 'QGIS' Processing Algorithms |
---|---|
Description: | Provides seamless access to the 'QGIS' (<https://qgis.org>) processing toolbox using the standalone 'qgis_process' command-line utility. Both native and third-party (plugin) processing providers are supported. Beside referring data sources from file, also common objects from 'sf', 'terra' and 'stars' are supported. The native processing algorithms are documented by QGIS.org (2024) <https://docs.qgis.org/latest/en/docs/user_manual/processing_algs/>. |
Authors: | Dewey Dunnington [aut] (<https://orcid.org/0000-0002-9415-4582>, Voltron Data), Floris Vanderhaeghe [aut, cre] (<https://orcid.org/0000-0002-6378-6229>, Research Institute for Nature and Forest (INBO)), Jan Caha [aut] , Jannes Muenchow [aut] , Antony Barja [ctb] , Robin Lovelace [ctb] , Jakub Nowosad [ctb] , Research Institute for Nature and Forest (INBO) [cph, fnd] (https://www.inbo.be/en/) |
Maintainer: | Floris Vanderhaeghe <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.4.1.9000 |
Built: | 2024-12-06 05:42:44 UTC |
Source: | https://github.com/r-spatial/qgisprocess |
has_qgis()
checks whether the loaded qgisprocess cache is populated,
which means that a QGIS installation was accessible and responsive when
loading the package.
qgis_has_plugin()
, qgis_has_provider()
and qgis_has_algorithm()
check
for the availability of one or several plugins, processing providers and
algorithms, respectively.
They are vectorized.
has_qgis() qgis_has_plugin(plugin, query = FALSE, quiet = TRUE) qgis_has_provider(provider, query = FALSE, quiet = TRUE) qgis_has_algorithm(algorithm, query = FALSE, quiet = TRUE)
has_qgis() qgis_has_plugin(plugin, query = FALSE, quiet = TRUE) qgis_has_provider(provider, query = FALSE, quiet = TRUE) qgis_has_algorithm(algorithm, query = FALSE, quiet = TRUE)
plugin |
A plugin name (e.g., |
query |
Use |
quiet |
Use |
provider |
A provider name (e.g., |
algorithm |
A qualified algorithm name
(e.g., |
A logical, with length 1 in case of has_qgis()
.
Only plugins that implement processing providers are supported.
Other topics about reporting the QGIS state:
qgis_algorithms()
,
qgis_path()
,
qgis_using_json_input()
has_qgis() if (has_qgis()) qgis_has_algorithm("native:filedownloader") if (has_qgis()) qgis_has_provider("native") if (has_qgis()) qgis_has_plugin(c("grassprovider", "processing_saga_nextgen"))
has_qgis() if (has_qgis()) qgis_has_algorithm("native:filedownloader") if (has_qgis()) qgis_has_provider("native") if (has_qgis()) qgis_has_plugin(c("grassprovider", "processing_saga_nextgen"))
Functions that return metadata about the installed and enabled algorithms or processing providers, or about the installed plugins that implement processing providers. See the QGIS docs for a detailed description of the algorithms provided 'out of the box' on QGIS.
qgis_algorithms(query = FALSE, quiet = TRUE, include_deprecated = TRUE) qgis_providers(query = FALSE, quiet = TRUE, include_deprecated = TRUE) qgis_plugins(which = "all", query = FALSE, quiet = TRUE, ...)
qgis_algorithms(query = FALSE, quiet = TRUE, include_deprecated = TRUE) qgis_providers(query = FALSE, quiet = TRUE, include_deprecated = TRUE) qgis_plugins(which = "all", query = FALSE, quiet = TRUE, ...)
query |
Use |
quiet |
Use |
include_deprecated |
Logical. Should deprecated algorithms be included? |
which |
String defining which plugins to select, based on their
status in QGIS (enabled or disabled).
Must be one of: |
... |
Only used by other functions calling this function. |
The include_deprecated
argument in qgis_algorithms()
does not affect the
cached value. The latter always includes deprecated algorithms if these are
returned by 'qgis_process' (this requires the JSON output method).
A tibble of algorithms, processing providers or plugins, with metadata.
qgis_enable_plugins()
, qgis_disable_plugins()
Other topics about information on algorithms & processing providers:
qgis_search_algorithms()
,
qgis_show_help()
Other topics about reporting the QGIS state:
has_qgis()
,
qgis_path()
,
qgis_using_json_input()
qgis_algorithms() qgis_algorithms(include_deprecated = FALSE) qgis_providers() qgis_plugins(quiet = FALSE) qgis_plugins(which = "disabled")
qgis_algorithms() qgis_algorithms(include_deprecated = FALSE) qgis_providers() qgis_plugins(quiet = FALSE) qgis_plugins(which = "disabled")
Convert a qgis_result object or one of its elements to a raster object
qgis_as_raster(x, ...) qgis_as_brick(x, ...) ## S3 method for class 'qgis_outputRaster' qgis_as_raster(x, ...) ## S3 method for class 'qgis_outputRaster' qgis_as_brick(x, ...) ## S3 method for class 'qgis_outputLayer' qgis_as_raster(x, ...) ## S3 method for class 'qgis_outputLayer' qgis_as_brick(x, ...) ## S3 method for class 'qgis_result' qgis_as_raster(x, ...) ## S3 method for class 'qgis_result' qgis_as_brick(x, ...)
qgis_as_raster(x, ...) qgis_as_brick(x, ...) ## S3 method for class 'qgis_outputRaster' qgis_as_raster(x, ...) ## S3 method for class 'qgis_outputRaster' qgis_as_brick(x, ...) ## S3 method for class 'qgis_outputLayer' qgis_as_raster(x, ...) ## S3 method for class 'qgis_outputLayer' qgis_as_brick(x, ...) ## S3 method for class 'qgis_result' qgis_as_raster(x, ...) ## S3 method for class 'qgis_result' qgis_as_brick(x, ...)
x |
A |
... |
Arguments passed to |
A RasterLayer
or a RasterBrick
object.
Other topics about coercing processing output:
qgis_as_terra()
,
st_as_sf
,
st_as_stars
Other topics about accessing or managing processing results:
qgis_as_terra()
,
qgis_clean_result()
,
qgis_extract_output()
,
qgis_result_status()
,
st_as_sf
,
st_as_stars
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:slope", INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess") ) # most direct approach, autoselecting a `qgis_outputRaster` type # output from the `result` object and reading as RasterLayer: qgis_as_raster(result) # if you need more control, extract the needed output element first: output_raster <- qgis_extract_output(result, "OUTPUT") qgis_as_raster(output_raster)
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:slope", INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess") ) # most direct approach, autoselecting a `qgis_outputRaster` type # output from the `result` object and reading as RasterLayer: qgis_as_raster(result) # if you need more control, extract the needed output element first: output_raster <- qgis_extract_output(result, "OUTPUT") qgis_as_raster(output_raster)
This function performs coercion to one of the terra classes
SpatRaster
, SpatVector
or SpatVectorProxy
(add proxy = TRUE
for the
latter).
The distinction between SpatRaster
and SpatVector
is based on the
output type.
qgis_as_terra(x, ...) ## S3 method for class 'qgis_outputRaster' qgis_as_terra(x, ...) ## S3 method for class 'qgis_outputLayer' qgis_as_terra(x, ...) ## S3 method for class 'qgis_outputVector' qgis_as_terra(x, ...) ## S3 method for class 'qgis_result' qgis_as_terra(x, ...)
qgis_as_terra(x, ...) ## S3 method for class 'qgis_outputRaster' qgis_as_terra(x, ...) ## S3 method for class 'qgis_outputLayer' qgis_as_terra(x, ...) ## S3 method for class 'qgis_outputVector' qgis_as_terra(x, ...) ## S3 method for class 'qgis_result' qgis_as_terra(x, ...)
x |
A |
... |
Arguments passed to |
A SpatRaster
, SpatVector
or SpatVectorProxy
object.
Other topics about coercing processing output:
qgis_as_raster()
,
st_as_sf
,
st_as_stars
Other topics about accessing or managing processing results:
qgis_as_raster()
,
qgis_clean_result()
,
qgis_extract_output()
,
qgis_result_status()
,
st_as_sf
,
st_as_stars
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:slope", INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess") ) # most direct approach, autoselecting a `qgis_outputRaster` type # output from the `result` object and reading as SpatRaster: qgis_as_terra(result) # if you need more control, extract the needed output element first: output_raster <- qgis_extract_output(result, "OUTPUT") qgis_as_terra(output_raster) # Same holds for coercion to SpatVector result2 <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake.gpkg", package = "qgisprocess"), DISTANCE = 100 ) qgis_as_terra(result2) output_vector <- qgis_extract_output(result2, "OUTPUT") qgis_as_terra(output_vector) # SpatVectorProxy: qgis_as_terra(result2, proxy = TRUE)
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:slope", INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess") ) # most direct approach, autoselecting a `qgis_outputRaster` type # output from the `result` object and reading as SpatRaster: qgis_as_terra(result) # if you need more control, extract the needed output element first: output_raster <- qgis_extract_output(result, "OUTPUT") qgis_as_terra(output_raster) # Same holds for coercion to SpatVector result2 <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake.gpkg", package = "qgisprocess"), DISTANCE = 100 ) qgis_as_terra(result2) output_vector <- qgis_extract_output(result2, "OUTPUT") qgis_as_terra(output_vector) # SpatVectorProxy: qgis_as_terra(result2, proxy = TRUE)
Deletes any temporary files that are defined in a
qgis_result
object.
These may comprise both input and output files.
qgis_clean_result(x)
qgis_clean_result(x)
x |
A |
The qgis_result
object passed to the function is returned
invisibly.
Other topics about accessing or managing processing results:
qgis_as_raster()
,
qgis_as_terra()
,
qgis_extract_output()
,
qgis_result_status()
,
st_as_sf
,
st_as_stars
result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) file.exists(qgis_extract_output(result)) qgis_clean_result(result) file.exists(qgis_extract_output(result))
result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) file.exists(qgis_extract_output(result)) qgis_clean_result(result) file.exists(qgis_extract_output(result))
Run qgis_configure()
to bring the package configuration in line with
QGIS and to save this configuration to a persistent cache.
See the Details section for more information about setting the path of
the 'qgis_process' command line tool.
qgis_configure(quiet = FALSE, use_cached_data = FALSE)
qgis_configure(quiet = FALSE, use_cached_data = FALSE)
quiet |
Use |
use_cached_data |
Use the cached algorithm list and |
The qgisprocess package is a wrapper around the 'qgis_process' command line tool distributed with QGIS (>=3.14). Several functions use heuristics to detect the location of the 'qgis_process' executable.
When loading the package, the configuration is automatically read from the
cache with qgis_configure(use_cached_data = TRUE, quiet = TRUE)
in order
to save time.
Run qgis_configure(use_cached_data = TRUE)
manually to get more details.
Use qgis_algorithms()
, qgis_providers()
, qgis_plugins()
,
qgis_using_json_output()
, qgis_path()
and qgis_version()
to inspect cache
contents.
If the configuration
fails or you have more than one QGIS installation, you can set
options(qgisprocess.path = "path/to/qgis_process")
or the
R_QGISPROCESS_PATH
environment variable (useful on CI). On Linux the
'qgis_process' executable is generally available on the user's PATH,
on MacOS the executable is within the QGIS*.app/Contents/MacOS/bin folder,
and on Windows the executable is named qgis_process-qgis.bat or
qgis_process-qgis-dev.bat and is located in Program Files/QGIS*/bin or
OSGeo4W(64)/bin.
The result of processx::run()
.
Other topics about configuring QGIS and qgisprocess:
qgis_enable_plugins()
,
qgis_run()
# not running in R CMD check to save time qgis_configure(use_cached_data = TRUE) ## Not run: # package reconfiguration # (not run in example() as it rewrites the package cache file) qgis_configure() ## End(Not run)
# not running in R CMD check to save time qgis_configure(use_cached_data = TRUE) ## Not run: # package reconfiguration # (not run in example() as it rewrites the package cache file) qgis_configure() ## End(Not run)
Discovers existing 'qgis_process' executables on the system and returns their
filepath.
Only available for Windows and macOS systems.
qgis_detect_paths()
is a shortcut to qgis_detect_windows_paths()
on
Windows and qgis_detect_macos_paths()
on macOS.
qgis_detect_paths(drive_letter = strsplit(R.home(), ":")[[1]][1]) qgis_detect_windows_paths(drive_letter = strsplit(R.home(), ":")[[1]][1]) qgis_detect_macos_paths()
qgis_detect_paths(drive_letter = strsplit(R.home(), ":")[[1]][1]) qgis_detect_windows_paths(drive_letter = strsplit(R.home(), ":")[[1]][1]) qgis_detect_macos_paths()
drive_letter |
The drive letter on which to search. By default, this is the same drive letter as the R executable. Only applicable to Windows. |
A character vector of possible paths to the 'qgis_process' executable.
These functions do not verify whether the discovered 'qgis_process'
executables successfully run.
You can run qgis_path(query = TRUE, quiet = FALSE)
to discover and cache
the first 'qgis_process' in the list that works.
if (.Platform$OS.type == "windows") { qgis_detect_paths() identical(qgis_detect_windows_paths(), qgis_detect_paths()) } if (Sys.info()["sysname"] == "Darwin") { qgis_detect_paths() identical(qgis_detect_macos_paths(), qgis_detect_paths()) }
if (.Platform$OS.type == "windows") { qgis_detect_paths() identical(qgis_detect_windows_paths(), qgis_detect_paths()) } if (Sys.info()["sysname"] == "Darwin") { qgis_detect_paths() identical(qgis_detect_macos_paths(), qgis_detect_paths()) }
Processing plugins, installed in QGIS, can be in an 'enabled' or 'disabled'
state in QGIS.
The plugin state can be controlled from R.
qgis_enable_plugins()
enables plugins while qgis_disable_plugins()
does the reverse.
qgis_enable_plugins(names = NULL, quiet = FALSE) qgis_disable_plugins(names = NULL, quiet = FALSE)
qgis_enable_plugins(names = NULL, quiet = FALSE) qgis_disable_plugins(names = NULL, quiet = FALSE)
names |
Optional character vector of plugin names. |
quiet |
Use |
The cache is immediately updated upon enabling or disabling plugins from R.
Run qgis_plugins()
to list the available plugins that implement processing
providers.
If you installed, removed, enabled or disabled plugins in the QGIS GUI, then
run qgis_configure()
to make those changes available in R.
If names
is not provided to qgis_enable_plugins()
, it is assumed that all
disabled plugins are to be enabled.
If names
is not provided to qgis_disable_plugins()
, it is assumed that all
enabled plugins are to be disabled.
Note that the 'processing' plugin is ignored, because it is always available
to 'qgis_process' (not QGIS though).
A tibble of plugins, invisibly.
Only plugins that implement processing providers are supported. Installing or removing plugins is not supported.
Other topics about configuring QGIS and qgisprocess:
qgis_configure()
,
qgis_run()
qgis_enable_plugins("name_of_plugin")
qgis_enable_plugins("name_of_plugin")
These functions extract one output element from the result of
qgis_run_algorithm()
, potentially more than one in the case of
qgis_extract_output_by_class()
.
An output element can be extracted based on its name, its position in the
printed qgis_result
object returned by qgis_run_algorithm()
, or its
class.
qgis_extract_output()
is an alias to qgis_extract_output_by_name()
.
qgis_extract_output_by_name(x, name = "OUTPUT", first = TRUE) qgis_extract_output(x, name = "OUTPUT", first = TRUE) qgis_extract_output_by_position(x, which) qgis_extract_output_by_class(x, class, single = TRUE)
qgis_extract_output_by_name(x, name = "OUTPUT", first = TRUE) qgis_extract_output(x, name = "OUTPUT", first = TRUE) qgis_extract_output_by_position(x, which) qgis_extract_output_by_class(x, class, single = TRUE)
x |
A |
name |
The name of an output. |
first |
Logical.
Should |
which |
The index of an output. |
class |
Character vector of classes.
At least one class must be inherited by an element of |
single |
Logical.
Ensures the selection of a single output in |
A qgis_output*
object.
Other topics about accessing or managing processing results:
qgis_as_raster()
,
qgis_as_terra()
,
qgis_clean_result()
,
qgis_result_status()
,
st_as_sf
,
st_as_stars
result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) # the print() method of a qgis_result only prints its output elements: result # nevertheless, more elements are included: length(result) names(result) # extract the output element 'OUTPUT': qgis_extract_output(result)
result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) # the print() method of a qgis_result only prints its output elements: result # nevertheless, more elements are included: length(result) names(result) # extract the output element 'OUTPUT': qgis_extract_output(result)
As opposed to qgis_run_algorithm()
, qgis_function()
creates a callable
function based on the argument metadata provided by qgis_get_argument_specs()
.
qgis_function(algorithm, ...)
qgis_function(algorithm, ...)
algorithm |
A qualified algorithm name
(e.g., |
... |
Algorithm arguments.
These values are evaluated once and immediately, so you shouldn't
call |
The logic of qgis_function()
has been implemented in R package
qgis.
This package also provides the QGIS documentation of each processing
algorithm as corresponding R function documentation.
A function.
qgis_buffer <- qgis_function("native:buffer") qgis_buffer( system.file( "longlake/longlake_depth.gpkg", package = "qgisprocess" ), DISTANCE = 10 )
qgis_buffer <- qgis_function("native:buffer") qgis_buffer( system.file( "longlake/longlake_depth.gpkg", package = "qgisprocess" ), DISTANCE = 10 )
Some algorithm arguments require a compound object, consisting of several layers or elements. These functions apply strict validation rules when generating this object and are recommended.
qgis_list_input(...) qgis_dict_input(...)
qgis_list_input(...) qgis_dict_input(...)
... |
Named values for |
qgis_list_input()
generates an unnamed list of class qgis_list_input
.
The use of qgis_list_input()
instead of list() is required for compound
arguments in case of no-JSON input (see qgis_using_json_input()
).
Since it applies strict validation rules, it is recommended in all cases
though.
qgis_dict_input()
generates a named list of class qgis_dict_input
.
qgis_dict_input()
is only supported when the JSON input method applies
(see qgis_using_json_input()
), where it can be interchanged with a named list()
.
It can only be used for arguments requiring named lists.
Since it applies strict validation rules, it is recommended above list()
.
Some QGIS argument types that need a compount object are the multilayer
,
aggregates
, fields_mapping
, tininputlayers
and
vectortilewriterlayers
argument types.
qgis_list_input()
: An object of class 'qgis_list_input'
qgis_dict_input()
: An object of class 'qgis_dict_input'
qgis_list_input(1, 2, 3) qgis_dict_input(a = 1, b = 2, c = 3)
qgis_list_input(1, 2, 3) qgis_dict_input(a = 1, b = 2, c = 3)
qgis_path()
returns the filepath of the 'qgis_process' command, while
qgis_version()
returns the QGIS version.
qgis_path(query = FALSE, quiet = TRUE) qgis_version(query = FALSE, quiet = TRUE, full = TRUE, debug = FALSE)
qgis_path(query = FALSE, quiet = TRUE) qgis_version(query = FALSE, quiet = TRUE, full = TRUE, debug = FALSE)
query |
Use |
quiet |
Use |
full |
Logical.
If |
debug |
Logical.
If |
A string.
Other topics about reporting the QGIS state:
has_qgis()
,
qgis_algorithms()
,
qgis_using_json_input()
qgis_path() qgis_path(quiet = FALSE) qgis_version() qgis_version(full = FALSE) qgis_version(debug = TRUE)
qgis_path() qgis_path(quiet = FALSE) qgis_version() qgis_version(full = FALSE) qgis_version(debug = TRUE)
A qgis_result
object is a list that, next to the output elements,
also contains other elements that can be useful in scripting.
Several of these can be extracted with convenience functions:
the exit status of the process, standard output and standard error of
'qgis_process', arguments passed to 'qgis_process'.
qgis_result_status(x) qgis_result_stdout(x) qgis_result_stderr(x) qgis_result_args(x)
qgis_result_status(x) qgis_result_stdout(x) qgis_result_stderr(x) qgis_result_args(x)
x |
A |
A number in case of qgis_result_status()
.
A string in case of qgis_result_stdout()
and qgis_result_stderr()
.
A list in case of qgis_result_args()
.
Other topics about programming or debugging utilities:
qgis_run()
,
qgis_tmp_file()
,
qgis_unconfigure()
,
qgis_using_json_input()
Other topics about accessing or managing processing results:
qgis_as_raster()
,
qgis_as_terra()
,
qgis_clean_result()
,
qgis_extract_output()
,
st_as_sf
,
st_as_stars
result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) qgis_result_status(result) stdout <- qgis_result_stdout(result) cat(substr(stdout, 1, 335)) qgis_result_stderr(result) qgis_result_args(result)
result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) qgis_result_status(result) stdout <- qgis_result_stdout(result) cat(substr(stdout, 1, 335)) qgis_result_stderr(result) qgis_result_args(result)
qgis_run()
offers full access to 'qgis_process'.
Run cat(qgis_run("--help")$stdout)
to get the command's help.
qgis_run(args = character(), ..., env = qgis_env(), path = qgis_path())
qgis_run(args = character(), ..., env = qgis_env(), path = qgis_path())
args |
Command-line arguments |
... |
Passed to |
env |
A |
path |
A path to the 'qgis_process' executable. Defaults to
|
A processx::run()
return value, i.e. a list with status
, stdout
,
stderr
and timeout
elements.
Other topics about programming or debugging utilities:
qgis_result_status()
,
qgis_tmp_file()
,
qgis_unconfigure()
,
qgis_using_json_input()
Other topics about configuring QGIS and qgisprocess:
qgis_configure()
,
qgis_enable_plugins()
processx_list <- qgis_run(args = "--help") cat(processx_list$stdout)
processx_list <- qgis_run(args = "--help") cat(processx_list$stdout)
Runs an algorithm using 'qgis_process'. See the QGIS docs for a detailed description of the algorithms provided 'out of the box' on QGIS.
qgis_run_algorithm( algorithm, ..., PROJECT_PATH = NULL, ELLIPSOID = NULL, .raw_json_input = NULL, .quiet = TRUE )
qgis_run_algorithm( algorithm, ..., PROJECT_PATH = NULL, ELLIPSOID = NULL, .raw_json_input = NULL, .quiet = TRUE )
algorithm |
A qualified algorithm name (e.g., |
... |
Named key-value pairs as arguments for the algorithm. Features of
|
PROJECT_PATH , ELLIPSOID
|
Global values for QGIS project file and ellipsoid name for distance calculations. |
.raw_json_input |
The raw JSON to use as input in place of |
.quiet |
Use |
qgis_run_algorithm()
accepts various R objects as algorithm arguments.
An overview is given by vignette("qgis_arguments")
.
Examples include an R matrix or data frame for the
argument type 'matrix', R colors for the argument type 'color',
sf or terra (SpatVector) objects for the argument type 'vector' and
raster/terra/stars objects for the argument type 'raster', but there are many
more.
qgis_run_algorithm()
preprocesses the provided objects into the format that
QGIS expects for a given argument.
Providing R objects that cannot be converted to the applicable argument type will lead to an error.
Algorithm arguments can be passed as arguments of qgis_run_algorithm()
, but
they can also be combined as a JSON string and fed into the .raw_json_input
argument.
A JSON string can be obtained from the QGIS GUI, either from the
processing tool dialog or from the processing history dialog, by selecting
'Copy as JSON' in the 'Advanced' dropdown menu.
So a user can first try out a geoprocessing step in the QGIS GUI, and
once the chosen algorithm arguments are satisfactory, copy the JSON string
to reproduce the operation in R.
A screenshot is available at the package homepage.
A qgis_result
object.
QGIS models and Python scripts can be added to the Processing Toolbox in the
QGIS GUI, by pointing at their corresponding file.
This will put the model or script below the provider 'Models' or
'Scripts', respectively.
Next, it is necessary to run qgis_configure()
in R in order to make the
model or script available to qgisprocess (even reloading the package won't
detect it, since these providers have dynamic content, not tied to a
plugin or to a QGIS version).
You can check the outcome with qgis_providers()
and
qgis_search_algorithms()
.
Now, just as with other algorithms, you can provide the model:<name>
or
script:<name>
identifier to the algorithm
argument of
qgis_run_algorithm()
.
As the output argument name of a QGIS model can have an R-unfriendly
syntax, you may need to take the JSON parameter string from the QGIS
processing dialog and feed the JSON string to the .raw_json_input
argument
of qgis_run_algorithm()
instead of providing separate arguments.
Although the 'qgis_process' backend also supports replacing the 'algorithm' parameter by the file path of a model file or a Python script, it is not planned to implement this in qgisprocess, as it would bypass argument preprocessing in R (including checks).
vignette("qgis_arguments")
Other functions to run one geoprocessing algorithm:
qgis_run_algorithm_p()
qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 )
qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 )
qgis_run_algorithm_p()
wraps qgis_run_algorithm()
, passing
its first argument to the first argument of the QGIS algorithm
.
This makes it more convenient in a pipeline (hence '_p' in the name).
qgis_run_algorithm_p( .data, algorithm, ..., .select = "OUTPUT", .clean = TRUE, .quiet = TRUE )
qgis_run_algorithm_p( .data, algorithm, ..., .select = "OUTPUT", .clean = TRUE, .quiet = TRUE )
.data |
Passed to the first input of |
algorithm |
A qualified algorithm name
(e.g., |
... |
Other algorithm arguments.
These values are evaluated once and immediately, so you shouldn't
call |
.select |
String.
The name of the element to select from |
.clean |
Logical.
Should an incoming |
.quiet |
Use |
Uses qgis_function()
under the hood.
A qgis_result
object.
Other functions to run one geoprocessing algorithm:
qgis_run_algorithm()
system.file( "longlake/longlake_depth.gpkg", package = "qgisprocess" ) |> qgis_run_algorithm_p( "native:buffer", DISTANCE = 10 )
system.file( "longlake/longlake_depth.gpkg", package = "qgisprocess" ) |> qgis_run_algorithm_p( "native:buffer", DISTANCE = 10 )
Searches for algorithms using a regular expression. In its simplest form that is just a string that must match part of a character value.
qgis_search_algorithms( algorithm = NULL, provider = NULL, group = NULL, include_deprecated = FALSE )
qgis_search_algorithms( algorithm = NULL, provider = NULL, group = NULL, include_deprecated = FALSE )
algorithm |
Regular expression to match the |
provider |
Regular expression to match the |
group |
Regular expression to match the |
include_deprecated |
Logical. Should deprecated algorithms be included? |
When using multiple arguments in combination, only the algorithms are returned that fulfill all conditions.
All regular expressions that stringr::str_detect()
can handle, are
accepted.
Have a look at stringi::search_regex()
to get a nice overview.
A tibble.
Other topics about information on algorithms & processing providers:
qgis_algorithms()
,
qgis_show_help()
qgis_search_algorithms( algorithm = "point.*line", provider = "^native$" )
qgis_search_algorithms( algorithm = "point.*line", provider = "^native$" )
Get detailed information about one algorithm
qgis_show_help(algorithm) qgis_get_description(algorithm) qgis_get_argument_specs(algorithm, ...) qgis_get_output_specs(algorithm, ...)
qgis_show_help(algorithm) qgis_get_description(algorithm) qgis_get_argument_specs(algorithm, ...) qgis_get_output_specs(algorithm, ...)
algorithm |
A qualified algorithm name
(e.g., |
... |
For internal use only. |
qgis_get_description()
: a string.
qgis_get_argument_specs()
, qgis_get_output_specs()
: a tibble.
qgis_show_help()
: the algorithm name, invisibly.
Other topics about information on algorithms & processing providers:
qgis_algorithms()
,
qgis_search_algorithms()
qgis_get_description("native:filedownloader") # not running below examples in R CMD check to save time qgis_get_argument_specs("native:filedownloader") qgis_get_output_specs("native:filedownloader") qgis_show_help("native:filedownloader")
qgis_get_description("native:filedownloader") # not running below examples in R CMD check to save time qgis_get_argument_specs("native:filedownloader") qgis_get_output_specs("native:filedownloader") qgis_show_help("native:filedownloader")
These functions create temporary files that can be used
in calls to qgis_run_algorithm()
or elsewhere. These
files are created in a special temporary directory
(qgis_tmp_base()
) that should be periodically cleaned up
using qgis_clean_tmp()
. You can set your preferred
vector and/or raster file extension using
options(qgisprocess.tmp_vector_ext = "...")
and/or
options(qgisprocess.tmp_raster_ext = "...")
, respectively.
qgis_tmp_file(ext) qgis_tmp_folder() qgis_tmp_vector(ext = getOption("qgisprocess.tmp_vector_ext", ".gpkg")) qgis_tmp_raster(ext = getOption("qgisprocess.tmp_raster_ext", ".tif")) qgis_tmp_base() qgis_clean_tmp()
qgis_tmp_file(ext) qgis_tmp_folder() qgis_tmp_vector(ext = getOption("qgisprocess.tmp_vector_ext", ".gpkg")) qgis_tmp_raster(ext = getOption("qgisprocess.tmp_raster_ext", ".tif")) qgis_tmp_base() qgis_clean_tmp()
ext |
The file extension to be used. |
A character vector indicating the location of a (not yet created) temporary file.
Other topics about programming or debugging utilities:
qgis_result_status()
,
qgis_run()
,
qgis_unconfigure()
,
qgis_using_json_input()
qgis_tmp_base() qgis_tmp_file(".csv") qgis_tmp_vector() qgis_tmp_raster()
qgis_tmp_base() qgis_tmp_file(".csv") qgis_tmp_vector() qgis_tmp_raster()
Empties the qgisprocess cache environment.
qgis_unconfigure()
qgis_unconfigure()
NULL
, invisibly.
Other topics about programming or debugging utilities:
qgis_result_status()
,
qgis_run()
,
qgis_tmp_file()
,
qgis_using_json_input()
## Not run: # not running this function in example() as it clears the cache environment. qgis_unconfigure() ## End(Not run) # undoing qgis_unconfigure() by repopulating the cache environment from file: # not running in R CMD check to save time qgis_configure(use_cached_data = TRUE)
## Not run: # not running this function in example() as it clears the cache environment. qgis_unconfigure() ## End(Not run) # undoing qgis_unconfigure() by repopulating the cache environment from file: # not running in R CMD check to save time qgis_configure(use_cached_data = TRUE)
Returns a logical that reveals whether the JSON input and output methods are used, respectively.
qgis_using_json_input() qgis_using_json_output(query = FALSE, quiet = TRUE)
qgis_using_json_input() qgis_using_json_output(query = FALSE, quiet = TRUE)
query |
Logical.
Should the outcome of
|
quiet |
Use |
Since QGIS 3.24 the JSON input method of 'qgis_process' is used by default
when calling the command.
It allows to use certain algorithms that
require a more complex input argument, e.g. a list of lists (see
qgis_list_input()
).
Likewise, JSON output is the default output format requested from 'qgis_process'. Using the JSON input method of 'qgis_process' automatically implies using the JSON output method; when not using the JSON input method it is possible (but not the default) to also not use the JSON output method.
The defaults can be overruled with the options
qgisprocess.use_json_input
or qgisprocess.use_json_output
, and with the
environment variables R_QGISPROCESS_USE_JSON_INPUT
or
R_QGISPROCESS_USE_JSON_OUTPUT
.
The returned JSON output method is always
cached during the current session by qgis_using_json_output()
.
Given that qgis_using_json_output()
is called by various functions
in the package, having a user setting 'use_json_output' in place (see above)
will have effect during subsequent usage of the package.
To cache the value between sessions, qgis_configure()
needs to be called
to update the value stored in the persistent package cache file.
The JSON input method is not cached but simply determined on the fly, based on QGIS version, the JSON output method and the user setting if present.
There is good reason for having 'use_json_output' in the persistent package
cache: the values of qgis_algorithms()
and qgis_plugins()
are different
with or without the JSON output method, and are also stored in the cache.
A logical of length 1.
Other topics about programming or debugging utilities:
qgis_result_status()
,
qgis_run()
,
qgis_tmp_file()
,
qgis_unconfigure()
Other topics about reporting the QGIS state:
has_qgis()
,
qgis_algorithms()
,
qgis_path()
qgis_using_json_input() qgis_using_json_output()
qgis_using_json_input() qgis_using_json_output()
Convert a qgis_result object or one of its elements to an sf object
## S3 method for class 'qgis_result' st_as_sf(x, ...) ## S3 method for class 'qgis_outputVector' st_as_sf(x, ...) ## S3 method for class 'qgis_outputLayer' st_as_sf(x, ...)
## S3 method for class 'qgis_result' st_as_sf(x, ...) ## S3 method for class 'qgis_outputVector' st_as_sf(x, ...) ## S3 method for class 'qgis_outputLayer' st_as_sf(x, ...)
x |
A |
... |
Arguments passed to |
The sf package must be loaded explicitly to use these methods.
An sf
object.
Other topics about coercing processing output:
qgis_as_raster()
,
qgis_as_terra()
,
st_as_stars
Other topics about accessing or managing processing results:
qgis_as_raster()
,
qgis_as_terra()
,
qgis_clean_result()
,
qgis_extract_output()
,
qgis_result_status()
,
st_as_stars
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) # most direct approach, autoselecting a `qgis_outputVector` type # output from the `result` object and reading as sf object: sf::st_as_sf(result) # if you need more control, extract the needed output element first: output_vector <- qgis_extract_output(result, "OUTPUT") sf::st_as_sf(output_vector)
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:buffer", INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"), DISTANCE = 10 ) # most direct approach, autoselecting a `qgis_outputVector` type # output from the `result` object and reading as sf object: sf::st_as_sf(result) # if you need more control, extract the needed output element first: output_vector <- qgis_extract_output(result, "OUTPUT") sf::st_as_sf(output_vector)
Convert a qgis_result object or one of its elements to a stars object
## S3 method for class 'qgis_outputRaster' st_as_stars(x, ...) ## S3 method for class 'qgis_outputLayer' st_as_stars(x, ...) ## S3 method for class 'qgis_result' st_as_stars(x, ...)
## S3 method for class 'qgis_outputRaster' st_as_stars(x, ...) ## S3 method for class 'qgis_outputLayer' st_as_stars(x, ...) ## S3 method for class 'qgis_result' st_as_stars(x, ...)
x |
A |
... |
Arguments passed to |
The stars package must be loaded explicitly to use these methods.
A stars
or a stars_proxy
object.
Other topics about coercing processing output:
qgis_as_raster()
,
qgis_as_terra()
,
st_as_sf
Other topics about accessing or managing processing results:
qgis_as_raster()
,
qgis_as_terra()
,
qgis_clean_result()
,
qgis_extract_output()
,
qgis_result_status()
,
st_as_sf
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:slope", INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess") ) # most direct approach, autoselecting a `qgis_outputRaster` type # output from the `result` object and reading as stars or stars_proxy: stars::st_as_stars(result) stars::st_as_stars(result, proxy = TRUE) # if you need more control, extract the needed output element first: output_raster <- qgis_extract_output(result, "OUTPUT") stars::st_as_stars(output_raster)
# not running below examples in R CMD check to save time result <- qgis_run_algorithm( "native:slope", INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess") ) # most direct approach, autoselecting a `qgis_outputRaster` type # output from the `result` object and reading as stars or stars_proxy: stars::st_as_stars(result) stars::st_as_stars(result, proxy = TRUE) # if you need more control, extract the needed output element first: output_raster <- qgis_extract_output(result, "OUTPUT") stars::st_as_stars(output_raster)