qgis_as_terra {qgisprocess}R Documentation

Convert a qgis_result object or one of its elements to a terra object

Description

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.

Usage

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, ...)

Arguments

x

A qgis_result object from qgis_run_algorithm() or a ⁠qgis_output*⁠ object from one of the qgis_extract_output() functions.

...

Arguments passed to terra::rast() or terra::vect(), depending on the output type of x (or one of its elements, if x is a qgis_result).

Value

A SpatRaster, SpatVector or SpatVectorProxy object.

See Also

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

Examples



# 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)



[Package qgisprocess version 0.3.0 Index]