as_qgis_argument: Type coercion for arguments to QGIS processing algorithms

View source: R/qgis-arguments.R

as_qgis_argumentR Documentation

Type coercion for arguments to QGIS processing algorithms

Description

Calls to qgis_run_algorithm() can and should contain R objects that need to be serialized before they are passed to the command line. In some cases (e.g., sf objects), temporary files need to be written and cleaned up. The as_qgis_argument() and qgis_clean_argument() S3 generics provide hooks for argument values to be serialized correctly.

Usage

as_qgis_argument(x, spec = qgis_argument_spec(), use_json_input = FALSE)

qgis_clean_argument(value)

Arguments

x

An object passed to a QGIS processing algorithm

spec

A list() with values for algorithm, name, description, and qgis_type. See qgis_argument_spec() to create a blank spec for testing.

use_json_input

TRUE if the arguments will be serialized as JSON instead of serialized as a command-line argument.

value

The result of as_qgis_argument() after the QGIS processing algorithm has been run.

Value

The returned object class and form depends on the class and form of x and on the targeted qgis_type.

If x is a qgis_list_input or a qgis_dict_input object, the same class is returned but with as_qgis_argument() applied to each element.

In all other cases, the outcome can depend on the value of use_json_input and this also holds for the elements of qgis_list_input and qgis_dict_input objects:

  • if use_json_input = FALSE: a string.

  • if use_json_input = TRUE: various classes can be returned that will be correctly serialized as JSON.

Examples


qgisprocess::as_qgis_argument(
  c("a", "b"),
  spec = list(qgis_type = "range"),
  use_json_input = FALSE
)
qgisprocess::as_qgis_argument(
  c(1, 2),
  spec = list(qgis_type = "range"),
  use_json_input = FALSE
)
qgisprocess::as_qgis_argument(
  c("a", "b"),
  spec = list(qgis_type = "range"),
  use_json_input = TRUE
)
qgisprocess::as_qgis_argument(
  c(1, 2),
  spec = list(qgis_type = "range"),
  use_json_input = TRUE
)
mat <- matrix(1:12, ncol = 3)
mat
qgisprocess::as_qgis_argument(
  mat,
  spec = list(qgis_type = "matrix"),
  use_json_input = FALSE
)
qgisprocess::as_qgis_argument(
  mat,
  spec = list(qgis_type = "matrix"),
  use_json_input = TRUE
)


qgisprocess documentation built on Aug. 17, 2023, 5:14 p.m.