Getting Started

geocube combines the interfaces of:

and is powered by GDAL using:

When getting started, the API documentation to start reading would be geocube.api.core.make_geocube().

The simplest example would be to rasterize a single column:

from geocube.api.core import make_geocube

out_grid = make_geocube(
    vector_data="path_to_file.gpkg",
    measurements=["column_name"],
    resolution=(-0.0001, 0.0001),
)
out_grid["column_name"].rio.to_raster("my_rasterized_column.tif")

You can also rasterize a GeoDataFrame directly in the vector_data argument. This enables you to load in subsets of data or perform various operations before rasterization.

Once finished, you can write to anything supported by rasterio using rioxarray’s rio.to_raster() method. You can also write to a netCDF file using xarray’s to_netcdf().

However, life is only this simple when your data is perfectly clean, geospatially unique, and numeric. The good news is that geocube supports a variety of use cases and custom rasterization functions if your dataset does not meet these criteria (see: Usage Examples).