geohash-neighbours

finds the cells near a given geohash

NPM version Build Status

js-standard-style

Table Of Contents

Installation

With npm do

npm install geohash-neighbours

Status

Algorithm was written and implemented in few days: as a mathematician, I am confident it is right. It needs more test cases as well as users that try it and compare it to the method they are currently using. Your feedback will be welcome.

GeoHash format

The geoHash is given in binary format as a string of 0 1, so iterations look like the following

n=1

0 - 1

n=2

00 - 01
  ___/
 /
10 - 11

n=3

000 - 001 - 010 - 011
  _________________/
 /
100 - 101 - 110 - 111

n=4

0000 - 0001   0100 - 0101
   ____/    __/   ____/
  /        /     /
0010 - 0011   0110 - 0111
   ___________________/
  /
1000 - 1001   1100 - 1101
   ____/    __/   ____/
  /        /     /
1010 - 1011   1110 - 1111

API

neighboursOf(geoHash)

computes the cells near a given geohash

const neighboursOf = require('geohash-neighbours').neighboursOf
const geoHash = '0011'

console.log(neighboursOf(geoHash)) // [
                                   //   '0000', '0001', '0100'
                                   //   '0010',         '0110'
                                   //   '1000', '1001', '1100'
                                   // ]

eastOf(geoHash)

neighbour at east a given geohash, if any

const eastOf = require('geohash-neighbours').eastOf

console.log(eastOf('0000'))

northeastOf(geoHash)

neighbour at northeast a given geohash, if any

const northeastOf = require('geohash-neighbours').northeastOf

console.log(northeastOf('0000'))

northOf(geoHash)

neighbour at north a given geohash, if any

const northOf = require('geohash-neighbours').northOf

console.log(northOf('0000'))

northwestOf(geoHash)

neighbour at northwest a given geohash, if any

const northwestOf = require('geohash-neighbours').northwestOf

console.log(northwestOf('0000'))

westOf(geoHash)

neighbour at west a given geohash, if any

const westOf = require('geohash-neighbours').westOf

console.log(westOf('0000'))

southwestOf(geoHash)

neighbour at southwest a given geohash, if any

const southwestOf = require('geohash-neighbours').southwestOf

console.log(southwestOf('0000'))

southOf(geoHash)

neighbour at south a given geohash, if any

const southOf = require('geohash-neighbours').southOf

console.log(southOf('0000'))

southeastOf(geoHash)

neighbour at southeast a given geohash, if any

const southeastOf = require('geohash-neighbours').southeastOf

console.log(southeastOf('0000'))

License

MIT