⚠️ 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! 🙂



Vector.create_mask(raster=None, crs=None, xres=None, yres=None, bounds=None, buffer=0, as_array=False)[source]#

Create a mask from the vector features.

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

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.

Vector features which fall outside the bounds of the raster file are not written to the new mask file.

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

  • crs (CRS | None) – A pyproj or rasterio CRS object (Default to raster.crs if not None then self.crs)

  • xres (float | None) – Output raster spatial resolution in x. Only is raster is None.

  • yres (float | None) – Output raster spatial resolution in y. Only if raster is None. (Default to xres)

  • bounds (tuple[float, float, float, float] | None) – Output raster bounds (left, bottom, right, top). Only if raster is None (Default to self bounds)

  • buffer (int | float | integer[Any] | floating[Any]) – Size of buffer to be added around the features, in the raster’s projection units. If a negative value is set, will erode the features.

  • as_array (bool) – Return mask as a boolean array

Return type:

Mask | ndarray[Any, dtype[bool_]]


A Mask object contain a boolean array