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

grid-point-store

v2.1.1

Published

Fast 2D point insertions and spatial querying over a fixed grid.

Downloads

16

Readme

grid-point-store

Fast 2D point insertions and spatial querying over a fixed grid.

Usage

var GeoStore = require('grid-point-store')
var memdb = require('memdb')

var store = GeoStore({
  store: memdb(),
  zoomLevel: 14
})

var pending = 10
var spread = 0.1  // ~10km
function insert () {
  if (!pending) return check()
  var x = Math.random() * spread - spread / 2
  var y = Math.random() * spread - spread / 2
  var loc = parseInt(Math.random().toString().substring(15))
  store.insert([y, x], loc, function (err) {
    pending--
    insert()
  })
}
insert()

function check () {
  var bbox = [ [ -1, 1 ], [ -1,  1 ] ]
  var q = store.queryStream(bbox)
  q.on('data', function (pt) {
    console.log('data', pt)
  })
}

outputs

data { point: 0.021974959554208737, -0.036042143780795316 }, value: 486 }
data { point: 0.01731653112725491, 0.04090562190958498 }, value: 398 }
data { point: -0.0059460250360946695, -0.027539338463307098 }, value: 3 }
data { point: -0.037361984139033334, -0.002493949477883839 }, value: 3795 }
data { point: -0.043988977366412524, -0.03764949331648002 }, value: 4426 }
data { point: -0.045367303981649724, -0.03634679567215611 }, value: 356 }
data { point: 0.023642309425643854, 0.017864021495420324 }, value: 81 }
data { point: -0.031037061354238983, 0.006035785956166738 }, value: 407 }
data { point: 0.03480660267412845, 0.032896501435967895 }, value: 46 }
data { point: 0.02960226742605787, 0.027872606373290573 }, value: 788 }

API

var GeoStore = require('grid-point-store')

var store = GeoStore(opts)

Create a new point store store backed by the LevelUP instance leveldb.

Valid opts include:

  • (required) store: an LevelUP compatible database instance.
  • (optional) zoomLevel (integer): an OSM-style zoom level to divide the world up by. zoomLevel == 1 captures the entire world in 1 tile, 2 in 4 tiles, 3 in 16 tiles, and so forth. Read more on OSM zoom levels.
  • (optional) types (Array[3]): a size-3 array of comparable storable type strings for the X and Y components, with the 3rd being the value format. Defaults to ['float64', 'float64', 'uint32'].

store.insert([x, y], value, cb)

Insert a point [x, y] with value value into the store.

cb is a callback that will be called as cb(err) if an error occurs, or cb(null) if the insertion succeeded.

store.query(bbox[, opts], cb)

Query a rectangular region for points. cb is called with the array of points in the region.

bbox is an array of arrays of the form

[
  [ minX, maxX ],
  [ minY, maxY ]
]

var stream = store.queryStream(bbox)

Query a rectangular region for points. Returns the Readable stream stream.

store.remove(pt[, opts], cb)

Deletes points at pt (a size-2 array of the form [x, y]).

Valid opts include

  • (optional) opts.value: Only delete points at this location with this specific value.

cb is a callback that will be called as cb(err) if an error occurs, or cb(null) if the deletion succeeded.

Caveats

  • Missing: stream backpressure on queryStream

PRs very welcome! :heart:

Install

With npm installed, run

$ npm install grid-point-store

See Also

License

ISC