stefankoegl/kdtree
A Python implementation of a kd-tree
What it solves
This project provides a simple Python implementation of a kd-tree, a data structure used to organize points in k-dimensional space to facilitate efficient spatial searches, such as finding the nearest neighbor to a specific location.
How it works
The library allows users to create a tree from a list of points or start with an empty tree and add points individually. It supports various point formats, including tuples, lists, and custom objects that support indexing. The library provides methods to add, remove, and rebalance the tree to maintain efficiency, as well as tools to visualize the tree structure and traverse it in inorder or level order.
Who it’s for
Developers who need a lightweight, easy-to-use Python tool for managing multi-dimensional points and performing nearest-neighbor searches without needing a complex dependency chain.
Highlights
- Flexible Point Support: Works with tuples, lists, and custom indexable objects.
- Nearest Neighbor Search: Includes a built-in
search_nnmethod for fast spatial queries. - Tree Management: Supports adding, removing, and rebalancing nodes to keep the tree optimized.
- Payload Integration: Allows users to attach custom data payloads to points by using custom classes that emulate tuples.
Related
- Project
- Project
- Project
- Project