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

hyperlog-geopoint-index

v1.0.0

Published

Manage a geo-point store using data from a hyperlog.

Downloads

4

Readme

hyperlog-geopoint-index

Manage a geo-point store using data from a hyperlog.

Example

var hypergeo = require('hyperlog-geopoint-index')
var hyperlog = require('hyperlog')
var level = require('level')

var log = hyperlog(level('./log'), { valueEncoding: 'json' })

var kdb = hypergeo({
  log: log,
  db: level('./db'),
  geostore: level('./geo'),
  map: function (row, next) {
    if (row.value.type === 'point') {
      next(null, [ row.value.lat, row.value.lon ])
    } else next()
  }
})

if (process.argv[2] === 'add') {
  log.add(null, {
    type: 'point',
    lat: Number(process.argv[3]),
    lon: Number(process.argv[4])
  })
} else if (process.argv[2] === 'query') {
  var q = process.argv.slice(3).map(commaSplit)
  kdb.query(q, function (err, pts) {
    if (err) return console.error(err)
    pts.forEach(function (pt) {
      console.log(pt.point)
    })
  })
}

function commaSplit (s) { return s.split(',').map(Number) }
$ node log.js add 64.7 -147.9
$ node log.js add 66.2 -147.5
$ node log.js add 61.6 -148.3
$ node log.js query 60,65 -149,-146
[ 64.69999694824219, -147.89999389648438 ]
[ 61.599998474121094, -148.3000030517578 ]

API

var hypergeo = require('hyperlog-geopoint-index')

var geo = hypergeo(opts)

Create a spatial index of points over a hyperlog. These options are required:

  • opts.log - a hyperlog where data is written
  • opts.db - leveldb instance to store hyperlog+geo index data
  • opts.geostore - leveldb instance to store spatial index data
  • opts.map(row, next) - asynchronous function mapping hyperlog rows to points

Optional:

In the opts.map(row, next), if there are no points to map in a given row, call next() with a falsy value. Otherwise call next(err, rec) with a record:

  • rec.type - 'put' or 'del'
  • rec.point - array of coordinates

If rec is an array, it will be interpreted as a point in a 'put'.

geo.query(q, opts={}, cb)

Query for all points in the region described by q. This method is passed through to the underlying geopoint store's query method.

var r = geo.queryStream(q, opts={})

Return a readable stream r with the region described by q. This method is passed through to the underlying geopoint store's query method.

geo.ready(fn)

When the index has caught up with the latest known entry in the hyperlog, fn() fires.

log.add(links, doc, cb)

When you write to the hyperlog, the links should refer to the ancestors of the current doc which will be replaced with the new value.

When you create a new point, links should be any empty array [].

When you update an existing point, links should contain a list of immediate ancestors that the update will replace. Usually this will be a single key, but for merge cases, this can be several keys.

Install

npm install hyperlog-geopoint-index

Acknowledgments

This code forked from substack's hyperlog-kdb-index.

License

ISC