rasterize

Contents

rasterize#

rasterize(xda: DataArray, vector: str | CloudPath | Path | GeoDataFrame, value_field: str = None, default_nodata: int = 0, default_value: int = 1, name: str = None, **kwargs) DataArray | Dataset[source]#

Rasterize a vector into raster format.

Note that passing merge_alg = MergeAlg.add will add the vector values to the given raster

See: https://pygis.io/docs/e_raster_rasterize.html

Use value_field to create a raster with multiple values. If set to None, the raster will be binary.

Warning

With dask usage, this function is not lazy (yet)!

Parameters:
  • xda (xr.DataArray) – Path to the raster or a rasterio dataset or a xarray.DataArray, used as base for the vector’s rasterization data (shape, etc.)

  • vector (AnyVectorType) – Vector to be rasterized

  • value_field (str) – Field of the vector with the values to be burnt on the raster (should be scalars). If let to None, the raster will be binary.

  • default_nodata (int) – Default nodata of the raster (outside the vector in the raster extent)

  • default_value (int) – Used as value for all geometries, if value_field not provided

  • name (str) – Name to give to the raster

Returns:

Rasterized vector

Return type:

AnyXrDataStructure

Example

>>> raster_path = "path/to/raster.tif"
>>> vec_path = "path/to/vector.shp"
>>> rasterize(raster_path, vec_path, value_field="classes")