City2Graph
Convert from any graph formatto City2Graph Convert from City2Graphto any other format
City2Graph is a BSD 3-Clause licensed Python library that converts geospatial datasets into graph structures for Graph Neural Network (GNN) training and network analysis. It is developed by Yuta Sato and associated with the Geographic Data Science Lab at the University of Liverpool, distributed on PyPI as "city2graph" with archival releases on Zenodo (DOI 10.5281/zenodo.15858845). Its stated purpose is to bridge traditional GIS and modern GeoAI by treating heterogeneous urban relationships as graphs, so spatial data scientists can move directly from map layers to machine-learning-ready tensors.
The library is built around three integrated interfaces: GeoPandas for input, NetworkX for graph construction and analysis, and PyTorch Geometric for GNN workflows. Nodes and edges are carried as GeoDataFrames, preserving geometry and attributes, and can be exported either to NetworkX graph objects or to PyTorch Geometric Data and HeteroData objects. The HeteroData path is central to its design: multiple node and edge types (buildings, streets, stops, zones, flows) are combined into a single heterogeneous graph, and metapaths connect features through intermediate networks. RustWorkX is used for performance and DuckDB backs large GTFS queries.
City2Graph groups its constructors by the kind of spatial relationship being modeled. Morphological graphs link buildings, streets, and land-use features within a distance threshold; transportation graphs are built from format:gtfs public-transit feeds; contiguity graphs derive Queen or Rook adjacency from polygonal zones; proximity graphs offer fixed-radius, k-nearest-neighbor, and Waxman connectivity over points of interest; and mobility graphs represent flows from origin-destination matrices, bike-sharing, and pedestrian movement. It also builds accessibility catchments and isochrones for multi-center analysis.
In the broader graph-tooling landscape, City2Graph occupies a spatial, GNN-oriented niche adjacent to general graph libraries such as tool:networkx and tool:igraph, and to the transit-to-graph converters tool:gtfs2nx and tool:peartree. Rather than defining an interchange serialization, it produces in-memory NetworkX and PyTorch Geometric objects, so persisting to portable formats like format:graphml or format:gexf-1.3 relies on the underlying libraries' writers.
Its main limitations are matters of scope and packaging. It targets urban and geospatial datasets specifically, not general-purpose graph interchange, and the heavier PyTorch and PyTorch Geometric dependencies are optional installs (the base pip install omits them), with conda-forge no longer officially carrying those components. Documentation is example-driven and the project is comparatively young, so long-term API stability is not yet guaranteed.
Input Formats
Frequently Asked Questions
What graph file formats does City2Graph support?
See the list on this page — it shows every format City2Graph can read, write and display.
How do I import a graph into City2Graph?
Convert your file to a format City2Graph can read, then open it in City2Graph. Use GraphInOut to get a City2Graph-compatible file in seconds.
How do I convert a file so City2Graph can open it?
Use the convert links above — upload or paste your graph, pick a format City2Graph accepts and download the result, right in your browser.
