Code Monkey home page Code Monkey logo

rbush-knn-sphere's Introduction

rbush-knn-sphere

k-nearest neighbors search for RBush. Implements a simple depth-first kNN search algorithm using a priority queue, with spatial coordinates.

var RBush = require('rbush');
var knn = require('@sweco-se/rbush-knn-sphere');

var tree = new RBush(); // create RBush tree
tree.load(data); // bulk insert
var neighbors = knn(tree, 40, 40, 10); // return 10 nearest items around point [40, 40]

You can optionally pass a filter function to find k neighbors that satisfy a certain condition:

var neighbors = knn(tree, 40, 40, 10, function (item) {
    return item.foo === 'bar';
});

Or specify a maximum radius in metres to limit the search to:

var neighbors = knn(tree, 40, 40, 10, null, 1000);

API

knn(tree, x, y, [k, filterFn, maxDistance])

  • tree: an RBush tree
  • x, y: query coordinates
  • k: number of neighbors to search for (Infinity by default)
  • filterFn: optional filter function; k nearest items where filterFn(item) === true will be returned.
  • maxDistance (optional): maximum distance in metres between neighbors and the query coordinates (Infinity by default)

Changelog

@sweco-se/rbush-knn-sphere (forked repo):

4.0.0 (Jun 30, 2022)
  • Breaking: forked from original repo by @sefjod and renamed to @sweco-se/rbush-knn-sphere
  • Changed max distance calculation to support spatial coordinates

mourner/rbush-knn (original repo):

3.0.1 (Mar 19, 2020)
  • Breaking: fixed maxDistance argument โ€” now it's taken into account correctly (rather than being used as a max squared distance). h/t @AleksandarFaraj
  • Updated dependencies & compatibility with RBush v3.
2.0.0 (Jun 30, 2016)
  • Breaking: updated to be compatible with RBush 2.0.
  • Breaking: signature changed from tree, [x, y], k, filterFn to tree, x, y, k, filterFn
  • Improved performance by ~20%.
1.1.0 (Feb 29, 2015)
  • Add an optional filter function argument.
1.0.2 (Jun 25, 2015)
  • 2.5x performance improvement!
1.0.1 (Jun 10, 2015)
  • Fixed an error when requesting more items than the tree has. #1
1.0.0 (Apr 24, 2015)
  • Initial release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.