OSM_graph
Quickly generate isochrones for Python and Rust!
This library provides a set of tools for generating isochrones and reverse isochrones from geographic coordinates. It leverages OpenStreetMap data to construct road networks and calculate areas accessible within specified time limits. The library is designed for both Rust and Python, offering high performance and easy integration into data science workflows.

Features
- Graph Construction: Parses OpenStreetMap data to construct a directed graph representing the road network.
- Graph Simplification: Topologically simplifies the graph by collapsing linear chains and deduplicating parallel edges, reducing node/edge count by ~89% for faster downstream computation.
- Spatial Indexing: R-tree spatial index for O(log n) nearest-node lookups, built once and reused for all queries.
- Isochrone Calculation: Generates isochrones using a single Dijkstra traversal, with hull computation parallelized across time limits.
- Routing: A* point-to-point routing returning a GeoJSON LineString with distance, total duration, and cumulative travel times at each waypoint.
- Geocoding: Place-name to coordinate lookup via Nominatim.
- Concave and Convex Hulls: Supports convex, fast-concave, and concave hull types for isochrone shapes.
- Caching: Three-level cache (disk XML → in-memory XML → in-memory graph) so repeated queries for the same area skip the network entirely, persisting across process restarts.
- Python Integration: Python bindings for all core functionality — isochrones, routing, geocoding, and cache management.
- GeoJSON Output: All results returned as GeoJSON strings for easy integration with mapping tools and data science workflows.
Installation
To use the library in Rust, add it to your Cargo.toml:
[]
= "0.2.0"
For Python:
Or build from source with Rust and maturin installed:
Usage
Python
Isochrones
=
# Returns a list of GeoJSON geometry strings, one per time limit
Routing
=
# Returns a GeoJSON Feature (LineString) with properties:
# distance_m – total distance in metres
# duration_s – total travel time in seconds
# cumulative_times_s – travel time at each waypoint (parallel to coordinates)
Geocoding
, =
Points of interest
# Pass any isochrone string from calc_isochrones
=
# Returns a GeoJSON FeatureCollection; each feature carries raw OSM tags as properties
Cache management
# path to the on-disk XML cache
# clear both in-memory and disk caches
Rust
use ;
use NetworkType;
async
Performance
Benchmarks run on Munich road network, cached data only (no network I/O), Intel Core i7-11370H.
Compared against osmnx using a pre-enriched graph and a single Dijkstra pass — the fairest apples-to-apples comparison.
To reproduce: python benchmarks/comparison.py
| Radius | Nodes | Edges | pysochrone | osmnx | Speedup |
|---|---|---|---|---|---|
| 5,000m | 6,251 | 15,356 | 0.030s | 0.190s | 6.3× |
| 10,000m | 16,183 | 41,601 | 0.064s | 0.365s | 5.7× |
| 20,000m | 32,501 | 82,385 | 0.092s | 0.455s | 4.9× |
The ~5–6× gap reflects compiled Rust and petgraph's flat adjacency list vs pure-Python NetworkX. osmnx is a full-featured geospatial analysis library rather than a purpose-built isochrone engine — this comparison isolates the core Dijkstra computation to show what you gain from a compiled, cache-aware implementation.
pysochrone's caching model means graph construction and edge enrichment are one-time costs paid on the first query for an area. Subsequent queries reuse the in-memory graph directly, so the numbers above represent steady-state performance for repeated queries over the same region.

Roadmap
- Testing and benchmarks.
- Customizable Speed Limits: Allow users to specify custom speed limits for different road types.
- Support for Pedestrian and Bicycle Networks: Expand the graph construction to support pedestrian and bicycle network types.
- Topological simplification of osm graphs for more efficient downstream analytics.
- Additional Roadnetwork analytics.
- Routing engine.
- Advanced Caching Strategies: Implement more sophisticated caching mechanisms for dynamic query parameters.
- Interactive Visualization Tools: Develop a set of tools for interactive visualization of isochrones in web applications.
- API Integration: Provide integration options with third-party APIs for enhanced data accuracy and features.
- Optimization and Parallel Computing: Further optimize the graph algorithms and explore parallel computing options for large-scale data.
Contributing
Contributions are welcome! Please submit pull requests, open issues for discussion, and suggest new features or improvements.
License
This library is licensed under MIT License.