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 ontodata_to_aggregate (GeoDataFrame) – GeoDataFrame of data to aggregate. Expected to already contain a column (
by) identifying which row ofgrideach row belongs to, e.g. as added by spatially joiningdata_to_aggregateontogridwithgeopandas.GeoDataFrame.sjoin().columns_to_aggregate (list[str]) – Columns of
data_to_aggregateto aggregate."geometry"is appended automatically if not already present, since it is required bydissolve.agg_func (Callable | str | dict) – Aggregation function(s), passed as the
aggfuncofgeopandas.GeoDataFrame.dissolve()by (str) – Column of
data_to_aggregateidentifying which grid cell each row belongs to. Defaults to"index_right", the column added bygeopandas.GeoDataFrame.sjoin().drop_na (bool) – If
True(default), drop grid cells with no aggregated data (i.e. no rows joined to them)
- Returns:
gridjoined with the aggregated values ofcolumns_to_aggregate, one row per grid cell- Return type:
GeoDataFrame