Spatial Data Structures

Spatial indexing structures for multi-dimensional data: k-d trees, R-trees, quadtrees, octrees, grid files, and space-filling curves (Z-order, Hilbert).

  • JSON9,282 B
  • YAML6,312 B · −32%
  • TOON5,454 B · −41%

Data structures for multidimensional and geographic data: k-d trees, R-trees, quadtrees, octrees, grid files and the Z-order and Hilbert space-filling curves, each with dimensions, query time, space, operations, uses and notes.

Use it when

  • You need nearest-neighbor, range or collision queries in two or more dimensions.
  • You are choosing a spatial index for a map, a game or a database.

Watch out for

  • Performance degrades in high dimensions; many structures work well only in two or three.
  • Choice depends on whether data is static or changes often.

The data

Structures

NameDimensionsQuery timeSpaceDescriptionOperationsUse casesNotes
k-d Tree (k-dimensional tree)Any kO(n^(1-1/k)) average for nearest neighborO(n)Binary tree alternating split axis at each level; partitions k-dimensional space
  • nearest neighbor
  • range search
  • k-nearest neighbors
  • 3D graphics (ray tracing acceleration)
  • Point cloud processing
  • Recommendation systems (k-NN)
  • Robotics path planning
Not suitable for high dimensions (curse of dimensionality); best for k ≤ 20
R-Tree2D/3D spatialO(log n) averageO(n)Balanced tree grouping nearby objects with minimum bounding rectangles (MBRs); optimized for disk storage
  • range search
  • nearest neighbor
  • spatial join
  • window query
  • GIS systems (PostGIS, SpatiaLite)
  • Location-based services
  • Game engines (collision detection)
  • Database spatial indexes
Variants: R*-tree (better split strategy), R+-tree (no overlap), STR-packed (bulk loading)
Quadtree2DO(log n) averageO(n)Recursive subdivision of 2D space into 4 quadrants; leaf nodes contain points or regions
  • point query
  • range search
  • nearest neighbor
  • region query
  • 2D game collision detection
  • Image compression (quadtree encoding)
  • Mesh generation
  • Sparse matrix storage
Point quadtree (stores points) vs region quadtree (stores areas); unbalanced without care
Octree3DO(log n) averageO(n)3D extension of quadtree; recursively subdivides space into 8 octants
  • point query
  • range search
  • frustum culling
  • collision detection
  • 3D game engines (Unreal, Unity)
  • Point cloud processing (LiDAR)
  • Voxel engines (Minecraft-like)
  • 3D mesh simplification
Essential for 3D spatial partitioning; often combined with frustum culling for rendering
Grid File2D/low-dimensionalO(1) for exact match, O(k) for rangeO(n + grid_size)Uniform grid overlaying space; each cell points to objects within it
  • point query
  • range search
  • nearest neighbor
  • Particle systems
  • Molecular dynamics
  • Simple collision detection
  • Real-time physics engines
Simple but suffers from curse of dimensionality; cell size critically affects performance
Z-Order Curve (Morton Order)Any kO(log n) with B-treeO(n)Maps multi-dimensional points to 1D by interleaving binary representations; preserves locality
  • range search via B-tree on Z-values
  • nearest neighbor
  • Geohashing (geographic indexing)
  • GPU spatial sorting
  • Database indexing (HBase, Accumulo)
  • Texture memory layout
Can use standard B-tree/B+-tree on Z-values; locality preservation not as good as Hilbert curve
Hilbert Curve2D (extendable)O(log n) with B-treeO(n)Space-filling curve with better locality preservation than Z-order; maps 2D to 1D continuously
  • range search
  • nearest neighbor via 1D index
  • Image processing
  • Database indexing (better locality than Z-order)
  • Distributed hash tables
  • Cache-oblivious algorithms
More complex to compute than Z-order but significantly better spatial locality; used in Google S2 Geometry

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
structuresnamestringk-d Tree (k-dimensional tree)
structuresdimensionsstringAny k
structuresquery_timestringO(n^(1-1/k)) average for nearest neighbor
structuresspacestringO(n)
structuresdescriptionstringBinary tree alternating split axis at each leve…
structuresoperationsarray[3 items]
structuresuse_casesarray[4 items]
structuresnotesstringNot suitable for high dimensions (curse of dime…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/spatial-data-structures?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/spatial-data-structures.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • spatial
  • kd-tree
  • rtree
  • quadtree
  • octree
  • space-filling-curves
  • geospatial
  • nearest-neighbor

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets