基于city2graph、OSMnx和PyTorch Geometric的空间图神经网络城市功能推断编码实现
英文摘要
This tutorial builds an end-to-end spatial graph learning pipeline using the city2graph library. It collects real POI and street network data from OpenStreetMap around Shibuya, Tokyo (with a synthetic clustered fallback to ensure reliability), engineers spatial features like local density and street distance, and constructs six proximity graph families (KNN, Delaunay, Gabriel, RNG, EMST, Waxman) to compare graph topologies. A two-layer GraphSAGE model is trained on a homogeneous KNN graph to predict urban function categories (food, retail, education, health) from spatial structure and node features, achieving test accuracy and macro-F1. The pipeline also demonstrates heterogeneous graph construction using bridge edges between node types and a heterogeneous GNN forward pass via PyTorch Geometric's to_hetero, along with PCA visualization of learned embeddings and a geographic prediction map.
中文摘要
该教程构建了一个完整的空间图学习流程,使用city2graph库收集东京涩谷周边OpenStreetMap的真实POI和街道网络数据(含合成聚类备用方案),并设计局部密度、街道距离等空间特征。构建了六类邻近图(KNN、Delaunay、Gabriel、RNG、EMST、Waxman)以比较不同图拓扑,随后在齐次KNN图上训练两层GraphSAGE模型,根据空间结构和节点特征预测城市功能类别(餐饮、零售、教育、健康),并给出了测试准确率和宏观F1分数。流程还展示了利用桥梁边构建异构图类型,并通过PyTorch Geometric的to_hetero运行异构图神经网络前向传播,同时使用PCA可视化学到的嵌入和地理预测图。
关键要点
city2graph directly transforms OpenStreetMap POI and street network data into ready-to-use spatial graph structures.
city2graph直接将OpenStreetMap的POI和街道网络数据转化为可直接使用的空间图结构。
Six proximity graph families (KNN, Delaunay, Gabriel, RNG, EMST, Waxman) connect the same set of POIs with varying edge counts and average degrees, highlighting different spatial representations.
六类邻近图(KNN、Delaunay、Gabriel、RNG、EMST、Waxman)以不同的边数和平均度连接同一组POI,展示了多种空间表征方式。
A synthetic clustered POI fallback ensures the tutorial remains executable offline when OSM data is unavailable.
合成聚类POI回退方案在OSM数据不可用时保证教程仍可运行。
A two-layer GraphSAGE classifier successfully predicts urban function categories using spatial features (coordinates, local density, street distance, degree) and graph structure.
两层GraphSAGE分类器利用空间特征(坐标、局部密度、街道距离、度)和图结构成功预测城市功能类别。
The pipeline supports both homogeneous graph training and heterogeneous multi‑layer graph experimentation through PyTorch Geometric’s to_hetero utility.
该流程通过PyTorch Geometric的to_hetero功能同时支持齐次图训练和异构图多层图实验。