Proximity#
Module for generating proximity-based graphs from geospatial data.
This module provides functions to create k-nearest neighbor and Delaunay triangulation graphs from GeoDataFrame geometries.
- city2graph.proximity.delaunay_graph(gdf, distance_metric='euclidean', network_gdf=None, as_gdf=False)[source]#
Generate Delaunay graph from points or polygon centroids.
- Parameters:
gdf (geopandas.GeoDataFrame) – Input data as a GeoDataFrame. Centroids of geometries are used.
distance_metric (str, default "euclidean") – Distance metric to use. Options: “euclidean”, “manhattan”, or “network”. Network metric only affects edge weights, not topology.
network_gdf (geopandas.GeoDataFrame, optional) – Network GeoDataFrame for network distance calculations. Required when distance_metric=”network”.
as_gdf (bool, default False) – If True, return edges as GeoDataFrame instead of NetworkX graph.
- Returns:
Graph with nodes and Delaunay triangulation edges. If as_gdf=True, returns GeoDataFrame of edges. Node attributes include original data and ‘pos’ coordinates.
- Return type:
- city2graph.proximity.gilbert_graph(gdf, radius, distance_metric='euclidean', network_gdf=None, as_gdf=False)[source]#
Generate Gilbert disc model graph from GeoDataFrame point geometries.
- Parameters:
gdf (geopandas.GeoDataFrame) – Input GeoDataFrame with point geometries.
radius (float) – Connection radius.
distance_metric (str, default "euclidean") – Distance metric to use. Options: “euclidean”, “manhattan”, or “network”.
network_gdf (geopandas.GeoDataFrame, optional) – Network GeoDataFrame for network distance calculations. Required when distance_metric=”network”.
as_gdf (bool, default False) – If True, return edges as GeoDataFrame instead of NetworkX graph.
- Returns:
Graph with nodes and edges connecting points within radius. If as_gdf=True, returns GeoDataFrame of edges.
- Return type:
- city2graph.proximity.knn_graph(gdf, k=5, distance_metric='euclidean', network_gdf=None, as_gdf=False)[source]#
Generate k-nearest neighbor graph from points or polygon centroids.
- Parameters:
gdf (geopandas.GeoDataFrame) – Input data as a GeoDataFrame. Centroids of geometries are used.
k (int, default 5) – Number of nearest neighbors to connect to each node.
distance_metric (str, default "euclidean") – Distance metric to use. Options: “euclidean”, “manhattan”, or “network”.
network_gdf (geopandas.GeoDataFrame, optional) – Network GeoDataFrame for network distance calculations. Required when distance_metric=”network”.
as_gdf (bool, default False) – If True, return edges as GeoDataFrame instead of NetworkX graph.
- Returns:
Graph with nodes and k-nearest neighbor edges. If as_gdf=True, returns GeoDataFrame of edges. Node attributes include original data and ‘pos’ coordinates.
- Return type:
- city2graph.proximity.waxman_graph(gdf, beta, r0, seed=None, distance_metric='euclidean', network_gdf=None, as_gdf=False)[source]#
Generate Waxman random geometric graph with $H_{ij} = beta e^{-d_{ij}/r_0}}$.
- Parameters:
gdf (geopandas.GeoDataFrame) – Input GeoDataFrame with point geometries.
beta (float) – Probability scale factor.
r0 (float) – Euclidean distance scale factor.
seed (int | None, optional) – Random seed for reproducibility.
distance_metric (str, default "euclidean") – Distance metric to use. Options: “euclidean”, “manhattan”, or “network”. Note: Waxman model uses distance for probability calculation.
network_gdf (geopandas.GeoDataFrame, optional) – Network GeoDataFrame for network distance calculations. Required when distance_metric=”network”.
as_gdf (bool, default False) – If True, return edges as GeoDataFrame instead of NetworkX graph.
- Returns:
Stochastic Waxman graph with ‘beta’ and ‘r0’ in graph attributes. If as_gdf=True, returns GeoDataFrame of edges.
- Return type: