spatial_aggregation#

rojak.core.geometric.spatial_aggregation(grid, data_to_aggregate, columns_to_aggregate, agg_func, by='index_right', drop_na=True)[source]#

Aggregate data onto a grid, based on a prior spatial join between the data and the grid

Parameters:
  • grid (GeoDataFrame) – GeoDataFrame of grid cells (see create_grid_data_frame()) to aggregate onto

  • data_to_aggregate (GeoDataFrame) – GeoDataFrame of data to aggregate. Expected to already contain a column (by) identifying which row of grid each row belongs to, e.g. as added by spatially joining data_to_aggregate onto grid with geopandas.GeoDataFrame.sjoin().

  • columns_to_aggregate (list[str]) – Columns of data_to_aggregate to aggregate. "geometry" is appended automatically if not already present, since it is required by dissolve.

  • agg_func (Callable | str | dict) – Aggregation function(s), passed as the aggfunc of geopandas.GeoDataFrame.dissolve()

  • by (str) – Column of data_to_aggregate identifying which grid cell each row belongs to. Defaults to "index_right", the column added by geopandas.GeoDataFrame.sjoin().

  • drop_na (bool) – If True (default), drop grid cells with no aggregated data (i.e. no rows joined to them)

Returns:

grid joined with the aggregated values of columns_to_aggregate, one row per grid cell

Return type:

GeoDataFrame