momepy.Neighbors#
- class momepy.Neighbors(gdf, spatial_weights, unique_id, weighted=False, verbose=True)[source]#
Calculate the number of neighbours captured by
spatial_weights
. Ifweighted=True
, the number of neighbours will be divided by the perimeter of the object to return relative value.Adapted from [Hermosilla et al., 2012].
- Parameters:
- gdfGeoDataFrame
A GeoDataFrame containing objects to analyse.
- spatial_weightslibpysal.weights
A spatial weights matrix.
- unique_idstr
The name of the unique ID column used as the
spatial_weights
index.- weightedbool (default False)
If
True
, the number of neighbours will be divided by the perimeter of object, to return the relative value.- verbosebool (default True)
If
True
, shows progress bars in loops and indication of steps.
Examples
>>> sw = libpysal.weights.contiguity.Queen.from_dataframe(tessellation_df, ... ids='uID') >>> tessellation_df['neighbours'] = momepy.Neighbors(tessellation_df, ... sw, ... 'uID').series 100%|██████████| 144/144 [00:00<00:00, 6909.50it/s] >>> tessellation_df['neighbours'][0] 4
- Attributes:
- seriesSeries
A Series containing resulting values.
- gdfGeoDataFrame
The original GeoDataFrame.
- valuesSeries
A Series containing used values.
- swlibpysal.weights
The spatial weights matrix.
- idSeries
A Series containing used unique ID.
- weightedbool
Whether object is weighted or not.
Methods
__init__
(gdf, spatial_weights, unique_id[, ...])