momepy.mean_interbuilding_distance#

momepy.mean_interbuilding_distance(geometry, adjacency_graph, neighborhood_graph)[source]#

Calculate the mean distance between adjacent geometries within a set neighborhood

For each building, this function takes a neighborhood based on the neighbors within a neighborhood_graph and calculates the mean distance between adjacent buildings within this neighborhood where adjacency is captured by adjacency_graph.

Parameters:
geometryGeoDataFrame | GeoSeries

A GeoDataFrame or GeoSeries containing geometries to analyse.

adjacency_graphlibpysal.graph.Graph

Graph representing the adjacency of geometries. Typically, this is a contiguity graph derived from tessellation cells linked to buildings.

neighborhood_graphlibpysal.graph.Graph

Graph representing the extent around each geometry within which to calculate the mean interbuilding distance. This can be a distance based graph, KNN graph, higher order contiguity, etc.

Returns:
Series

Notes

The index of geometry must match the index along which both of the graphs are built.

Examples

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

Define a spatial graph denoting building adjacency:

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

Define a spatial graph denoting the neighborhood:

>>> knn15 = graph.Graph.build_knn(buildings.centroid, k=15)
>>> knn15
<Graph of 144 nodes and 2160 nonzero edges indexed by
 [0, 1, 2, 3, 4, ...]>

Measure mean interbuilding distance:

>>> momepy.mean_interbuilding_distance(buildings, delaunay, knn15)
0      29.516506
1      18.673132
2      23.277728
3      25.409034
4      18.454463
        ...
139    21.642580
140    16.427126
141    17.792155
142    10.844367
143    14.896066
Name: mean_interbuilding_distance, Length: 144, dtype: float64