momepy.closeness_centrality¶

momepy.closeness_centrality(graph, name='closeness', weight='mm_len', **kwargs)[source]

Calculates the closeness centrality for nodes.

Wrapper around networkx.closeness_centrality.

Closeness centrality of a node u is the reciprocal of the average shortest path distance to u over all n-1 nodes within reachable nodes.

$C(u) = \frac{n - 1}{\sum_{v=1}^{n-1} d(v, u)},$

where d(v, u) is the shortest-path distance between v and u, and n is the number of nodes that can reach u.

Parameters
graphnetworkx.Graph

Graph representing street network. Ideally genereated from GeoDataFrame using momepy.gdf_to_nx()

namestr, optional

calculated attribute name

weightstr (default ‘mm_len’)

attribute holding the weight of edge (e.g. length, angle)

**kwargs

kwargs for networkx.closeness_centrality

Returns
Graph

networkx.Graph

Examples

>>> network_graph = mm.closeness_centrality(network_graph)