PolyBush
Forked from KDBush:
A very fast static spatial index for 2D points based on a flat KD-tree. Compared to RBush:
- points only — no rectangles
- static — you can't add/remove items
- indexing is 5-8 times faster
const index = points; // make an indexconst ids1 = index; // bbox search - minX, minY, maxX, maxYconst ids2 = index; // radius search - x, y, radius
Install
Install using NPM (npm install polybush
) or Yarn (yarn add polybush
), then:
// import as a ES module; // or require in Node / Browserifyconst PolyBush = ;
Or use a browser build directly:
API
new PolyBush(points[, getX, getY, nodeSize, arrayType])
Creates an index from the given points.
points
: Input array of points.getX
,getY
: Functions to getx
andy
from an input point. By default, it assumes[x, y]
format.nodeSize
: Size of the -tree node,64
by default. Higher means faster indexing but slower search, and vise versa.arrayType
: Array type to use for storing coordinate values.Float64Array
by default, but if your coordinates are integer values,Int32Array
makes things a bit faster.
const index = points px py 64 Int32Array;
index.range(minX, minY, maxX, maxY)
Finds all items within the given bounding box and returns an array of indices that refer to the items in the original points
input array.
const results = index;
index.within(x, y, radius)
Finds all items within a given radius from the query point and returns an array of indices.
const results = index;
index.poly(polygon)
Finds all items within a given turf polygon
polygon = turf
index.multiPoly(multiPolygon)
Finds all items within a given turf multi-polygon
multiPolygon = turf; const results = index;
index.geoJSONFeature(polygon)
Finds all items within a given GeoJSON feature (polygon or multipolygon)
feature = type: 'Feature' geometry: type: 'Polygon' coordinates: 1000 00 1010 00 1010 10 1000 10 1000 00 properties: prop0: 'value0' prop1: this: 'that' ; const results = index;