Spatio is a fast, embedded spatial database designed for applications that need to store and query location-based data efficiently. Built with simplicity and performance in mind, Spatio provides a clean API for spatial operations without the complexity of traditional GIS systems.
Features
- Fast Key-Value Storage: High-performance in-memory operations with optional persistence
- Automatic Spatial Indexing: Geographic points are automatically indexed for efficient queries
- Spatial Queries: Find nearby points, check intersections, and query bounding boxes
- Trajectory Tracking: Store and query movement paths over time
- TTL Support: Built-in data expiration for temporary data
- Atomic Operations: Batch multiple operations for data consistency
- Thread-Safe: Concurrent read/write access without blocking
- Embedded: No external dependencies or setup required
- Simple API: Clean, focused interface that's easy to learn and use
Installation
Python
📦 PyPI: https://pypi.org/project/spatio
Rust
Add this to your Cargo.toml:
[]
= "0.1"
📦 Crates.io: https://crates.io/crates/spatio
Language Support
Spatio is available for multiple languages:
- Rust (native): High-performance, zero-cost abstractions
- Python: Easy-to-use bindings via PyO3
Quick Start
Python
# Create an in-memory database
=
# Store a simple key-value pair
# Store a geographic point (automatically indexed)
=
# Find nearby points within 100km
=
Rust
use ;
use Duration;
Examples
Run the included examples to see Spatio in action:
Getting Started
Spatial Queries
Trajectory Tracking
Comprehensive Demo
Use Cases
Location-Based Services
- Geofencing: Track when objects enter/leave geographic regions
- Proximity Search: Find nearby points of interest, users, or services
- Location Analytics: Analyze spatial patterns and relationships
Vehicle & Asset Tracking
- Fleet Management: Track vehicle locations and routes in real-time
- Delivery Optimization: Find nearest drivers or optimal delivery routes
- Movement Analysis: Analyze movement patterns and efficiency
IoT & Sensor Networks
- Environmental Monitoring: Track sensor data with geographic context
- Smart Cities: Manage spatially-distributed infrastructure
- Asset Management: Monitor equipment locations and status
Real-time Analytics
- Geospatial Dashboards: Build real-time location-aware applications
- Event Processing: Process location-based events with temporal context
- Spatial Aggregation: Compute statistics over geographic regions
API Overview
Core Operations
// Basic key-value operations
db.insert?;
let value = db.get?;
db.delete?;
Spatial Operations
let point = new;
// Insert point with automatic spatial indexing
db.insert_point?;
// Find nearby points
let nearby = db.find_nearby?;
// Check if points exist in region
let exists = db.contains_point?;
// Count points within distance
let count = db.count_within_distance?;
// Query bounding box
let in_bounds = db.find_within_bounds?;
let intersects = db.intersects_bounds?;
Trajectory Tracking
// Store movement over time
let trajectory = vec!;
db.insert_trajectory?;
// Query trajectory for time range
let path = db.query_trajectory?;
Atomic Operations
db.atomic?;
Time-to-Live (TTL)
// Data expires in 1 hour
let opts = with_ttl;
db.insert?;
Performance
Spatio is designed for high performance:
- In-memory operations with microsecond latency
- Automatic spatial indexing using efficient geohash algorithms
- Concurrent access with read-write locks
- Batch operations for high-throughput scenarios
- Optional persistence with append-only file format
Spatial Features
Automatic Indexing
Points are automatically indexed using geohash for efficient spatial queries:
- O(log n) insertion and lookup
- Efficient range queries
- Automatic neighbor finding
Distance Calculations
Built-in haversine distance calculations for accurate geographic distances:
let distance = point1.distance_to; // Returns meters
let nearby = point1.within_distance; // Within 1km
Bounding Box Operations
use BoundingBox;
let bbox = new;
let intersects = bbox.intersects;
Development
Building from Source
Running Tests
Running Benchmarks
Documentation
Architecture
Spatio uses a layered architecture:
- Storage Layer: In-memory B-trees with optional AOF persistence
- Indexing Layer: Automatic geohash-based spatial indexing
- Query Layer: Optimized spatial query execution
- API Layer: Clean, type-safe Rust interface
Status
Spatio is production-ready for embedded use cases. Current version: 0.1.0
Features
- Key-value storage with spatial indexing
- Geographic point operations
- Trajectory tracking
- TTL support
- Atomic operations
- Thread-safe concurrent access
- Comprehensive spatial queries
Roadmap
- Enhanced persistence with full AOF replay
- Performance optimizations
- Additional spatial data types
- Query optimization
Contributing
Contributions are welcome! Please read our Contributing Guidelines before submitting pull requests.
Development Setup
Links & Resources
Package Repositories
- PyPI: https://pypi.org/project/spatio
- Crates.io: https://crates.io/crates/spatio
Documentation & Source
- GitHub Repository: https://github.com/pkvartsianyi/spatio
- Rust Documentation: https://docs.rs/spatio
- Python Documentation: https://github.com/pkvartsianyi/spatio/tree/main/py-spatio
Community
- Issues & Bug Reports: https://github.com/pkvartsianyi/spatio/issues
- Releases & Changelog: https://github.com/pkvartsianyi/spatio/releases
License
MIT License (LICENSE-MIT)
Acknowledgments
- Built with the Rust ecosystem's excellent geospatial libraries
- Inspired by modern embedded databases and spatial indexing research
- Thanks to the Rust community for feedback and contributions