geoutils.Vector.rasterize

geoutils.Vector.rasterize#

Vector.rasterize(raster=None, crs=None, xres=None, yres=None, bounds=None, in_value=None, out_value=0)[source]#

Rasterize vector to a raster or mask, with input geometries burned in.

Match-reference: a raster can be passed to match its resolution, bounds and CRS when rasterizing the vector.

Alternatively, user can specify a grid to rasterize on using xres, yres, bounds and crs. Only xres is mandatory, by default yres=xres and bounds/crs are set to self’s.

Burn value is set by user and can be either a single number, or an iterable of same length as self.ds. Default is an index from 1 to len(self.ds).

Parameters:
  • raster (Raster | None) – Reference raster to match during rasterization.

  • crs (CRS | int | None) – Coordinate reference system as string or EPSG code (Default to raster.crs if not None then self.crs).

  • xres (float | None) – Output raster spatial resolution in x. Only if raster is None. Must be in units of crs, if set.

  • yres (float | None) – Output raster spatial resolution in y. Only if raster is None. Must be in units of crs, if set. (Default to xres).

  • bounds (tuple[float, float, float, float] | None) – Output raster bounds (left, bottom, right, top). Only if raster is None. Must be in same system as crs, if set. (Default to self bounds).

  • in_value (int | float | Iterable[int | float] | None) – Value(s) to be burned inside the polygons (Default is self.ds.index + 1).

  • out_value (int | float) – Value to be burned outside the polygons (Default is 0).

Return type:

Raster | Mask

Returns:

Raster or mask containing the burned geometries.