Srai
Spatial Representations for Artificial Intelligence - a Python library toolkit for geospatial machine learning focused on creating embeddings for downstream tasks
Install / Use
/learn @kraina-ai/SraiREADME
Spatial Representations for Artificial Intelligence
<p align="center">⚠️🚧 This library is under HEAVY development. Expect breaking changes between <i>minor</i> versions 🚧⚠️</p> <p align="center">💬 Feel free to open an issue if you find anything confusing or not working 💬</p>Project Spatial Representations for Artificial Intelligence (srai) is a Python library for geospatial machine learning focusing on vector geometries. It provides tools for acquiring spatial data, dividing areas into micro-regions and embedding those regions into vector spaces.
Use cases
In the current state, srai provides the following functionalities:
- OSM / OvertureMaps data download - downloading OpenStreetMap / Overture Maps data for a given area using different sources
- Vector data processing - processing acquired vector data to extract useful information (e.g. road network, buildings, POIs, etc.)
- GTFS processing - extracting features from GTFS data
- Regionalization - splitting a given area into smaller regions using different algorithms (e.g. Uber's H3[1], Voronoi, etc.)
- Embedding - embedding regions into a vector space based on different spatial features, and using different algorithms and PyTorch models (eg. hex2vec[2], etc.)
- Datasets - provides prepared datasets for downstream tasks
- Utilities for spatial data visualization and processing
For future releases, we plan to add more functionalities, such as:
- Pre-computed embeddings - pre-computed embeddings for different regions and different embedding algorithms
- Full pipelines - full pipelines for different embedding approaches, pre-configured from
sraicomponents - Image data download and processing - downloading and processing image data (eg. OSM tiles, etc.)
End-to-end examples
Look into an example page with dedicated real-world scenarios and downstream tasks.
<p align="center"> <img src="https://raw.githubusercontent.com/kraina-ai/srai/main/docs/assets/images/use_case_example_results.png" style="max-width:600px;width:100%"/> </p>Datasets
The library also includes a dedicated datasets and benchmark modules for downstream tasks based on public data.
Installation
To install srai simply run:
pip install srai
This will install the srai package and dependencies required by most of the use cases. There are several optional dependencies that can be installed to enable additional functionality. These are listed in the optional dependencies section.
Optional dependencies
The following optional dependencies can be installed to enable additional functionality:
srai[all]- all optional dependenciessrai[osm]- dependencies required to download OpenStreetMap datasrai[overturemaps]- dependencies required to download Overture Maps datasrai[datasets]- dependencies required for downloading datasetssrai[voronoi]- dependencies to use Voronoi-based regionalization methodsrai[gtfs]- dependencies to process GTFS datasrai[plotting]- dependencies to plot graphs and mapssrai[torch]- dependencies to use torch-based embedders
Documentation
You can find the documentation for SRAI hosted on Github Pages.
It includes API documentation, contributing instructions and many examples. You can also check out our paper.
Tutorial
For a full tutorial on srai and geospatial data in general visit the srai-tutorial repository. It contains easy to follow jupyter notebooks concentrating on every part of the library.
You can also see the recordings of the tutorials on YouTube:
<p style="display: flex;"> <a href="https://www.youtube.com/watch?v=JlyPh_AdQ8E" style="margin: 0 10px"> <img src="https://img.youtube.com/vi/JlyPh_AdQ8E/0.jpg"> </a> <a href="https://www.youtube.com/watch?v=1-xLkFwibb4&t=17416s" style="margin: 0 10px"> <img src="https://img.youtube.com/vi/1-xLkFwibb4/0.jpg"> </a> </p>Usage
Downloading OSM data
To download OSM data for a given area, using a set of tags use one of OSMLoader classes:
OSMOnlineLoader- downloads data from OpenStreetMap API using osmnx - this is faster for smaller areas or tags countsOSMPbfLoader- loads data from automatically downloaded PBF file from protomaps - this is faster for larger areas or tags counts
Example with OSMOnlineLoader:
from srai.loaders import OSMOnlineLoader
from srai.plotting import plot_regions
from srai.regionalizers import geocode_to_region_gdf
query = {"leisure": "park"}
area = geocode_to_region_gdf("Wrocław, Poland")
loader = OSMOnlineLoader()
parks_gdf = loader.load(area, query)
folium_map = plot_regions(area, colormap=["rgba(0,0,0,0)"], tiles_style="CartoDB positron")
parks_gdf.explore(m=folium_map, color="forestgreen")
<p align="center">
<img src="https://raw.githubusercontent.com/kraina-ai/srai/main/docs/assets/images/downloading_osm_data.jpg" style="max-width:600px;width:100%"/>
</p>
Downloading road network
Road network downloading is a special case of OSM data downloading. To download road network for a given area, use OSMWayLoader class:
from srai.loaders import OSMNetworkType, OSMWayLoader
from srai.plotting import plot_regions
from srai.regionalizers import geocode_to_region_gdf
area = geocode_to_region_gdf("Utrecht, Netherlands")
loader = OSMWayLoader(OSMNetworkType.BIKE)
nodes, edges = loader.load(area)
folium_map = plot_regions(area, colormap=["rgba(0,0,0,0.1)"], tiles_style="CartoDB positron")
edges[["geometry"]].explore(m=folium_map, color="seagreen")
<p align="center">
<img src="https://raw.githubusercontent.com/kraina-ai/srai/main/docs/assets/images/downloading_road_network_data.jpg" style="max-width:600px;width:100%"/>
</p>
Downloading GTFS data
To extract features from GTFS use GTFSLoader. It will extract trip count and available directions for each stop in 1h time windows.
from pathlib import Path
from srai.loaders import GTFSLoader, download_file
from srai.plotting import plot_regions
from srai.regionalizers import geocode_to_region_gdf
area = geocode_to_region_gdf("Vienna, Austria")
gtfs_file = Path("vienna_gtfs.zip")
download_file("https://transitfeeds.com/p/stadt-wien/888/latest/download", gtfs_file.as_posix())
loader = GTFSLoader()
features = loader.load(gtfs_file)
folium_map = plot_regions(area, colormap=["rgba(0,0,0,0.1)"], tiles_style="CartoDB positron")
features[["trips_at_8", "geometry"]].explore("trips_at_8", m=folium_map)
<p align="center">
<img src="https://raw.githubusercontent.com/kraina-ai/srai/main/docs/assets/images/downloading_gtfs_data.jpg" style="max-width:600px;width:100%"/>
</p>
Regionalization
Regionalization is a process of dividing a given area into smaller regions. Th
Related Skills
claude-opus-4-5-migration
83.0kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
336.9kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
feishu-drive
336.9k|
things-mac
336.9kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
