Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quadbin

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quadbin

Utility functions for working with Quadbins

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61K
decreased by-19.01%
Maintainers
0
Weekly downloads
 
Created
Source

quadbin-js

The quadbin-js is a TypeScript library for working with the Quadbin spatial index.

Install

npm install quadbin

Usage

import {cellToParent, getResolution, hexToBigInt} from 'quadbin';

cellToParent(5210915457518796799n) // => 5206425052030959615n
getResolution(hexToBigInt('4830ffffffffffff')) // => 3

I/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): string

Encodes an index into a string, suitable for use in JSON.

hexToBigInt

function hexToBigInt(hex: string): bigint

Decodes 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}): bigint

Converts 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 

cellToBoundary

function cellToBoundary(quadbin: Quadbin): Polygon 

Converts a Quadbin cell identifier into a geographical boundary represented as a polygon

cellToOffset

function cellToOffset(quadbin: Quadbin): [number, number, number]

Converts a Quadbin cell identifier into world coordinates offset values

cellToWorldBounds

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

getCellPolygon

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

Keywords

FAQs

Package last updated on 07 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc