-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(geohash, quadkey): New geohash and quadkey modules (#319)
- Loading branch information
Showing
23 changed files
with
1,449 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# @math.gl/sun | ||
|
||
[math.gl](https://math.gl/docs) is a suite of math modules for 3D and geospatial applications. | ||
|
||
This module contains math for the GeoHash DGGS (Discrete Global Grid System). | ||
|
||
For documentation please visit the [website](https://math.gl). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Overview | ||
|
||
`@math.gl/geohash` is a JavaScript library with | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @math.gl/sun | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import {getGeohashPolygon} from '@math.gl/quadkey'; | ||
const polygon = getGeohashPolygon(geohash); | ||
``` | ||
|
||
## Attribution | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# geohash | ||
|
||
> TBA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@math.gl/geohash", | ||
"description": "Math for the GeoHash DGGS (Discrete Global Grid System)", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"version": "3.6.3", | ||
"keywords": [ | ||
"javascript", | ||
"math", | ||
"geospatial", | ||
"sun", | ||
"suncalc", | ||
"solar" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/uber-web/math.gl.git" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"main": "dist/es5/index.js", | ||
"module": "dist/esm/index.js", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"dependencies": { | ||
"@babel/runtime": "^7.12.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// math.gl, MIT license | ||
|
||
/* eslint-disable max-depth */ | ||
|
||
const BASE32_CODES = '0123456789bcdefghjkmnpqrstuvwxyz'; | ||
const BASE32_CODES_DICT: Record<string, number> = {}; | ||
for (let i = 0; i < BASE32_CODES.length; i++) { | ||
BASE32_CODES_DICT[BASE32_CODES.charAt(i)] = i; | ||
} | ||
|
||
const MIN_LAT = -90; | ||
const MAX_LAT = 90; | ||
const MIN_LON = -180; | ||
const MAX_LON = 180; | ||
|
||
// Adapted from ngeohash decode_bbox | ||
export function getGeohashBounds(geohash: string): number[] { | ||
let isLon = true; | ||
let maxLat = MAX_LAT; | ||
let minLat = MIN_LAT; | ||
let maxLon = MAX_LON; | ||
let minLon = MIN_LON; | ||
let mid: number; | ||
|
||
let hashValue = 0; | ||
for (let i = 0, l = geohash.length; i < l; i++) { | ||
const code = geohash[i].toLowerCase(); | ||
hashValue = BASE32_CODES_DICT[code]; | ||
|
||
for (let bits = 4; bits >= 0; bits--) { | ||
const bit = (hashValue >> bits) & 1; | ||
if (isLon) { | ||
mid = (maxLon + minLon) / 2; | ||
if (bit === 1) { | ||
minLon = mid; | ||
} else { | ||
maxLon = mid; | ||
} | ||
} else { | ||
mid = (maxLat + minLat) / 2; | ||
if (bit === 1) { | ||
minLat = mid; | ||
} else { | ||
maxLat = mid; | ||
} | ||
} | ||
isLon = !isLon; | ||
} | ||
} | ||
|
||
return [minLat, minLon, maxLat, maxLon]; | ||
} | ||
|
||
export function getGeohashPolygon(geohash: string): number[] { | ||
const [s, w, n, e] = getGeohashBounds(geohash); | ||
|
||
return [e, n, e, s, w, s, w, n, e, n]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {getGeohashBounds, getGeohashPolygon} from './geohash'; |
Oops, something went wrong.