Convert a qgis_result object or one of its elements to a terra object
Source:R/compat-terra.R
qgis_as_terra.Rd
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 fromqgis_run_algorithm()
or aqgis_output*
object from one of theqgis_extract_output()
functions.- ...
Arguments passed to
terra::rast()
orterra::vect()
, depending on the output type ofx
(or one of its elements, ifx
is aqgis_result
).
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
# \donttest{
# 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")
)
#> Argument `Z_FACTOR` is unspecified (using QGIS default value).
#> Using `OUTPUT = qgis_tmp_raster()`
# most direct approach, autoselecting a `qgis_outputRaster` type
# output from the `result` object and reading as SpatRaster:
qgis_as_terra(result)
#> class : SpatRaster
#> dimensions : 100, 100, 1 (nrow, ncol, nlyr)
#> resolution : 18.27273, 15.53535 (x, y)
#> extent : 409939.9, 411767.1, 5083307, 5084861 (xmin, xmax, ymin, ymax)
#> coord. ref. : NAD83 / UTM zone 20N (EPSG:26920)
#> source : file2b044ec5ffea.tif
#> name : file2b044ec5ffea
# if you need more control, extract the needed output element first:
output_raster <- qgis_extract_output(result, "OUTPUT")
qgis_as_terra(output_raster)
#> class : SpatRaster
#> dimensions : 100, 100, 1 (nrow, ncol, nlyr)
#> resolution : 18.27273, 15.53535 (x, y)
#> extent : 409939.9, 411767.1, 5083307, 5084861 (xmin, xmax, ymin, ymax)
#> coord. ref. : NAD83 / UTM zone 20N (EPSG:26920)
#> source : file2b044ec5ffea.tif
#> name : file2b044ec5ffea
# Same holds for coercion to SpatVector
result2 <- qgis_run_algorithm(
"native:buffer",
INPUT = system.file("longlake/longlake.gpkg", package = "qgisprocess"),
DISTANCE = 100
)
#> 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()`
qgis_as_terra(result2)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 1, 1 (geometries, attributes)
#> extent : 409850.6, 411856.3, 5083216, 5084951 (xmin, xmax, ymin, ymax)
#> source : file2b044b33769b.gpkg
#> coord. ref. : NAD83 / UTM zone 20N (EPSG:26920)
#> names : label
#> type : <chr>
#> values : Long Lake
output_vector <- qgis_extract_output(result2, "OUTPUT")
qgis_as_terra(output_vector)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 1, 1 (geometries, attributes)
#> extent : 409850.6, 411856.3, 5083216, 5084951 (xmin, xmax, ymin, ymax)
#> source : file2b044b33769b.gpkg
#> coord. ref. : NAD83 / UTM zone 20N (EPSG:26920)
#> names : label
#> type : <chr>
#> values : Long Lake
# SpatVectorProxy:
qgis_as_terra(result2, proxy = TRUE)
#> class : SpatVectorProxy
#> geometry : polygons
#> dimensions : 1, 1 (geometries, attributes)
#> extent : 409850.6, 411856.3, 5083216, 5084951 (xmin, xmax, ymin, ymax)
#> source : file2b044b33769b.gpkg
#> coord. ref. : NAD83 / UTM zone 20N (EPSG:26920)
#> names : label
#> type : <chr>
# }