A Coding Implementation on Spatial Graph Neural Networks for Urban Function Inference Using city2graph, OSMnx, and PyTorch Geometric
In this tutorial, we build an end-to-end spatial graph learning pipeline using city2graph . We start by collecting real urban POI data and street network information from OpenStreetMap, with a synthetic fallback to ensure the workflow remains reliable. We then engineer spatial features, construct multiple proximity graph families, and compare how different graph-building strategies represent the same urban environment. After that, we create both heterogeneous and homogeneous graph structures, convert them into PyTorch Geometric format, and train a GraphSAGE model to predict POI categories from spatial structure. Through this process, we integrate geospatial data processing, graph construction, and GNN-based urban function inference into a single practical workflow. Installing city2graph and Importing Geospatial and Graph Learning Libraries Copy Code Copied Use a different Browser !pip -q install "city2graph[cpu]" osmnx contextily scikit-learn 2>/dev/null import w...
