JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2416338
  • Score
    100M100P100Q195221F

High-performance 2D spatial index for rectangles (based on R*-tree with bulk loading and bulk insertion algorithms)

Package Exports

  • rbush
  • rbush/rbush.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rbush) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

RBush

A high-performance JavaScript library for 2D spatial indexing of points and rectangles by Vladimir Agafonkin, based on R*-tree data structure with bulk loading and bulk insertion algorithms. A work in progress.

Roadmap

  • tree search
  • bulk loading (OMT)
  • single insertion (R*-tree)
    • choose subtree
      • optimize min-overlap calculation
    • reinsert
    • split
      • choose split axis
      • choose split index
    • recalculate bboxes
  • bulk insertion (seeded clustering)
  • single removal
  • bulk removal

Usage

Creating a Tree

var tree = rbush();

Bulk Load

Builds a tree with the given data (in [minX, minY, maxX, maxY] format) from scratch:

var tree = rbush().load([
    [10, 10, 15, 20],
    [12, 15, 40, 64.5],
    ...
]);

Bulk loading is much faster than adding data points one by one.

Adding and Removing Data

Not supported yet.

var result = tree.search([40, 20, 80, 70]);

Returns an array of data items (points or rectangles) that the given bounding box (in [minX, minY, maxX, maxY] form) contains.

Customizing

Max Fill

rbush accepts an optional maxFill argument which is a maximum number of entries in a tree node. Adjusting it can drastically affect performance depending on the type of data and search queries you perform.

var tree = rbush(20);

Data Format

By default, rbush assumes the format of data points as [minX, minY, maxX, maxY]. However you can customize this by redefining sortX, sortY and toBBox methods like this:

var tree = rbush();

tree.sortX  = function (a, b) { return a.minLng > b.minLng ? 1 : -1; };
tree.sortY  = function (a, b) { return a.minLat > b.minLat ? 1 : -1; };
tree.toBBox = function (a)    { return [a.minLng, a.minLat, a.maxLng, a.maxLat]; };

tree.load([{id: 'foo', minLng: 30, minLat: 50, maxLng: 40, maxLat: 60}, ...]);

Papers

License

This library is licensed under the MIT License.
Copyright (c) 2013 Vladimir Agafonkin.