edit: Since GeoCube has quite some (nontrivial) dependencies, I recommend creating a new environment with: conda create -n <your_name> -c conda-forge geocube <whatever_else>, optionally also --strict-channel-priority
There is a great module: GeoCube, that does exactly what you want. It is somewhat more high-level, but uses GDAL internally I believe. Then, it becomes as easy as:
from geocube.api.core import make_geocube import rioxarray import geopandas as gpd raster_path = 'your path' vector_path = 'other path' source_ds = gpd.read_file(vector_path) DEM = rioxarray.open_rasterio(raster_path,masked=True) Cube = make_geocube(vector_data['columns1'vector_data=source_ds['columns1','columns2']=LUMap'columns2'],like=DEM) Cube.columns1.plot() alternatively, you can leave out the ['columns1','columns2'] to rasterize all attributes of the shapefile
sidenote: shapefile is the ESRI standard for storing vector formats, so I prefer to call it vector inside a program/script, since you can derive them from anywhere.