tracematch
High-performance GPS route matching library.
Features
- Route Matching - AMD-based polyline similarity with bidirectional detection
- Route Grouping - Cluster activities by route using Union-Find
- Section Detection - Multi-scale detection of frequently-traveled sections
- Spatial Indexing - R-tree for O(log n) viewport queries
- Parallel Processing - Optional rayon-based parallelism
Performance
Fast enough for real-time use on mobile devices. Benchmarked on real GPS traces (140-490 points per track):
| Operation | Time | What it means |
|---|---|---|
| Create signature | 10-16 µs | Process a 200-point track in 0.016ms |
| Compare two routes | 20-28 µs | Check similarity in 0.028ms |
| Group 20 routes | 750 µs | Cluster all routes in under 1ms |
Why it's fast:
- R-tree spatial indexing - O(log n) nearest-neighbor queries instead of O(n) linear scan
- Early exit - Dissimilar routes (different regions) detected in ~3 nanoseconds
- Rayon parallelism - Optional multi-core processing for large datasets
- Zero-copy design - Minimal allocations in hot paths
Run benchmarks: cargo bench --bench route_matching
Installation
How It Works
Route Matching compares two GPS tracks by measuring how far apart they are. For each point on route A, find the nearest point on route B and measure that distance. Average all these distances to get the AMD (Average Minimum Distance). Lower AMD means more similar routes. The comparison runs both directions (A→B and B→A) to detect if one route is a subset of another.
Route Grouping clusters multiple activities by similarity. Each activity starts in its own group. When two routes match, their groups merge using Union-Find (a fast algorithm for tracking connected components). The result: activities on the same route end up in the same group.
Section Detection finds frequently-traveled portions of tracks across many activities using spatial indexing (R-tree) and consensus algorithms.
Usage
Route matching
use ;
let london = vec!;
let nyc = vec!;
let config = default;
let sig1 = from_points.unwrap;
let sig2 = from_points.unwrap;
let sig3 = from_points.unwrap;
compare_routes; // Some(100% match, same)
compare_routes; // None (different routes)
london-1 vs london-2:
100% match (same)
london-1 vs nyc:
no match
Route grouping
use ;
// Two activities on the same route (London, ~1km)
let london: =
.map
.collect;
// One activity on a different route (NYC, ~1km)
let nyc: =
.map
.collect;
let config = default;
let sigs = vec!;
for group in group_signatures
// Output:
// monday: ["monday", "wednesday"]
// friday: ["friday"]
Configuration
All fields have sensible defaults. Adjust thresholds based on GPS accuracy and use case.
use MatchConfig;
let config = MatchConfig ;
References
Implemented algorithms:
-
Beckmann, N., Kriegel, H.-P., Schneider, R., & Seeger, B. (1990). The R*-tree: An efficient and robust access method for points and rectangles. Proceedings of the 1990 ACM SIGMOD International Conference on Management of Data, 322–331.
- Spatial indexing via rstar crate
-
Tarjan, R. E. (1975). Efficiency of a good but not linear set union algorithm. Journal of the ACM, 22(2), 215–225.
- Route grouping with path compression and union by rank
-
Douglas, D. H., & Peucker, T. K. (1973). Algorithms for the reduction of the number of points required to represent a digitized line or its caricature. Cartographica, 10(2), 112–122.
- Polyline simplification via geo crate
-
Kaufman, L., & Rousseeuw, P. J. (1987). Clustering by means of medoids. Statistical Data Analysis Based on the L₁-Norm and Related Methods, 405–416.
- Representative route selection (medoid concept; not full PAM)
Conceptual inspiration:
-
Lee, J.-G., Han, J., & Whang, K.-Y. (2007). Trajectory clustering: A partition-and-group framework. Proceedings of the 2007 ACM SIGMOD International Conference on Management of Data, 593–604.
- MDL principle for avoiding over-segmentation
-
Xu, W., & Dong, S. (2022). Application of artificial intelligence in an unsupervised algorithm for trajectory segmentation based on multiple motion features. Wireless Communications and Mobile Computing, 2022, 9540944.
- Two-phase segmentation-then-mergence pipeline
-
Yang, J., Mariescu-Istodor, R., & Fränti, P. (2019). Three rapid methods for averaging GPS segments. Applied Sciences, 9(22), 4899.
- Consensus polyline computation concepts
License
Apache-2.0