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().
Usage
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)Arguments
- x
A
qgis_resultobject returned byqgis_run_algorithm().- name
The name of an output.
- first
Logical. Should
qgis_extract_output_by_name()fall back to the first output element if the defaultOUTPUToroutputelement is not available? Only takes effect ifnameis equal toOUTPUToroutput, but not found.- which
The index of an output.
- class
Character vector of classes. At least one class must be inherited by an element of
xfor that element to be selected.- single
Logical. Ensures the selection of a single output in
qgis_extract_output_by_class(). TheOUTPUToroutputelement is taken if available and on condition that it inherits a specified class; otherwise falls back to the first element that inherits a specified class.
See also
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
Examples
result <- qgis_run_algorithm(
"native:buffer",
INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"),
DISTANCE = 10
)
#> 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).
#> Argument `DISSOLVE` is unspecified (using QGIS default value).
#> Argument `SEPARATE_DISJOINT` is unspecified (using QGIS default value).
#> Using `OUTPUT = qgis_tmp_vector()`
# the print() method of a qgis_result only prints its output elements:
result
#> <Result of `qgis_run_algorithm("native:buffer", ...)`>
#> List of 1
#> $ OUTPUT: 'qgis_outputVector' chr "/tmp/RtmpYRKnrl/file2bd74c64ebaa/file2bd78acea80.gpkg"
# nevertheless, more elements are included:
length(result)
#> [1] 5
names(result)
#> [1] "OUTPUT" ".algorithm" ".args" ".raw_json_input"
#> [5] ".processx_result"
# extract the output element 'OUTPUT':
qgis_extract_output(result)
#> [1] "/tmp/RtmpYRKnrl/file2bd74c64ebaa/file2bd78acea80.gpkg"
#> attr(,"class")
#> [1] "qgis_outputVector"