reVeal.overlay.calc_area_weighted_average#
- calc_area_weighted_average(zones_df, dset_src, attribute, where=None, **kwargs)[source]#
Calculate the area-weighted average of the specified attribute for input features intersecting each zone in input zones dataframe. Area-weighted average is defined as the sum of all intersecting features’ area x attribute value divided by the sum of all areas.
Does not attribute any value to areas where features are not present – i.e., if only a small portion of a zone is covered by features, but those features have high attribute values, the result will have a high attribute value. In cases where this matters, use this function in conjunction with calc_percent_covered() or calc_sum_area().
If no features intersect a given zone, a value of NA will be returned for that zone.
- Parameters:
zones_df (geopandas.GeoDataFrame) – Input zones dataframe, to which results will be aggregated. This function assumes that the index of zones_df is unique for each feature. If this is not the case, unexpected results may occur.
dset_src (str) – Path to input vector dataset with geometries to be included in calculating coverage percents. Expected to a be a Polygon or MultiPolygon input, though this is not checked. Results for Points/MultiPoints and LineStrings/MultiLineStrings will be returned as all NAs since those features have zero area. Must be in the same CRS as the zones_df.
attribute (str) – Name of attribute in dset_src to use for calculating area-weighted average.
where (str, optional) – Optional query string to apply to the input dset_src to subset the features included in the results. Should follow the format expr defined in pandas.DataFrame.query.
**kwargs – Arbitrary keyword arguments. Not used, but allows passing extra parameters.
- Returns:
pandas.DataFrame – Returns a pandas DataFrame with a “value” column, representing the area-weighted average of attribute values of features in each zone. The index from the input zones_df is also included.