Skip to main content

@math.gl/dggs

From-v4.0

@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 pathDecoderCell identifierClassification
@math.gl/dggs/decodersShared decoder APIVaries by gridRegistry
@math.gl/dggs/a5A5DecoderHexadecimal string or bigintDGGS
@math.gl/dggs/geohashGeohashDecoderStringDGGS-like geocode
@math.gl/dggs/h3H3DecoderHexadecimal string or bigintDGGS
@math.gl/dggs/plus-codePlusCodeDecoderFull string codeDGGS-like geocode
@math.gl/dggs/quadkeyQuadkeyDecoderStringDGGS-like tile hierarchy
@math.gl/dggs/s2S2DecoderToken string or bigintDGGS

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​

FeatureSupportNotes
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.