Learn R Programming

clc (version 1.0.0)

as_raster: Convert a `clc` Object to Raster Format

Description

Returns an object of class `clc_raster` that contains a `terra::SpatRaster` raster object representing the converted vector layer into raster format.

Usage

as_raster(clo, base_raster, resolution)

# S3 method for clc as_raster(clo, base_raster = NULL, resolution = NULL)

Value

An object of class `clc_raster`.

Arguments

clo

A `clc` object.

base_raster

(Optional) A raster object to use as the base for rasterization.

resolution

(Optional) Numeric resolution to define the raster grid.

Details

The function requires either `base_raster` or `resolution` to be provided. If both are missing, an error is raised.

See Also

Other CLC class functions: clc(), copy_to(), cut_to_extent(), get_colors.clc(), get_levels.clc(), get_raster(), plot_clc(), prepare_plot(), save_to()

Examples

Run this code
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc")
clo <- clc(source = source_gpkg, layer_name = "clc")

raster_path <- system.file("extdata", "mdt.tif", package = "clc")
base_raster <- terra::rast(raster_path)

# ex1
r <- clo |>
     as_raster(base_raster = base_raster)

# ex2
r <- clo |>
     as_raster(resolution = 50)

Run the code above in your browser using DataLab