spatial-narrative spatial-narrative
Open Source Research Library

Spatiotemporal Event Analysis

A Rust library for modeling, indexing, and analyzing events that unfold across geographic space and chronological time. Built for researchers, digital humanists, and data scientists.

199 passed · 1 ignored
Unit Tests
8
Core Modules
5
I/O Formats
90–93%
ML F1 (model dependent)
Installation
cargo add spatial-narrative
With all features
cargo add spatial-narrative -F full
Quick Example
use spatial_narrative::prelude::*;

// Create a spatiotemporal event
let event = Event::builder()
    .text("Conference in Paris")
    .location(Location::new(48.8566, 2.3522))
    .timestamp(Timestamp::parse("2024-03-15")?)
    .build()?;

// Build a narrative collection
let mut narrative = Narrative::new("Research Trip");
narrative.add_event(event);

// Spatial query with R*-tree index
let nearby = index.nearest(&paris, 5);

// Extract entities from text
let entities = analyzer.extract_entities(text);

Flexible Event Representation

Events with WGS84 coordinates, multi-precision timestamps (year to second granularity), extensible metadata, and rich semantic tagging. Designed for heterogeneous historical and contemporary data.

Spatial Indexing

R*-tree and quadtree structures for efficient spatial queries. Nearest neighbor search, bounding box operations, and range queries with logarithmic complexity.

Text Processing

Pattern-based and ML-powered named entity recognition with BERT models via ONNX Runtime.

Movement Analysis

Trajectory simplification, speed calculation, stop detection, and clustering algorithms.

Format Support

Import and export JSON, GeoJSON, CSV, GPX tracks, and SQLite with full-text search.

Analysis Tools

DBSCAN and k-means clustering, temporal windowing, and statistical summaries.

Core Modules

Library Structure

coreLocation, Timestamp, Event, Narrative, GeoBounds — complete ✅
indexSpatialIndex (R-tree), TemporalIndex, SpatiotemporalIndex, Heatmap — complete ✅
graphNarrativeGraph, DOT export, pathfinding — complete ✅
analysisMovement (trajectory, stops), Clustering (DBSCAN, KMeans), Spatial & Temporal metrics — mature ✅
ioJSON, GeoJSON, CSV, (GPX optional), SQLite (optional, FTS) — adapters & examples
textTextAnalyzer, KeywordExtractor, Entity extraction; ML-based NER available via ml-ner feature (optional)
parserGeoParser, Gazetteer, Mention resolution (geoparsing)
transformCoordinate transforms, distance & bearing utilities

Algorithm Complexity

Haversine Distance O(1)
R*-tree Query O(log n)
DBSCAN Clustering O(n log n)
K-means Clustering O(k·n·i)
Digital Humanities
Historical events, literary geography, archival analysis
Social Science
Migration patterns, urban mobility, conflict studies
Journalism
Investigative research, fact-checking, data stories
Logistics
GPS track analysis, route optimization, delivery patterns
Fitness
Training analysis, route tracking, performance metrics
Personal
Photo organization, travel diaries, family history