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

nontree

v0.4.1

Published

geohash (ish) nontree (9-tree) spatial indexing for GeoJSON

Downloads

63

Readme

NonTree

An experiment in spatial indexing ternary geohash in other words instead of a quad tree, a nontree. Instead of using a 2x2 grid each level we use a 3x3 one we use a modified hilbert curve which I'll be calling a 'hilbertish curve'.

Points are storied by finding the full key for the point, multipoints have a key inserted for each point, and line and polygon features are broken up into a number of bboxen which cover it.

References

API

var NonTree = require(nontree);
var nonTree = new NonTree({
  range: [-180, -90, 180, 90]
  precision: 10
  maxPieces: 20;
})
  • range is the size of the coordinates space to divide up, defaults to the world, change it if your not using lat longs
  • precision refers to the number of digits in length the hash should be
  • maxPieces refers to the maximum number of pieces that a polygon or line should be broken up into.
nonTree.encode([x, y]);

takes an point expressed in geojson style [x, y] (e.g. [lng, lat]) returns a geohash.

nonTree.decode(hash, returnMidpoint);

Takes a hash and an optional argument returnMidpoint, if returnMidpoint is falsy or absent then a bbox of the form [xmin, ymin, xmax, ymax] which the hash represents is returned. If returnMidpoint is truthy then a point of the form [x, y] which represents the midpoint of the geohash is returned.

nonTree.encodeFeature(feature);

Takes a geojson feature or geometry and returns an array of hashes.

nonTree.toRange(array);

Takes a hash or array of geohashes and returns the ranges they represent in the form of an array of object with start and end prosperities note that the end is noninclusive, so nonTree.toRange('ab'); returns [{start: 'ab', end: 'ac'}]. Adjastent ranges are merged so nonTree.toRange(['ab', 'di', ac]); would return [[{start: 'ab', end: 'ad'}, {start: 'di', end: 'e'}]

nonTree.query(array, hash);

Takes an array of hashes and a hash, tests if the has is covered by any of the hashes in the array, returns a boolean.

Hibertish Curves

A basic set of 9 tiles is arranged as follows

1  2  3
6  5  4
7  8  9

you can think of this as a set of directions

⟶  ⟶  ↓
↓   ⟵  ⟵
⟶  ⟶  ⟶

you want it to line up so that the first tile of the next block lines up with the last one of this one, so the next tile needs to be

⟶  ⟶  ↓    ⟶  ⟶  ⟶
↓   ⟵  ⟵   ↑   ⟵  ⟵
⟶  ⟶  ⟶   ⟶  ⟶   ↑

for a whole set of 9 blocks is

⟶  ⟶   ↓   ⟶  ⟶  ⟶   ⟶  ⟶   ↓   
↓   ⟵  ⟵   ↑   ⟵  ⟵   ↓   ⟵  ⟵
⟶  ⟶  ⟶   ⟶  ⟶   ↑   ⟶  ⟶   ↓

↓   ⟵  ⟵   ⟵  ⟵  ⟵   ↓   ⟵  ⟵   
⟶  ⟶   ↓   ⟶  ⟶   ↑   ⟶  ⟶   ↓
↓   ⟵  ⟵   ↑   ⟵  ⟵   ⟵  ⟵  ⟵

⟶  ⟶   ↓   ⟶  ⟶  ⟶   ⟶  ⟶   ↓   
↓   ⟵  ⟵   ↑   ⟵  ⟵   ↓   ⟵  ⟵
⟶  ⟶  ⟶   ⟶  ⟶   ↑   ⟶  ⟶   ↓

you can represent this more compactly by symbolizing each block as an arrow

↘↗↘
↙↖↙
↘↗↘

and this pattern extends all the way down by the simple rule of flipping the middle column on it's horizontal axis and flipping the middle row on its vertical axis, the middle square ends up getting flipped twice (equivalent to being rotated 180 degrees).

↘↗↘  ↗↘↗⟶↘↗↘
↙↖↙  ↖↙↖  ↙↖↙
↘↗↘⟶↗↘↗  ↘↗↘
             ↓
↙↖↙⟵↖↙↖  ↙↖↙
↘↗↘  ↗↘↗  ↘↗↘
↙↖↙  ↖↙↖⟵↙↖↙
↓
↘↗↘  ↗↘↗⟶↘↗↘
↙↖↙  ↖↙↖  ↙↖↙
↘↗↘⟶↗↘↗  ↘↗↘