# city2graph: GeoAI with Graph Neural Networks (GNNs) and Spatial Network Analysis
[](http://city2graph.net/_static/social_preview.png)
**city2graph** is a Python library for converting geospatial datasets into graph representations, providing an integrated interface for [GeoPandas](https://geopandas.org/), [NetworkX](https://networkx.org/), and [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/latest/) across multiple domains (e.g. streets, transportations, OD matrices, POI proximities, etc.). It enables researchers and practitioners to seamlessly develop advanced GeoAI and geographic data science applications. For more information, please visit the [documentation](https://city2graph.net).
[](https://badge.fury.io/py/city2graph/) [](https://anaconda.org/conda-forge/city2graph/) [](https://pepy.tech/projects/city2graph) [](https://doi.org/10.5281/zenodo.15858845) [](https://github.com/c2g-dev/city2graph/blob/main/LICENSE)
[](https://anaconda.org/conda-forge/city2graph) [](https://codecov.io/gh/c2g-dev/city2graph) [](https://github.com/astral-sh/ruff)
## Features
[](http://city2graph.net/_static/scope.png)
- **Graph Construction for GeoAI:** Build graphs from diverse urban datasets, including buildings, streets, and land use, to power GeoAI and GNN applications.
- **Transportation Network Modeling:** Analyze public transport systems (buses, trams, trains) by constructing detailed transportation graphs with support of GTFS format.
- **Proximity and Contiguity Analysis:** Create graphs based on spatial proximity and adjacency for applications in urban planning and environmental analysis.
- **Mobility Flow Analysis:** Model and analyze urban mobility patterns from various data sources like bike-sharing, migration, and pedestrian flows.
- **PyTorch Geometric Integration:** Seamlessly convert geospatial data into PyTorch tensors for GNNs.
## Installation
### Using pip
#### Basic Installation
The simplest way to install city2graph is via pip:
```bash
pip install city2graph
```
This installs the core functionality without PyTorch and PyTorch Geometric.
#### With PyTorch (CPU)
If you need the Graph Neural Networks functionality, install with the `cpu` option:
```bash
pip install "city2graph[cpu]"
```
This will install PyTorch and PyTorch Geometric with CPU support, suitable for development and small-scale processing.
#### With PyTorch + CUDA (GPU)
For GPU acceleration, you can install city2graph with a specific CUDA version extra. For example, for CUDA 12.8:
```bash
pip install "city2graph[cu128]"
```
Supported CUDA versions are `cu118`, `cu124`, `cu126`, and `cu128`.
### Using conda
#### Basic Installation
You can also install city2graph using conda from conda-forge:
```bash
conda install -c conda-forge city2graph
```
This installs the core functionality without PyTorch and PyTorch Geometric.
#### With PyTorch (CPU)
To use PyTorch and PyTorch Geometric with city2graph installed from conda-forge, you need to manually add these libraries to your environment:
```bash
# Install city2graph
conda install -c conda-forge city2graph
# Then install PyTorch and PyTorch Geometric
conda install -c conda-forge pytorch pytorch_geometric
```
#### With PyTorch + CUDA (GPU)
For GPU support, you should select the appropriate PyTorch variant by specifying the version and CUDA build string. For example, to install PyTorch 2.7.1 with CUDA 12.8 support:
```bash
# Install city2graph
conda install -c conda-forge city2graph
# Then install PyTorch with CUDA support
conda install -c conda-forge pytorch=2.7.1=*cuda128*
conda install -c conda-forge pytorch_geometric
```
You can browse available CUDA-enabled builds on the [conda-forge PyTorch files page](https://anaconda.org/conda-forge/pytorch/files) and substitute the desired version and CUDA variant in your install command. Make sure that the versions of PyTorch and PyTorch Geometric you install are compatible with each other and with your system.
**⚠️ Important:** conda is not officially supported by PyTorch and PyTorch Geometric anymore, and only conda-forge distributions are available for them. We recommend using pip or uv for the most streamlined installation experience if you need PyTorch functionality.
## For Development
If you want to contribute to city2graph, you can set up a development environment using `uv`.
```bash
# Install uv if you haven't already done it
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone https://github.com/c2g-dev/city2graph.git
cd city2graph
# Install development dependencies with a PyTorch variant (e.g., cpu or cu128)
uv sync --extra cpu --group dev
```
You can then run commands within the managed environment:
```bash
# Add IPython kernel for interactive development
uv run ipython kernel install --name "your-env-name" --user
# Or start Jupyter Notebook
uv run jupyter notebook
```
### Development Environment
The development dependencies include:
- `ipython`: Enhanced interactive Python shell with Jupyter kernel support
- `jupyter` and `notebook`: For running Jupyter notebooks with project-specific kernel
- `isort`: Code formatting tools
- `pytest` and `pytest-cov`: Testing tools
The Jupyter kernel installation ensures that when you start Jupyter notebooks, you can select the "city2graph" kernel which has access to all your project dependencies in the correct virtual environment.
### Using Docker Compose
Before using Docker Compose, ensure you have Docker and Docker Compose installed on your system:
```bash
# Check Docker installation
docker --version
# Check Docker Compose installation
docker compose version
```
If these commands don't work, you need to install Docker first:
- For macOS: Install [Docker Desktop](https://www.docker.com/products/docker-desktop)
- For Linux: Follow the [installation instructions](https://docs.docker.com/engine/install/) for your specific distribution
- For Windows: Install [Docker Desktop](https://www.docker.com/products/docker-desktop)
Once Docker is installed, clone the repository and start the containers:
```bash
# Clone the repository
git clone https://github.com/yu-ta-sato/city2graph.git
cd city2graph
# Build and run in detached mode
docker compose up -d
# Access Jupyter notebook at http://localhost:8888
# Stop containers when done
docker compose down
```
You can customize the services in the `docker-compose.yml` file according to your needs.
## Citation
If you use city2graph in your research, please cite it as follows:
```bibtex
@software{sato2025city2graph,
  title = {city2graph: Transform geospatial relations into graphs for spatial network analysis and Graph Neural Networks},
  author = {Sato, Yuta},
  year = {2025},
  url = {https://github.com/c2g-dev/city2graph},
  doi = {10.5281/zenodo.15858845},
}
```
You can also use the DOI to cite a specific version: [](https://doi.org/10.5281/zenodo.15858845)
Alternatively, you can find the citation information in the [CITATION.cff](CITATION.cff) file in this repository, which follows the Citation File Format standard.
## Contributing
We welcome contributions to the city2graph project! To contribute:
1. **Fork and clone the repository:**
   ```bash
   git clone https://github.com/<your-name>/city2graph.git
   cd city2graph
   git remote add upstream https://github.com/c2g-dev/city2graph.git
   ```
2. **Set up the development environment:**
   ```bash
   uv sync --group dev --extra cpu
   source .venv/bin/activate  # On Windows: .venv\Scripts\activate
   ```
3. **Create a feature branch:**
   ```bash
   git checkout -b feature/your-feature-name
   ```
4. **Make your changes and test:**
   ```bash
   # Run pre-commit checks
   uv run pre-commit run --all-files
   # Run tests
   uv run pytest --cov=city2graph --cov-report=html --cov-report=term
   ```
5. **Submit a pull request** with a clear description of your changes.
For detailed contributing guidelines, code style requirements, and documentation standards, please see our [Contributing Guide](docs/source/contributing.rst).
## Code Quality
We maintain strict code quality standards using:
- **Ruff**: For linting and formatting
- **mypy**: For static type checking
- **numpydoc**: For docstring style validation
All contributions must pass pre-commit checks before being merged.
[](https://www.liverpool.ac.uk/geographic-data-science/)
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": null,
    "name": "city2graph",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "Digital Twin, GNNs, GeoAI, Geographic Data Science, Geospatial Analysis, Geospatial Foundation Models, Graph Neural Networks, Graph Representation Learning, PyTorch Geometric, Spatial Data Science, Spatial Knowledge Graphs, Spatiotemporal Analysis, Transportation Networks, Urban Analytics, Urban Informatics, Urban Mobility, Urban Planning and Design",
    "author": null,
    "author_email": "Yuta Sato <y.sato@liverpool.ac.uk>",
    "download_url": "https://files.pythonhosted.org/packages/0b/a2/aaca3c110d8f0be6e5fbf58455bb96b4ab21a50ee00f64e223c643787e00/city2graph-0.1.4.tar.gz",
    "platform": null,
    "description": "# city2graph: GeoAI with Graph Neural Networks (GNNs) and Spatial Network Analysis\n\n[](http://city2graph.net/_static/social_preview.png)\n\n**city2graph** is a Python library for converting geospatial datasets into graph representations, providing an integrated interface for [GeoPandas](https://geopandas.org/), [NetworkX](https://networkx.org/), and [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/latest/) across multiple domains (e.g. streets, transportations, OD matrices, POI proximities, etc.). It enables researchers and practitioners to seamlessly develop advanced GeoAI and geographic data science applications. For more information, please visit the [documentation](https://city2graph.net).\n\n[](https://badge.fury.io/py/city2graph/) [](https://anaconda.org/conda-forge/city2graph/) [](https://pepy.tech/projects/city2graph) [](https://doi.org/10.5281/zenodo.15858845) [](https://github.com/c2g-dev/city2graph/blob/main/LICENSE)\n[](https://anaconda.org/conda-forge/city2graph) [](https://codecov.io/gh/c2g-dev/city2graph) [](https://github.com/astral-sh/ruff)\n\n## Features\n\n[](http://city2graph.net/_static/scope.png)\n\n- **Graph Construction for GeoAI:** Build graphs from diverse urban datasets, including buildings, streets, and land use, to power GeoAI and GNN applications.\n- **Transportation Network Modeling:** Analyze public transport systems (buses, trams, trains) by constructing detailed transportation graphs with support of GTFS format.\n- **Proximity and Contiguity Analysis:** Create graphs based on spatial proximity and adjacency for applications in urban planning and environmental analysis.\n- **Mobility Flow Analysis:** Model and analyze urban mobility patterns from various data sources like bike-sharing, migration, and pedestrian flows.\n- **PyTorch Geometric Integration:** Seamlessly convert geospatial data into PyTorch tensors for GNNs.\n\n\n## Installation\n\n### Using pip\n\n#### Basic Installation\n\nThe simplest way to install city2graph is via pip:\n\n```bash\npip install city2graph\n```\n\nThis installs the core functionality without PyTorch and PyTorch Geometric.\n\n#### With PyTorch (CPU)\n\nIf you need the Graph Neural Networks functionality, install with the `cpu` option:\n\n```bash\npip install \"city2graph[cpu]\"\n```\n\nThis will install PyTorch and PyTorch Geometric with CPU support, suitable for development and small-scale processing.\n\n#### With PyTorch + CUDA (GPU)\n\nFor GPU acceleration, you can install city2graph with a specific CUDA version extra. For example, for CUDA 12.8:\n\n```bash\npip install \"city2graph[cu128]\"\n```\n\nSupported CUDA versions are `cu118`, `cu124`, `cu126`, and `cu128`.\n\n### Using conda\n\n#### Basic Installation\n\nYou can also install city2graph using conda from conda-forge:\n\n```bash\nconda install -c conda-forge city2graph\n```\n\nThis installs the core functionality without PyTorch and PyTorch Geometric.\n\n#### With PyTorch (CPU)\n\nTo use PyTorch and PyTorch Geometric with city2graph installed from conda-forge, you need to manually add these libraries to your environment:\n\n```bash\n# Install city2graph\nconda install -c conda-forge city2graph\n\n# Then install PyTorch and PyTorch Geometric\nconda install -c conda-forge pytorch pytorch_geometric\n```\n\n#### With PyTorch + CUDA (GPU)\n\nFor GPU support, you should select the appropriate PyTorch variant by specifying the version and CUDA build string. For example, to install PyTorch 2.7.1 with CUDA 12.8 support:\n\n```bash\n# Install city2graph\nconda install -c conda-forge city2graph\n\n# Then install PyTorch with CUDA support\nconda install -c conda-forge pytorch=2.7.1=*cuda128*\nconda install -c conda-forge pytorch_geometric\n```\n\nYou can browse available CUDA-enabled builds on the [conda-forge PyTorch files page](https://anaconda.org/conda-forge/pytorch/files) and substitute the desired version and CUDA variant in your install command. Make sure that the versions of PyTorch and PyTorch Geometric you install are compatible with each other and with your system.\n\n**\u26a0\ufe0f Important:** conda is not officially supported by PyTorch and PyTorch Geometric anymore, and only conda-forge distributions are available for them. We recommend using pip or uv for the most streamlined installation experience if you need PyTorch functionality.\n\n## For Development\n\nIf you want to contribute to city2graph, you can set up a development environment using `uv`.\n\n```bash\n# Install uv if you haven't already done it\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# Clone the repository\ngit clone https://github.com/c2g-dev/city2graph.git\ncd city2graph\n\n# Install development dependencies with a PyTorch variant (e.g., cpu or cu128)\nuv sync --extra cpu --group dev\n```\n\nYou can then run commands within the managed environment:\n\n```bash\n# Add IPython kernel for interactive development\nuv run ipython kernel install\u200a--name \"your-env-name\"\u200a--user\n\n# Or start Jupyter Notebook\nuv run jupyter notebook\n```\n\n### Development Environment\n\nThe development dependencies include:\n- `ipython`: Enhanced interactive Python shell with Jupyter kernel support\n- `jupyter` and `notebook`: For running Jupyter notebooks with project-specific kernel\n- `isort`: Code formatting tools\n- `pytest` and `pytest-cov`: Testing tools\n\nThe Jupyter kernel installation ensures that when you start Jupyter notebooks, you can select the \"city2graph\" kernel which has access to all your project dependencies in the correct virtual environment.\n\n### Using Docker Compose\n\nBefore using Docker Compose, ensure you have Docker and Docker Compose installed on your system:\n\n```bash\n# Check Docker installation\ndocker --version\n\n# Check Docker Compose installation\ndocker compose version\n```\n\nIf these commands don't work, you need to install Docker first:\n- For macOS: Install [Docker Desktop](https://www.docker.com/products/docker-desktop)\n- For Linux: Follow the [installation instructions](https://docs.docker.com/engine/install/) for your specific distribution\n- For Windows: Install [Docker Desktop](https://www.docker.com/products/docker-desktop)\n\nOnce Docker is installed, clone the repository and start the containers:\n\n```bash\n# Clone the repository\ngit clone https://github.com/yu-ta-sato/city2graph.git\ncd city2graph\n\n# Build and run in detached mode\ndocker compose up -d\n\n# Access Jupyter notebook at http://localhost:8888\n\n# Stop containers when done\ndocker compose down\n```\n\nYou can customize the services in the `docker-compose.yml` file according to your needs.\n\n## Citation\n\nIf you use city2graph in your research, please cite it as follows:\n\n```bibtex\n@software{sato2025city2graph,\n  title = {city2graph: Transform geospatial relations into graphs for spatial network analysis and Graph Neural Networks},\n  author = {Sato, Yuta},\n  year = {2025},\n  url = {https://github.com/c2g-dev/city2graph},\n  doi = {10.5281/zenodo.15858845},\n}\n```\n\nYou can also use the DOI to cite a specific version: [](https://doi.org/10.5281/zenodo.15858845)\n\nAlternatively, you can find the citation information in the [CITATION.cff](CITATION.cff) file in this repository, which follows the Citation File Format standard.\n\n## Contributing\n\nWe welcome contributions to the city2graph project! To contribute:\n\n1. **Fork and clone the repository:**\n   ```bash\n   git clone https://github.com/<your-name>/city2graph.git\n   cd city2graph\n   git remote add upstream https://github.com/c2g-dev/city2graph.git\n   ```\n\n2. **Set up the development environment:**\n   ```bash\n   uv sync --group dev --extra cpu\n   source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\n   ```\n\n3. **Create a feature branch:**\n   ```bash\n   git checkout -b feature/your-feature-name\n   ```\n\n4. **Make your changes and test:**\n   ```bash\n   # Run pre-commit checks\n   uv run pre-commit run --all-files\n\n   # Run tests\n   uv run pytest --cov=city2graph --cov-report=html --cov-report=term\n   ```\n\n5. **Submit a pull request** with a clear description of your changes.\n\nFor detailed contributing guidelines, code style requirements, and documentation standards, please see our [Contributing Guide](docs/source/contributing.rst).\n\n## Code Quality\n\nWe maintain strict code quality standards using:\n- **Ruff**: For linting and formatting\n- **mypy**: For static type checking\n- **numpydoc**: For docstring style validation\n\nAll contributions must pass pre-commit checks before being merged.\n\n[](https://www.liverpool.ac.uk/geographic-data-science/)\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A Python library for Geospatial Graph Neural Networks and GeoAI for Urban Analytics with PyTorch Geometric. Convert geospatial data to graphs for spatiotemporal analysis, urban mobility studies, and more.",
    "version": "0.1.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/c2g-dev/city2graph/issues",
        "Documentation": "https://city2graph.net",
        "Homepage": "https://github.com/c2g-dev/city2graph"
    },
    "split_keywords": [
        "digital twin",
        " gnns",
        " geoai",
        " geographic data science",
        " geospatial analysis",
        " geospatial foundation models",
        " graph neural networks",
        " graph representation learning",
        " pytorch geometric",
        " spatial data science",
        " spatial knowledge graphs",
        " spatiotemporal analysis",
        " transportation networks",
        " urban analytics",
        " urban informatics",
        " urban mobility",
        " urban planning and design"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e032bfa0ba1d7bdd0598e200abb43161adb40f41bea04025cff8bae02a76f135",
                "md5": "662a927b341308b6cbc5acce0db788a9",
                "sha256": "48dd973696c23e8847a583627f9faa6b27921361251ca8b16170ab0c72858bca"
            },
            "downloads": -1,
            "filename": "city2graph-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "662a927b341308b6cbc5acce0db788a9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 114398,
            "upload_time": "2025-09-16T16:28:22",
            "upload_time_iso_8601": "2025-09-16T16:28:22.470566Z",
            "url": "https://files.pythonhosted.org/packages/e0/32/bfa0ba1d7bdd0598e200abb43161adb40f41bea04025cff8bae02a76f135/city2graph-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0ba2aaca3c110d8f0be6e5fbf58455bb96b4ab21a50ee00f64e223c643787e00",
                "md5": "a706584db5d1df186d914131d470674b",
                "sha256": "55929a3ed707fb23614430122533c7e17bbbbd52e2f15ee3bab50e3f91095fb3"
            },
            "downloads": -1,
            "filename": "city2graph-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a706584db5d1df186d914131d470674b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 53705194,
            "upload_time": "2025-09-16T16:28:25",
            "upload_time_iso_8601": "2025-09-16T16:28:25.751580Z",
            "url": "https://files.pythonhosted.org/packages/0b/a2/aaca3c110d8f0be6e5fbf58455bb96b4ab21a50ee00f64e223c643787e00/city2graph-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-16 16:28:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "c2g-dev",
    "github_project": "city2graph",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "city2graph"
}