Skip to main content

Transform geospatial relations into graphs for spatial analysis and GNNs.

Project description

city2graph

city2graph

city2graph is a Python library for converting urban geometry into graph representations, enabling advanced analysis of urban environments. For more information, please reach out to the document (https://city2graph.net).

PyPI Version codecov License Ruff

Features

scope

  • Construct graphs from morphological datasets (e.g. buildings, streets, and land use)
  • Construct graphs from transportation datasets (e.g. public transport of buses, trams, and trains)
  • Construct graphs from contiguity datasets (e.g. land use, land cover, and administrative boundaries)
  • Construct graphs from mobility datasets (e.g. bike-sharing, migration, and pedestrian flows)
  • Convert geospatial data into pytorch tensors for graph representation learning, such as Graph Neural Networks (GNNs)

Installation

Without PyTorch

The simplest way to install city2graph is via pip:

# Basic installation (without PyTorch)
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:

# Install with PyTorch and PyTorch Geometric (CPU version)
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:

# e.g., for CUDA 12.8
pip install "city2graph[cu128]"

Supported CUDA versions are cu118, cu124, cu126, and cu128.

Important: The PyTorch Geometric extensions (pyg_lib, torch_scatter, etc.) are not included and must be installed separately. Please refer to the PyTorch Geometric documentation for instructions. Due to the low demand, conda distributions are deprecated for PyTorch and PyTorch Geometric. For the most reliable setup, we recommend using pip or uv as described above.

For Development

If you want to contribute to city2graph, you can set up a development environment using uv.

# 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:

# 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:

# Check Docker installation
docker --version

# Check Docker Compose installation
docker compose version

If these commands don't work, you need to install Docker first:

Once Docker is installed, clone the repository and start the containers:

# 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.

Contributing

We welcome contributions to the city2graph project! To contribute:

  1. Fork and clone the repository:

    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:

    uv sync --group dev --extra cpu
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Create a feature branch:

    git checkout -b feature/your-feature-name
    
  4. Make your changes and test:

    # 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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

city2graph-0.1.1.tar.gz (55.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

city2graph-0.1.1-py3-none-any.whl (95.1 kB view details)

Uploaded Python 3

File details

Details for the file city2graph-0.1.1.tar.gz.

File metadata

  • Download URL: city2graph-0.1.1.tar.gz
  • Upload date:
  • Size: 55.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.20

File hashes

Hashes for city2graph-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1fcece53e4bdbce34ffed90ce316b08c2a2092a0a0746699066bf5dca3908a71
MD5 c42846d0e09be3f2ddbd45988b1d4eab
BLAKE2b-256 b833653c8380b92c026f5386f062b3c006d70e0415820cf78e724feb66ad9e2c

See more details on using hashes here.

File details

Details for the file city2graph-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: city2graph-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.20

File hashes

Hashes for city2graph-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b22d6efc2173f8b08690ec3b796b2b43a7581441c7845e723d7220f2e17bc23e
MD5 d8a5cb6d6d8123371e52cfca76e4025b
BLAKE2b-256 1af7006ccd8a4a845b60e189ca313f4f01f21e7ddacbb31eb94fee1d20a35313

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page