src / pysoilmap / rasterops.py

rasterize_like

rasterize_like(like, polygons, values, nodata=-1)[source]

Rasterize polygon values like the given raster array.

This function uses rasterio.features.rasterize() under the hood and extends its functionality to:

  1. handle non-numeric data (such as arrays of string values), and

  2. allow rasterizing multiple channels at once

Parameters:
  • like (DataArray) – raster with the target shape and transform

  • polygons (GeoSeries) – 1D array of N polygons

  • values (ndarray) – (*C, N) array of corresponding values

  • nodata – nodata value.

Return type:

ndarray