rasterizer

rasterizer is a Python library for rasterizing vector data (lines and polygons) onto a regular, axis-aligned rectangular grid. It was developed to handle rasterization based on the length or area of intersection with each grid cell, which is a feature not readily available in other libraries like Rasterio or GDAL. It is designed to be fast and memory-efficient because it specializes in this regular-grid case, using a Numba-accelerated implementation instead of supporting arbitrary raster layouts.

For example, you can rasterize polygons like this:

import geopandas as gpd
import numpy as np
from rasterizer import rasterize_polygons

# `polygons` can be a GeoDataFrame or GeoSeries.
# If `crs` is omitted, it is inferred from the input when available.
raster = rasterize_polygons(
    polygons=polygons,
    x=x,
    y=y,
    mode='area',
    weight='your_weight_column', # or None
    progress_bar=False,
)
# `raster` is an xarray.DataArray with spatial dims and, when available, CRS metadata

You can install rasterizer using PyPI:

pip install rasterizer

The practical tradeoff is intentional: rasterizer gains speed by assuming 1D x and y arrays of cell centers with constant spacing, which define a regular rectilinear grid.