@math.gl/dggs
@math.gl/dggs provides a deliberately small JavaScript API for decoding cell geometry from A5, GeoHash, H3, Quadkey, S2, and full Google Plus Code identifiers. It also detects their conventional data-column names so visualization layers such as deck.gl-community's GlobalGridLayer can select the appropriate decoder.
It is not a general abstraction over the full API surface of DGGS implementations. Applications that need parent/child traversal, neighbors, fills, compaction, metrics, or OGC API - DGGS support should use a full implementation or an abstraction such as DGGAL.
Usageβ
import {GeohashDecoder} from '@math.gl/dggs/geohash';
const polygon = GeohashDecoder.cellToBoundary(geohashId);
import {findDGGSCellColumn} from '@math.gl/dggs/decoders';
const match = findDGGSCellColumn(['name', 's2_token', 'value']);
// {columnName: 's2_token', decoder: S2Decoder}
Package subpathsβ
Import from @math.gl/dggs for shared types, the decoder registry, or column detection. If the grid is known in advance, use its decoder subpath.
| Import path | Decoder | Cell identifier | Classification |
|---|---|---|---|
@math.gl/dggs/decoders | Shared decoder API | Varies by grid | Registry |
@math.gl/dggs/a5 | A5Decoder | Hexadecimal string or bigint | DGGS |
@math.gl/dggs/geohash | GeohashDecoder | String | DGGS-like geocode |
@math.gl/dggs/h3 | H3Decoder | Hexadecimal string or bigint | DGGS |
@math.gl/dggs/plus-code | PlusCodeDecoder | Full string code | DGGS-like geocode |
@math.gl/dggs/quadkey | QuadkeyDecoder | String | DGGS-like tile hierarchy |
@math.gl/dggs/s2 | S2Decoder | Token string or bigint | DGGS |
Only full Plus Codes can be decoded without more context. Short Plus Codes are intentionally unsupported because recovering one requires a reference location.
Each decoder's name, hasNumericRepresentation, cellToLngLat, and cellToBoundary fields are structurally compatible with deck.gl-community's GlobalGridLayer. The remaining methods are small decoding conveniences; full grid algorithms stay in each system's native library.
S2 Cell Formatβ
S2 cells are identified by a 64Β bit index. The three most significant bits encode the cube face, followed by 60Β bits that encode the cell's position on the Hilbert curve. The least significant bit is always set and trailing zero bits indicate the level of the cell. When written in hexadecimal the trailing zeros are stripped; this representation is commonly referred to as the S2 token.
Featuresβ
| Feature | Support | Notes |
|---|---|---|
| Multi-grid cell centers and boundaries | β | A5, GeoHash, H3, Quadkey, S2 and full Plus Code decoders share a compact geometry interface. |
| String and supported numeric identifiers | β | Decoder-specific contracts distinguish strings, tokens and BigInt identifiers; numeric support is not uniform across grids. |
| Column-name discovery and decoder registry | β | Conventional column detection and DGGSDecoder integrate with visualization adapters. |
| Parent/child and neighbor traversal | β | The common decoder API does not expose the native gridsβ full hierarchy or neighborhood operations. |
| Polygon fills, covering and compaction | β | Use full H3/S2/A5 or other native grid APIs for covering, compaction and grid-specific topology. |
| Uniform cell metrics and analytical aggregation | β | No shared area/distance/aggregation engine is provided across all grid systems. |
| Short Plus Code recovery | β | Short codes require a reference location; only full codes are decoded. |
| OGC API - DGGS services | β | This is a geometry-decoding library, not a service/protocol implementation or a full DGGS abstraction. |
Installationβ
npm install @math.gl/dggs
Attributionβ
The A5 adapter uses a5-js, the H3 adapter uses h3-js, and the Plus Code adapter uses Google's open-location-code. These libraries are distributed under the Apache 2.0 license.
The S2Encoder object is based on a subset of the s2-geometry module under ISC License (ISC)
Copyright (c) 2012-2016, Jon Atkins github@jonatkins.com
Copyright (c) 2016, AJ ONeal aj@daplie.com
See Attributions for the project-wide source inventory and acknowledgments.