Transform geospatial relations into graphs for spatial analysis and GNNs.
Project description
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).
Features
- 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 supportjupyterandnotebook: For running Jupyter notebooks with project-specific kernelisort: Code formatting toolspytestandpytest-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:
- For macOS: Install Docker Desktop
- For Linux: Follow the installation instructions for your specific distribution
- For Windows: Install Docker Desktop
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.
Docker Compose Configuration
The project includes a docker-compose.yml file that sets up:
- A Jupyter notebook server with all dependencies pre-installed
- GPU support if available on your system
- Mounted volumes for your data and notebooks
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file city2graph-0.1.0-py3-none-any.whl.
File metadata
- Download URL: city2graph-0.1.0-py3-none-any.whl
- Upload date:
- Size: 94.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48c7c884a79eeb5f1931b8e4b1c09090e219ab54af42b954abd96cddc965c6e5
|
|
| MD5 |
cb9ab279b4ae959717f7e68ef90e7625
|
|
| BLAKE2b-256 |
acf03ef4e9ba8a7ec9778ab1ade2ff4e9ca260be26fd41f3a4efc5dd7a7ea0d0
|