Coder Social home page Coder Social logo

node-level-z's Introduction

level-z

levelZ creates a sublevel db with the passed in name, that will insert items using their z-order index, so they can easily be queried by location. Items can still be retrieved efficiently by their primary id (this now requires 2 lookups rather than 1).

the new db has the following methods:

  • get: get entry by original id
  • put: insert an item by id, item should also have lat/long keys (items currently do not support being moved)
  • del: delete an item
  • createReadStream: default level readstream (note that keys are a z-order index, rather than insert key)
  • inBoundingBox: inBoundingBox: returns a stream of entries within (or close to) the bounding box. takes 1 arg: [[xMin, xMax], [yMin, yMax]]
var map = levelZ(db, 'map', {
  keys: ['long', 'lat'],
  bounds: [[-180, 180], [90, -90]]
})

var n = 0;
for (var i = -18; i <= 18; ++i) {
  for (var j = -9; j <= 9; ++j) {
    grid.put(n++, {
      long: i * 10,
      lat: j * 10,
      key: n,
      value: i * j
    })
  }
}

map.inBoundingBox([[-10, 10], [10,-10]]).on('data', function (location) {
  console.log(location)
})

Note: currently bounding box results are not filtered, so they may contain locations near the search area that are slightly outside the bounding box.

node-level-z's People

Contributors

hayes avatar

Stargazers

Vitaly Zadorozhny avatar Onlit avatar Aneil Mallavarapu avatar

Watchers

Vitaly Zadorozhny avatar  avatar

Forkers

onlit vitaly-z

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.