momepy.get_nearest_node#

momepy.get_nearest_node(buildings, nodes, edges, nearest_edge)[source]#

Identify the nearest node for each building.

Snap each building to the closest street network node on the closest network edge. This assumes that the nearest street network edge has already been identified using get_nearest_street().

The edges and nodes GeoDataFrames are expected to be an outcome of momepy.nx_to_gdf() or match its structure with ["node_start", "node_end"] columns and their meaning.

Parameters:
buildingsGeoSeries | GeoDataFrame

GeoSeries or GeoDataFrame of buildings.

nodesGeoDataFrame

A GeoDataFrame containing street nodes.

edgesGeoDataFrame

A GeoDataFrame containing street edges with ["node_start", "node_end"] columns marking start and end nodes of each edge. These are the default outcome of momepy.nx_to_gdf().

nearest_edgeSeries

A Series aligned with buildings containing the information on the nearest street edge. Matches the outcome of get_nearest_street().

Returns:
Series

Examples

>>> path = momepy.datasets.get_path("bubenec")
>>> buildings = geopandas.read_file(path, layer="buildings")
>>> streets = geopandas.read_file(path, layer="streets")

Pass an object via networkx to get the nodes and necessary information.

>>> G = momepy.gdf_to_nx(streets)
>>> nodes, edges = momepy.nx_to_gdf(G)

Get nearest edge:

>>> buildings["edge_index"] = momepy.get_nearest_street(buildings, edges)

Get nearest node:

>>> momepy.get_nearest_node(buildings, nodes, edges, buildings["edge_index"])
0       0.0
1       9.0
2      11.0
3      11.0
4      11.0
    ...
139     1.0
140    20.0
141    15.0
142     2.0
143    22.0
Length: 144, dtype: float64