Skip to content

Instantly share code, notes, and snippets.

@andrewharvey
Last active May 24, 2023 10:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewharvey/de265c3e5315cbb674488999d866d4c6 to your computer and use it in GitHub Desktop.
Save andrewharvey/de265c3e5315cbb674488999d866d4c6 to your computer and use it in GitHub Desktop.
Comparison of point and box spatial index libraries for JavaScript
Library Static / Dynamic Cartesian / Geographic kNN Index containing points Index containing boxes Within radius
rbush dynamic 🗺️ cartesian ✔️ ✔️
rbush-knn dynamic 🗺️ cartesian ✔️ ✔️ ✔️ ✔️
kdbush static 🗺️ cartesian ✔️ ✔️
geokdbush static 🌏 geo ✔️ ✔️ ✔️
flatbush static 🗺️ cartesian ✔️ ✔️ ✔️ ✔️
geoflatbush static 🌏 geo ✔️ ✔️ ✔️ ✔️

Definitions:

  • Static: All items must be added to the index initially, they cannot be modified once initialised.
  • Dynamic: Items in the index can be added and removed at any time
  • Cartesian: Operations an x, y Cartesian coordinates.
  • Geographic: Operations on geographic coordinates, lng, lat on a spheroid earth accounting for curvature of the earth and wrapping around the dateline.
  • kNN: Find the k (arbitrary number) of items closest to the query point
  • Index containing points: The index can contain points as items.
  • Index containing boxes: The index can contain rectangles or bounding boxes as items.
  • Within radius: Find all the items within a distance of the query point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment