Editorial illustration for Tutorial Shows Homogeneous and Heterogeneous GNN Training with city2graph
Tutorial Shows Homogeneous and Heterogeneous GNN...
Tutorial Shows Homogeneous and Heterogeneous GNN Training with city2graph
Here’s the thing: building a spatial graph from scratch used to be a handful of disjoint scripts. This tutorial stitches those pieces together with city2graph, a library that pulls real‑world points‑of‑interest and street‑network data straight from OpenStreetMap, then falls back on a synthetic dataset if the live query fails. While the data collection is straightforward, the real work begins when we engineer spatial features and spin up several proximity‑graph families to see how each captures the same urban fabric.
The guide walks you through constructing both heterogeneous and homogeneous graph representations, converting them into PyTorch Geometric tensors, and training a GraphSAGE model to infer POI categories from pure spatial structure. By the end, you’ll have a single, reproducible pipeline that merges geospatial preprocessing, graph construction, and GNN‑based function inference—all in one notebook. It’s a practical, hands‑on look at turning city maps into learnable graphs.
We also run a heterogeneous GNN forward pass with to_hetero, showing that the tutorial supports both homogeneous training and heterogeneous graph experimentation.
Key Takeaways
- city2graph turns raw OpenStreetMap POI and street data into spatial graphs.
- Six proximity graph families (KNN, Delaunay, Gabriel, RNG, EMST, Waxman) connect the same POIs differently.
- A synthetic clustered fallback keeps the workflow runnable without OSM access.
- A two-layer GraphSAGE model predicts urban function categories from spatial structure.
- The pipeline supports both homogeneous training and heterogeneous graph experimentation via to_hetero.
Conclusion
In conclusion, we completed a full spatial GNN pipeline that transforms raw city data into graph-based learning and visualization. We compared several proximity graph methods, built a heterogeneous multi-layer graph, trained a homogeneous GraphSAGE classifier, and inspected the learned embeddings and geographic predictions.
It gives us a practical understanding of how spatial relationships among POIs can be represented as graph structures and used to predict urban functions. It also shows how city2graph, GeoPandas, OSMnx, and PyTorch Geometric work together to support advanced geospatial machine learning experiments in a Colab-friendly setup.
Check out the Full Codes with Notebook here.
Why this matters
Can a single tutorial accelerate urban AI projects? We think it can, at least for those comfortable with Python and graph libraries. By stitching together city2graph, OSMnx, and PyTorch Geometric, the guide delivers a reproducible pipeline that pulls real POI data, falls back on synthetic inputs when needed, and engineers spatial features without manual wrangling.
The inclusion of multiple proximity graph families lets developers compare how different constructions capture city structure, while the to_hetero call demonstrates that both homogeneous and heterogeneous GNNs can be run on the same data. For founders eyeing location‑based services, the end‑to‑end example reduces the engineering overhead of building custom graph loaders. Researchers gain a concrete baseline for experimenting with heterogeneous message passing, yet the article does not provide performance benchmarks or validation on downstream tasks, leaving it unclear whether the approach scales to larger metropolitan datasets.
Overall, the tutorial lowers the barrier to entry for spatial graph learning, but its practical impact will depend on how the community tests and extends the provided code.
Further Reading
- Metapath Construction for Heterogeneous GNNs - City2Graph - City2Graph
- Heterogeneous Graph Learning — pytorch_geometric documentation - PyTorch Geometric
- Learning on Heterogeneous Graphs with PyG - PyTorch Geometric / YouTube
- Heterogeneous Graph Neural Network - KDD
- From theory to practice: The evolution and comparative analysis of graph neural network architectures - ScienceDirect