Socket
Socket
Sign inDemoInstall

geokdbush

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geokdbush

A geographic extension for [KDBush](https://github.com/mourner/kdbush), the fastest static spatial index for points in JavaScript.


Version published
Weekly downloads
25K
increased by1.63%
Maintainers
0
Weekly downloads
 
Created
Source

geokdbush Node Simply Awesome

A geographic extension for KDBush, the fastest static spatial index for points in JavaScript.

It implements fast nearest neighbors queries for locations on Earth, taking Earth curvature and date line wrapping into account. Inspired by sphere-knn, but uses a different algorithm.

Example

import KDBush from 'kdbush';
import * as geokdbush from 'geokdbush';

const index = new KDBush(points.length);
for (conts {lon, lat} of points) index.add(lon, lat);
index.finish();

const nearestIds = geokdbush.around(index, -119.7051, 34.4363, 1000);

const nearest = nearestIds.map(id => points[id]);

API

geokdbush.around(index, longitude, latitude[, maxResults, maxDistance, filterFn])

Returns an array of the closest points from a given location in order of increasing distance.

  • index: kdbush index.
  • longitude: query point longitude.
  • latitude: query point latitude.
  • maxResults: (optional) maximum number of points to return (Infinity by default).
  • maxDistance: (optional) maximum distance in kilometers to search within (Infinity by default).
  • filterFn: (optional) a function to filter the results with.
geokdbush.distance(longitude1, latitude1, longitude2, latitude2)

Returns great circle distance between two locations in kilometers.

Performance

This library is incredibly fast. The results below were obtained with npm run bench (Node v20, Macbook Pro 2020 M1 Pro).

benchmarkgeokdbushsphere-knnnaive
index 138398 points57.6ms408msn/a
query 1000 closest1.6ms1.8ms72ms
query 50000 closest14.7ms91.5ms72ms
query all 13839833.7ms500ms72ms
1000 queries of 124.7ms27.5ms11.1s

FAQs

Package last updated on 01 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc