Source code for earthdaily.earthdatastore.cube_utils.preprocessing

from rasterio import features


[docs] def rasterize(gdf, datacube, all_touched=True, fill=0): gdf["geometry"] = gdf.to_crs(datacube.rio.crs).clip_by_rect(*datacube.rio.bounds()) shapes = ((gdf.iloc[i].geometry, i + 1) for i in range(gdf.shape[0])) # rasterize features to use numpy/scipy to avoid polygon clipping feats = features.rasterize( shapes=shapes, fill=fill, out_shape=datacube.rio.shape, transform=datacube.rio.transform(), all_touched=all_touched, ) return feats