API

rasterizer.rasterize_lines(lines: GeoDataFrame | GeoSeries, x: ndarray, y: ndarray, crs=None, mode: str = 'length', weight: str | None = None, progress_bar: bool = False) DataArray

Rasterizes a GeoDataFrame of LineString and MultiLineString on a regular, axis-aligned rectangular grid.

Parameters:
  • lines (gpd.GeoDataFrame | gpd.GeoSeries) – Geospatial vector data containing the line geometries.

  • x (np.ndarray) – 1D array of x-coordinates of the cell centers, with constant spacing.

  • y (np.ndarray) – 1D array of y-coordinates of the cell centers, with constant spacing.

  • crs – The coordinate reference system of the output grid. If None, infer it from lines when available.

  • mode (str, optional) – ‘binary’ or ‘length’. Defaults to ‘length’. - ‘binary’: the cell is True if crossed, False otherwise. - ‘length’: the cell contains the total length of the line segments.

  • weight (str, optional) – If specified, must be a str designating a numerical column of the processed gdf. The computed values of the raster are the fraction of the length of the intersected line by each mesh multiplied by the value of the specified column. Defaults to None.

  • progress_bar (bool, optional) – If True, display a tqdm progress bar while processing exploded line geometries. Defaults to False.

Returns:

A rasterized DataArray.

Return type:

xr.DataArray

rasterizer.rasterize_polygons(polygons: GeoDataFrame | GeoSeries, x: ndarray, y: ndarray, crs=None, mode: str = 'area', weight: str | None = None, progress_bar: bool = False) DataArray

Rasterizes a GeoDataFrame of Polygon and MultiPolygon on a regular, axis-aligned rectangular grid.

Parameters:
  • polygons (gpd.GeoDataFrame | gpd.GeoSeries) – Geospatial vector data containing the polygon geometries.

  • x (np.ndarray) – 1D array of x-coordinates of the cell centers, with constant spacing.

  • y (np.ndarray) – 1D array of y-coordinates of the cell centers, with constant spacing.

  • crs – The coordinate reference system of the output grid. If None, infer it from polygons when available.

  • mode (str, optional) – ‘binary’ or ‘area’. Defaults to ‘area’. - ‘binary’: the cell is True if covered, False otherwise. - ‘area’: the cell contains the area of the polygon that covers it.

  • weight (str, optional) – If specified, must be a str designating a numerical column of the processed gdf. The computed values of the raster are the fraction of the area of the intersected polygon by each mesh multiplied by the value of the specified column. Defaults to None.

  • progress_bar (bool, optional) – If True, display a tqdm progress bar while processing exploded polygon geometries. Defaults to False.

Returns:

A rasterized DataArray.

Return type:

xr.DataArray