Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jblindsay/kdtree

A pure Nim k-d tree implementation for efficient spatial querying of point data
https://github.com/jblindsay/kdtree

gis spatial-analysis spatial-data

Last synced: 3 months ago
JSON representation

A pure Nim k-d tree implementation for efficient spatial querying of point data

Awesome Lists containing this project

README

        

# kdtree

**Contents**

1. [Description](#1-description)
2. [Documentation](#2-documentation)
3. [Usage](#2-usage)

## 1 Description

**kdtree** is a pure Nim [k-d tree](https://en.wikipedia.org/wiki/K-d_tree) implementation. k-d trees are data structures for performing efficient spatial query operations on point data sets. This implementation is very flexible, allowing for nearest-neighbour (single and multiple), within-radius (circular search areas), and range (rectangular search areas) spatial queries.

## 2 Documentation

Documentation for `kdtree` can be found [here](https://jblindsay.github.io/kdtree/kdtree.html).

## 3 Usage

```nim
import random, strformat
import kdtree

# Generate 100,000 random points
let numPoints = 100_000
var
points = newSeqOfCap[array[2, float]](numPoints)
values = newSeqOfCap[int](numPoints)
x: float
y: float
r = initRand(34)

for a in 0.. 1:
tree.rebalance()

############################
# Spatial query operations #
############################

# Perform nearestNeighour searches
let numSearches = 10_000
for a in 0..