Package Exports
- quadbin
- quadbin/dist/cjs/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (quadbin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
quadbin-js
The quadbin-js is a TypeScript library for working with the Quadbin spatial index.
Install
npm install quadbinUsage
import {cellToParent, getResolution, hexToBigInt} from 'quadbin';
cellToParent(5210915457518796799n) // => 5206425052030959615n
getResolution(hexToBigInt('4830ffffffffffff')) // => 3I/O types
A 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.
API
bigIntToHex
function bigIntToHex(index: bigint): stringEncodes an index into a string, suitable for use in JSON.
hexToBigInt
function hexToBigInt(hex: string): bigintDecodes an string into an index. Inverse of bigIntToHex().
getResolution
function getResolution(quadbin: bigint): bigint Calculates the resolution of a quadbin cell.
function cellToParent
function cellToParent(quadbin: bigint): bigint Calculates the parent cell.
tileToCell
function tileToCell(tile: {x: number, y: number, z: number}): bigintConverts a xyz tile into a quadbin cell.
cellToTile
function cellToTile(quadbin: bigint): Tile Converts quadbin cell into a xyz tile.
geometryToCells
function geometryToCells(geometry: GeoJSONGeometry, resolution: bigint): bigint Returns a list of cells covering a GeoJSON geometry at a given resolution