The quadbin-js is a TypeScript library for working with the Quadbin spatial index.
npm install quadbinimport {cellToParent, getResolution, hexToBigInt} from 'quadbin';
cellToParent(5210915457518796799n) // => 5206425052030959615n
getResolution(hexToBigInt('4830ffffffffffff')) // => 3A Quadbin index is a 64-bit integer. This library uses BigInt as a data type to represent quadbin indices, both as parameters and return values for functions.
When working with quadbin indices in other contexts (e.g. passing as a parameter in a URL or serializing as JSON), it is more appropriate to encode the index as a hexidecimal string. The library provides the bigIntToHex() & hexToBigInt() to facilitate this conversion.
function bigIntToHex(index: bigint): stringEncodes an index into a string, suitable for use in JSON.
function hexToBigInt(hex: string): bigintDecodes an string into an index. Inverse of bigIntToHex().
function getResolution(quadbin: bigint): bigintCalculates the resolution of a quadbin cell.
function cellToParent(quadbin: bigint): bigintCalculates the parent cell.
function cellToChildren(quadbin: bigint, resolution: bigint): bigint[]Calculates the child cells at given resolution.
function tileToCell(tile: {x: number, y: number, z: number}): bigintConverts a xyz tile into a quadbin cell.
function cellToTile(quadbin: bigint): TileConverts quadbin cell into a xyz tile.
function geometryToCells(geometry: GeoJSONGeometry, resolution: bigint): bigintfunction cellToBoundary(quadbin: Quadbin): PolygonConverts a Quadbin cell identifier into a geographical boundary represented as a polygon
function cellToOffset(quadbin: Quadbin): [number, number, number]Converts a Quadbin cell identifier into world coordinates offset values
function cellToWorldBounds(quadbin: Quadbin, coverage: number): [number[], number[]]Computes the world bounds (in Web Mercator coordinates) for a given Quadbin cell, taking into account the cell's coverage area
function getCellPolygon(quadbin: Quadbin, coverage = 1): number[]Generates the geographical polygon (in longitude and latitude) that represents the boundaries of a Quadbin cell, optionally taking into account coverage