momepy.Neighbors

class momepy.Neighbors(gdf, spatial_weights, unique_id, weighted=False)[source]

Calculate the number of neighbours captured by spatial_weights

If weighted=True, number of neighbours will be divided by the perimeter of object to return relative value.

Adapted from [HRRCambraLopez12].

Parameters
gdfGeoDataFrame

GeoDataFrame containing objects to analyse

spatial_weightslibpysal.weights

spatial weights matrix

unique_idstr

name of the column with unique id used as spatial_weights index

weightedbool (default False)

if True, number of neighbours will be divided by the perimeter of object, to return relative value

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

Series containing resulting values

gdfGeoDataFrame

original GeoDataFrame

valuesSeries

Series containing used values

swlibpysal.weights

spatial weights matrix

idSeries

Series containing used unique ID

weightedbool

used weighted value

__init__(self, gdf, spatial_weights, unique_id, weighted=False)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, gdf, spatial_weights, unique_id)

Initialize self.