SkillAgentSearch skills...

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/Srai

README

<p align="center"> <img width="300" src="https://raw.githubusercontent.com/kraina-ai/srai/main/docs/assets/logos/srai-logo-transparent.png"> </p> <p align="center"> <img alt="GitHub" src="https://img.shields.io/github/license/kraina-ai/srai?logo=apache&logoColor=%23fff"> <img src="https://img.shields.io/github/checks-status/kraina-ai/srai/main?logo=GitHubActions&logoColor=%23fff" alt="Checks"> <a href="https://github.com/kraina-ai/srai/actions/workflows/ci-dev.yml" target="_blank"><img alt="GitHub Workflow Status - DEV" src="https://img.shields.io/github/actions/workflow/status/kraina-ai/srai/ci-dev.yml?label=build-dev&logo=GitHubActions&logoColor=%23fff"></a> <a href="https://github.com/kraina-ai/srai/actions/workflows/ci-prod.yml" target="_blank"><img alt="GitHub Workflow Status - PROD" src="https://img.shields.io/github/actions/workflow/status/kraina-ai/srai/ci-prod.yml?label=build-prod&logo=GitHubActions&logoColor=%23fff"></a> <a href="https://results.pre-commit.ci/latest/github/kraina-ai/srai/main" target="_blank"><img src="https://results.pre-commit.ci/badge/github/kraina-ai/srai/main.svg" alt="pre-commit.ci status"></a> <a href="https://www.codefactor.io/repository/github/kraina-ai/srai"><img alt="CodeFactor Grade" src="https://img.shields.io/codefactor/grade/github/kraina-ai/srai?logo=codefactor&logoColor=%23fff"></a> <a href="https://app.codecov.io/gh/kraina-ai/srai/tree/main"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/kraina-ai/srai?logo=codecov&token=PRS4E02ZX0&logoColor=%23fff"></a> <a href="https://pypi.org/project/srai" target="_blank"><img src="https://img.shields.io/pypi/v/srai?color=%2334D058&label=pypi%20package&logo=pypi&logoColor=%23fff" alt="Package version"></a> <a href="https://pypi.org/project/srai" target="_blank"><img src="https://img.shields.io/pypi/pyversions/srai.svg?color=%2334D058&logo=python&logoColor=%23fff" alt="Supported Python versions"></a> <a href="https://pypi.org/project/srai" target="_blank"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/srai"></a> <a href="https://huggingface.co/kraina" target="_blank"><img alt="HuggingFace" src="https://img.shields.io/badge/Hugging_Face-Kraina-FFD21E?logo=huggingface"></a> </p>

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.

<p align="center"> <img src="https://drive.google.com/thumbnail?id=1iyajkX81PLrel-Xmz1lQpYQvePnLoO1U&sz=s1024" style="max-width:600px;width:100%"/> </p>

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 srai components
  • 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.

<p align="center"> <img src="https://raw.githubusercontent.com/kraina-ai/srai/main/docs/assets/images/london_airbnb.png" style="max-width:600px;width:100%"/> </p>

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 dependencies
  • srai[osm] - dependencies required to download OpenStreetMap data
  • srai[overturemaps] - dependencies required to download Overture Maps data
  • srai[datasets] - dependencies required for downloading datasets
  • srai[voronoi] - dependencies to use Voronoi-based regionalization method
  • srai[gtfs] - dependencies to process GTFS data
  • srai[plotting] - dependencies to plot graphs and maps
  • srai[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 counts
  • OSMPbfLoader - 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

View on GitHub
GitHub Stars358
CategoryData
Updated1d ago
Forks28

Languages

Python

Security Score

100/100

Audited on Mar 25, 2026

No findings