momepy.neighbor_distance

momepy.neighbor_distance(geometry, graph)[source]

Calculate the mean distance to adjacent elements.

Takes geometry of adjacent elements defined in graph and calculates the mean distance.

Notes

The index of geometry must match the index along which the graph is built.

Parameters:
geometry : GeoDataFrame | GeoSeries

A GeoDataFrame or GeoSeries containing geometries to analyse.

graph : libpysal.graph.Graph

Graph representing spatial relationships between elements.

Return type:

Series

Examples

>>> from libpysal import graph
>>> path = momepy.datasets.get_path("bubenec")
>>> buildings = geopandas.read_file(path, layer="buildings")

Define a spatial graph:

>>> delaunay = graph.Graph.build_triangulation(buildings.centroid)
>>> delaunay
<Graph of 144 nodes and 826 nonzero edges (1 component, 0 isolates) indexed by
 [0, 1, 2, 3, 4, ...]>

Mean distance to adjacent buildings within triangulated neighbors:

>>> momepy.neighbor_distance(buildings, delaunay)
focal
0      29.185890
1      30.244905
2      47.052305
3      22.831824
4      16.183615
         ...
139    39.698734
140    20.634252
141    38.208668
142     6.304569
143    14.551355
Length: 144, dtype: float64