Coder Social home page Coder Social logo

mi-sec / geonet-geohash Goto Github PK

View Code? Open in Web Editor NEW
18.0 5.0 0.0 1.14 MB

Geohash decode/encoder based on the public domain geocoding system

Home Page: https://mi-sec.github.io/geonet-geohash/

License: MIT License

JavaScript 100.00%
geospatial geolocation geohash nodejs

geonet-geohash's Introduction

@geonet/geohash

NPM

coverage report

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 @geonet/geohash

Deployment
npm run lint
npm run test
rm -rf docs/ && npm run docs
npm run build
np

Usage

Basic usage:

const Geohash = require( '@geonet/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 ]
// 		] ]
// 	}
// }

geonet-geohash's People

Contributors

dependabot[bot] avatar iskore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

geonet-geohash's Issues

update documentation

Documentation is missing:

  • Readme for major methods
  • includeGeohashAsProperty
  • includeFeatureBBox
  • find other params not in the docs

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.