VII · Spatial structures

R-tree

A tree of bounding boxes.

The story

Guttman's R-tree organises rectangles (or higher-dim hyperrectangles) by their bounding boxes. Internal nodes hold the union bounding box of their children. Spatial queries skip whole subtrees whose bounding boxes don't intersect the query. Standard in every spatial database.

How it works

Each node holds up to M entries; each entry is (bounding box, child or data). Insert chooses the path with smallest area increase; splits when full. Variants: R*-tree (better split heuristic), R+-tree (no overlap), Hilbert R-tree (space-filling curve order).

Where it lives

PostGIS (default index). MySQL spatial types. Oracle Spatial. SpatiaLite. Almost every "find nearby" feature on a mapping product.

The key insight

R-trees handle extents (boxes, polygons, lines), not just points. That's the difference between "find restaurants within 5km" and "find every road that intersects this neighbourhood".