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

@parellin/geohash

v1.0.7

Published

Geohash decode/encoder

Downloads

11

Readme

@parellin/geohash

NPM

Geohash decode/encoder

| Precision | Width | Height | |:---------:|:-----------:|:-----------:| | 1 | ≤ 5,000km | × 5,000km | | 2 | ≤ 1,250km | × 625km | | 3 | ≤ 156km | × 156km | | 4 | ≤ 39.1km | × 19.5km | | 5 | ≤ 4.89km | × 4.89km | | 6 | ≤ 1.22km | × 0.61km | | 7 | ≤ 153m | × 153m | | 8 | ≤ 38.2m | × 19.1m | | 9 | ≤ 4.77m | × 4.77m | | 10 | ≤ 1.19m | × 0.596m | | 11 | ≤ 149mm | × 149mm | | 12 | ≤ 37.2mm | × 18.6mm |

Installation

npm i @parellin/geohash

Usage

Basic usage:

const Geohash = require( '@parellin/geohash' );
const hash = Geohash.encode( -77.480, 38.866, 7 ); // hash: 'dqbvhgk'

encode

Encodes longitude/latitude to geohash, either to specified precision or to automatically evaluated precision.

params

  • lng {number} Longitude in degrees.
  • lat {number} Latitude in degrees.
  • precision {number} Number of characters in resulting geohash.

returns: Geohash of supplied longitude/latitude.

const hash = Geohash.encode( -77.480, 38.866, 7 ); // hash: 'dqbvhgk'

decode

Decode geohash to longitude/latitude (location is approximate center of geohash cell, to reasonable precision).

params

  • geohash {string} Geohash string to be converted to longitude/latitude.

returns: (Center of) geohashed location.

const latlng = Geohash.decode( 'dqbvhgk' ); // latlng: { lng: -77.4804, lat: 38.8662 }

neighbors

Returns 8 adjacent cells to specified geohash.

params

  • geohash {string} Geohash to find neighbors of.
  • asObject {boolean} return geohashes in an object ({c,n,ne,e,se,s,sw,w,nw})

returns: surrounding geohashes

const latlng = Geohash.neighbors( 'dqcjpxetzh6q' );
[
	'dqcjpxetzh6r', 'dqcjpxetzh6x', 'dqcjpxetzh6w', 'dqcjpxetzh6t',
	'dqcjpxetzh6m', 'dqcjpxetzh6j', 'dqcjpxetzh6n', 'dqcjpxetzh6p'
]

Example:

Geohash.neighbors( 'dqcjpxetzh6q' );

           ┬────────────────────────────────────────────────────┐
           │      'west'          'center'         'east'       │
┼──────────┼────────────────────────────────────────────────────┤
│ 'north'  │   'dqcjpxetzh6p'  'dqcjpxetzh6r'  'dqcjpxetzh6x'   │
│ 'center' │   'dqcjpxetzh6n'  'dqcjpxetzh6q'  'dqcjpxetzh6w'   │
│ 'south'  │   'dqcjpxetzh6j'  'dqcjpxetzh6m'  'dqcjpxetzh6t'   │
┴──────────┴────────────────────────────────────────────────────┘

GeohashStream

GeohashStream takes in a BBox and streams geohashes within that bbox.

params

  • minLng {number} bbox min longitude
  • minLat {number} bbox min latitude
  • maxLng {number} bbox max longitude
  • maxLat {number} bbox max latitude
  • precision {number=7} geohash precision (defaults to 7)
new Geohash.GeohashStream( 0.1, 52.2, 0.2, 52.3, 3 )
	.on( 'data', d => console.log( d.toString() ) )
	.on( 'end', () => console.log( 'done' ) );

// u12

GeohashStreamGeoJSON

GeohashStreamGeoJSON is the same as GeohashStream but streams back GeoJSON

params

  • minLng {number} bbox min longitude
  • minLat {number} bbox min latitude
  • maxLng {number} bbox max longitude
  • maxLat {number} bbox max latitude
  • precision {number=7} geohash precision (defaults to 7)
new Geohash.GeohashStreamGeoJSON( 0.1, 52.2, 0.2, 52.3, 3 )
	.on( 'data', d => console.log( d.toString() ) )
	.on( 'end', () => console.log( 'done' ) );

// {
// 	"type": "Feature",
// 	"bbox": [ 0, 52.03125, 1.40625, 53.4375 ],
// 	"properties": {},
// 	"geometry": {
// 		"type": "Polygon",
// 		"coordinates": [ [
// 			[ 0, 52.03125 ],
// 			[ 1.40625, 52.03125 ],
// 			[ 1.40625, 53.4375 ],
// 			[ 0, 53.4375 ],
// 			[ 0, 52.03125 ]
// 		] ]
// 	}
// }