city2graph documentation#

city2graph logo
city2graph logo

city2graph is a Python library for converting datasets of geospatial relations into graphs. It is designed to facilitate the graph data analytics in particular for urban studies and spatial analysis. It supports Pytorch Geometric to enable graph representation learning, such as Graph Neural Networks (GNNs).

Features#

  • Construct graphs from morphological datasets (e.g. buildings, streets, and land use)

  • Construct graphs from transportation datasets (e.g. public transport of buses, trams, and trains)

  • Construct graphs from contiguity datasets (e.g. land use, land cover, and administrative boundaries)

  • Construct graphs from mobility datasets (e.g. bike-sharing, migration, and pedestrian flows)

  • Convert geospatial data into pytorch tensors for graph representation learning, such as Graph Neural Networks (GNNs)

Examples#

Morphology

morphological_graph = city2graph.morphological_graph(
   buildings_gdf,
   segments_gdf,
   center_point,
   distance=500
 )
A morphological graph in Liverpool

A morphological graph of 500m walking distance in Liverpool#

>> For details, see Constructing Morphological Networks from Overture Maps

Transportation

sample_gtfs_path = Path("./itm_london_gtfs.zip")
gtfs_data = city2graph.load_gtfs(sample_gtfs_path)

travel_summary_gdf = city2graph.travel_summary_network(
   gtfs_data, calendar_start="20250401", calendar_end="20250401", as_gdf=True
)
A bus transportation graph in London

A travel summary graph of bus transportation between stops in London#

>> For details, see Processing GTFS to Obtain Flows of Public Transportation

Proximity

gilbert_graph = city2graph.gilbert_graph(poi_gdf, radius=100)
wax_l1 = city2graph.waxman_graph(poi_gdf,
                                 distance_metric="manhattan",
                                 r0=100,
                                 beta=0.5,
                                 as_gdf=True)

wax_l2 = city2graph.waxman_graph(poi_gdf,
                                 distance_metric="euclidean",
                                 r0=100,
                                 beta=0.5,
                                 as_gdf=True)

wax_net = city2graph.waxman_graph(poi_gdf,
                                 distance_metric="network",
                                 r0=100,
                                 beta=0.5,
                                 network_gdf=segments_gdf.to_crs(epsg=6677),
                                 as_gdf=True)
Waxman graph of points of interest in Liverpool

>> For details, see Generating Various Types of Graphs by Proximity

Documentation#

Indices and tables#