Project

neartree

0.0
No commit activity in last 3 years
No release in over 3 years
neartree is a Ruby library binding to the NearTree C library for storing point/value pairs in an R-Tree structure and searching it for the nearest neighbour for any given point.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

neartree¶ ↑

Ruby bindings for the NearTree C library¶ ↑

This project implements Ruby bindings for the NearTree C library. NearTree provides an R-Tree structure with fast nearest k-neighbour searches.

The NearTree C library is at:

neartree.sourceforge.net/

The bindings have only been tested on NearTree 2.3.2.

Usage¶ ↑

require 'neartree'

rtree = NearTree::RTree.new(2) # number of dimensions

# insert coordinates/value pair
# coordinates must be an array of Numeric objects
# The value can be any ruby object
rtree.insert([ 0.0,  0.0], 10.0) # coordinates, value
rtree.insert([ 2.0,  0.0],  2.0)
rtree.insert([-2.0, -2.0],  0.0)

rtree.find_nearest([  0.5, 0.5]) # => [[0.0, 0.0], 10.0]
rtree.find_nearest([100.0, 0.0]) # => [[2.0, 0.0], 2.0]

# coordinates, number_of_neighbours, radius
rtree.find_k_nearest([1.2, 0.5], 3, 2.0) # => [[[2.0, 0.0], 2.0], [[0.0, 0.0], 10.0]]
rtree.find_k_nearest([1.2, 0.5], 1, 2.0) # => [[[2.0, 0.0], 2.0]]