โš ๏ธ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. โš ๏ธ
Future changes will come with deprecation warnings! ๐Ÿ™‚

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.