Skip to contents

This function rasterizes an sf MULTIPOLYGON object to a SpatRaster object. The function also retains an attribute table from the sf object, by assigning categorical ID values to the raster values. The rasterized SpatRaster object will also contain a legend derived from the attribute table of the sf object.

Usage

rasterise_multipolygon(sf_object, raster_res = c(100, 100), field = "ID")

Arguments

sf_object

An sf MULTIPOLYGON object. It must contain an attribute table, with at least one categorical ID (numeric).

raster_res

A numeric vector specifying the resolution of the raster. Default is c(100,100).

field

A character string specifying the field name to be used for rasterization from the sf object. Default is "ID".

Value

A SpatRaster object that is a rasterized version of the input sf object, with a legend derived from the attribute table of the sf object.

Examples

rasterise_multipolygon(sf_object = ntt_admin, raster_res = c(100,100), field = "ID")
#> class       : SpatRaster 
#> dimensions  : 3570, 6884, 1  (nrow, ncol, nlyr)
#> resolution  : 100, 100  (x, y)
#> extent      : 52661.8, 741061.8, 8783176, 9140176  (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / UTM zone 51S (EPSG:32751) 
#> source(s)   : memory
#> categories  : Kabupaten 
#> name        :        Kabupaten 
#> min value   :     Sumba Tengah 
#> max value   : Sumba Barat Daya