npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@high-u/quadkeytools

v0.0.2

Published

Simple quadkey tools library for fast geospatial processing

Downloads

4

Readme

quadkeytools

Forked

Forked from https://bitbucket.org/steele/quadkeytools/src/master

Describe

A library to calculate unique keys that represent tiles in a quadtree grid for geo-coordinates. We will call these unique keys quadkeys. This was based off code put out by the Bing maps team http://msdn.microsoft.com/en-us/library/bb259689.aspx

About

Projection

In order to map a 2D plane on to the globe you have to use projection. This library uses Mercator projection. Which looks like this:

Mercator Projection Image

Detail Level

Once the globe is projected on to a 2D plane we can cut it up into quadrants then quadruple it's area and cut each quadrant into subquadrants. Each time the plane is increased in size we increase the detail level of each quadrant.

QuadkeyTools

Every time we increase the detail level we mark each subquadrant with a 0, 1, 2, or 3. Looks something like this:

Quadtree

Installation

npm install quadkeytools

Usage

locationToQuadkey( location, detail )

Get the quadkey for lat,lng at a specific detail

import { locationToQuadkey } from "quadkeytools";
const location = { lat: 40.01234, lng: -160.02324 };
const detail = 16;
const key = locationToQuadkey(location, detail);

bbox( quadkey )

Get the bounding box for a quadkey. Detail level is inferred by the length of the key.

import { bbox } from "quadkeytools";
const key = '11002122';
const bbox = bbox(key);

origin( quadkey )

Get the center origin lat,lng of a quadkey

import { origin } from "quadkeytools";
const key = '12332110';
const origin = origin(key);

inside( location, quadkey )

Check if a lat,lng is within the bounds of a quadkey. Returns true if the location is inside the quadkey and false otherwise. Detail level is inferred by the size of the key.

import { inside } from "quadkeytools";
const key = '00231211';
const location = { lat: 40.01234, lng: -160.02324 };
const isInside = inside(location, key);

children( quadkey )

Get all the children of a quadkey. This will return an array of keys representing the subquadrants at the next detail level.

import { children } from "quadkeytools";
const key = '0123332111';
const children = children(key);

sibling( quadkey, direction )

Get a sibling of a quadkey. This will return the key of a sibling in a particular direction. Directions can be 'left' 'right' 'up' or 'down'.

import { sibling } from "quadkeytools";
const key = '001';
const sibling = sibling(key, 'left');

parent( quadkey )

Get the parent of a quadkey. This will return the quadkey that represents the parent quadrant in the previous detail level.

import { parent } from "quadkeytools";
const key = '0012223';
const parent = parent(key);

locationToPixel( location, detail )

Convert lat,lng to pixel coordinates. Note - Pixel coordinates are Integers so precision will be lost.

import { locationToPixel } from "quadkeytools";
const location = { lat: 40.01234, lng: -160.02324 };
const detailLevel = 10;
const pixel = locationToPixel(location, detailLevel);

pixelToLocation( pixel, detail )

Convert pixel coordinates to lat,lng.

import { pixelToLocation } from "quadkeytools";
const pixel = { x: 14547, y: 99231 };
const location = pixelToLocation(pixel, 10);

pixelToTile( pixel )

Convert pixel coordinates to tile coordinates

import { pixelToTile } from "quadkeytools";
const pixel = { x: 14547, y: 99231 };
const tile = pixelToTile(pixel);

tileToPixel( tile )

Convert tile coordinates to pixel coordinates

import { tileToPixel } from "quadkeytools";
const tile = { x: 12, y: 200 };
const pixel = tileToPixel(tile);

tileToQuadkey( tile, detail )

Convert tile coordinates to a quadkey at a specific detail level

import { tileToQuadkey } from "quadkeytools";
const tile = { x: 220, y: 45 };
const detail = 10;
const key = tileToQuadkey(tile, detail);

quadkeyToTile( quadkey )

Get the tile coordinates of a quadkey. This will be the coordinates of the corner of the quadkey.

import { quadkeyToTile } from "quadkeytools";
const key = '000123220';
const tile = quadkeyToTile(key);

tileToLocation( tile, detail )

Get the lat,lng coordinates of a tile's corner for a specific detail level.

import { tileToLocation } from "quadkeytools";
const tile = { x: 220, y: 12 };
const detail = 4;
const location = tileToLocation( tile, detail );