Open a map app and search "coffee near me." Within milliseconds it returns a handful of cafés from a database of millions of places. How?
A naïve approach would scan every location and check its distance. For small datasets that works fine — but geography datasets contain billions of points, polygons, road segments, and building footprints. Scanning them all for every query would be catastrophically slow.
R-trees, introduced by Antonin Guttman in 1984, solved this with one elegant idea: group nearby objects into bounding rectangles, then group those rectangles into larger ones, building a hierarchy. A spatial query then descends the tree, pruning entire branches the moment their bounding box doesn't overlap the query region. Most of the index is never touched.
The key insight is that spatial data has locality — nearby things tend to stay nearby — and a good index exploits that locality to skip work. R-trees are the workhorse behind PostGIS, Oracle Spatial, SQLite's SpatiaLite, and virtually every GIS database on the planet.
Comments
Loading comments...