momepy.WeightedCharacter#
- class momepy.WeightedCharacter(gdf, values, spatial_weights, unique_id, areas=None, verbose=True)[source]#
Calculates the weighted character. Character weighted by the area of the objects within neighbors defined in
spatial_weights
.\[\frac{\sum_{i=1}^{n} {character_{i} * area_{i}}}{\sum_{i=1}^{n} area_{i}}\]Adapted from [Dibble et al., 2017].
- Parameters:
- gdfGeoDataFrame
The GeoDataFrame containing objects to analyse.
- valuesstr, list, np.array, pd.Series
The name of the
gdf
dataframe column,np.array
, orpd.Series
where the characters to be weighted are stored.- spatial_weightslibpysal.weights
A spatial weights matrix. If
None
, Queen contiguity matrix of set order will be calculated based on left.- unique_idstr
The name of the column with unique ID used as
spatial_weights
index.- areasstr, list, np.array, pd.Series (default None)
The name of the left dataframe column,
np.array
, orpd.Series
where the area values are stored.- verbosebool (default True)
If
True
, shows progress bars in loops and indication of steps.
Examples
>>> sw = libpysal.weights.DistanceBand.from_dataframe(tessellation_df, ... threshold=100, ... silence_warnings=True) >>> buildings_df['w_height_100'] = momepy.WeightedCharacter(buildings_df, ... values='height', ... spatial_weights=sw, ... unique_id='uID').series 100%|██████████| 144/144 [00:00<00:00, 361.60it/s]
- Attributes:
- seriesSeries
A Series containing resulting values.
- gdfGeoDataFrame
A original GeoDataFrame.
- valuesGeoDataFrame
A Series containing used values.
- areasGeoDataFrame
Series containing used areas.
- swlibpysal.weights
The spatial weights matrix.
- idSeries
A Series containing used unique ID.
Methods
__init__
(gdf, values, spatial_weights, unique_id)