npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

level-geospatial

v0.0.6

Published

Geospatial indexing for leveldb

Downloads

54

Readme

level-geospatial

Uses a quadtree to index latitude and longitude coordinates in a leveldb database.

NPM

Project Status

Experimental - subject to change.

Install

$ npm install level-geospatial

How to use

The module takes a leveldb database (or a sub-level):

var db = require('level')('path_to_your_database');
var geo = require('level-geospatial')(db);

You can then start adding key/values, along with latitude/longitude values.

// lat, lon, key, value 
geo.put({lat:52.081959, lon:1.415904}, 'Location1', 'My value', function(err){
	if (err) console.log(err);
});

You can retrieve a value back like this:

// this is the fast way of getting the value
geo.get({lat:52.081959, lon:1.415904}, 'Location1',function(err,data){
	console.log(data);
});

// this is the slower/convenient way of getting the value
geo.getByKey('Location1', function(err,data){
	console.log(data);
});

// the data returned looks like this:
{ quadKey: '1222222212112112222210',
  position: {
    lat: 52.081959,    
    lon: 1.415904 },
  id: 'Location1',
  value: 'My value' }

You can search within a radius (in meters) of a given point:

// lat, lon, radius in meters
geo.search({lat:52.081959, lon:1.415904}, 15000).on('data', function(data){
	console.log(data)
});

// the data returned looks like this:
{ quadKey: '1222222212112112222210',
  position: {
    lat: 52.081959,    
    lon: 1.415904 },
  id: 'Location1',
  value: 'My value',
  distance: 1232.232323 }  // this is the distance in meters from your search

Please note, the results are not returned in any meaningful order.

You can update/delete like this:

// to update the value/location:
geo.put({lat:53.1, lon:2.2}, "Location1", "NEW VALUE", function(err){
	if (err) console.log(err);
});

// to delete
geo.del("Location1", function(err){
	if (err) console.log(err);
});

How does it work?

The data is indexed using a quadtree. When you index a point, it's quadkey is calculated to a depth of 22.

The quadkey is a string which stores where the point lives in the quadtree. The quadkey notation used is the same as Bing Maps. The quadkeys can be inserted into this URL to retrieve a map tile for a given location:

http://ak.dynamic.t1.tiles.virtualearth.net/comp/ch/{QUADKEY}?mkt=en-gb&it=G,VE,BX,L,LA&shading=hill&og=18&n=z

When you search the database, the quadkey is calculated for search location. The radius is then used to calculate an appropriate depth in the quadtree to search to.

Potential matches within those quads are then tested using a simple distance calculation to work out if they are close enough to be included in the results.

TODO

Currently searches that span the international date line will not return all results. Batch operations are not supported.

License

MIT