Skip to contents

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

Usage

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

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 raster::raster() or raster::brick().

Value

A RasterLayer or a RasterBrick object.

See also

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

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 RasterLayer:
qgis_as_raster(result)
#> class      : RasterLayer 
#> dimensions : 100, 100, 10000  (nrow, ncol, ncell)
#> resolution : 18.27273, 15.53535  (x, y)
#> extent     : 409939.9, 411767.1, 5083307, 5084861  (xmin, xmax, ymin, ymax)
#> crs        : +proj=utm +zone=20 +datum=NAD83 +units=m +no_defs 
#> source     : file2b04200a85ef.tif 
#> names      : file2b04200a85ef 
#> 

# if you need more control, extract the needed output element first:
output_raster <- qgis_extract_output(result, "OUTPUT")
qgis_as_raster(output_raster)
#> class      : RasterLayer 
#> dimensions : 100, 100, 10000  (nrow, ncol, ncell)
#> resolution : 18.27273, 15.53535  (x, y)
#> extent     : 409939.9, 411767.1, 5083307, 5084861  (xmin, xmax, ymin, ymax)
#> crs        : +proj=utm +zone=20 +datum=NAD83 +units=m +no_defs 
#> source     : file2b04200a85ef.tif 
#> names      : file2b04200a85ef 
#> 
# }