geocomb-node
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha.0.1 • Public • Published

geocomb-node

welcome to geocomb-node, this project is a wrapper around geocomb-cpp so it can be used from node. It can convert locations to uniquiely identifiable hexagons for given resolutions, and vice versa.

how it works

geocomb generates points on the geocomb grid, which depends on 3 things: resolution, map orientation, and rotation method. The geocomb grid is broken up into rows and columns.

The points on a geocomb grid (GPoint3) store resolution, row, and column.

Based on some pretty nice relationships, hexagons/pentagons (phex, phexes) can be generated from points on a geocomb grid based on point row and col numbers, and this is how locations are stored: given a point, geocomb finds the phex that contains it for a given resolution, map orientation, and rotation method, and returns the HashProperties of that phex. HashProperties pretty much just contains info about a phex's center point, from which a phex or point can later be generated.

This means that geocomb can be used to store locations with hexagons, instead of traditional methods like geohashing which depend on rectangles. An other benefit is hexagons closely approximate circles, which can come in handy for findng locations withn a certain distance from other locations (burger restaurants within 5 km or something like that)

install

npm install geocomb --save

usage

phase 1: convert coordinates to hash properties

1. import

import { HashProperties, Icosahedron, Point3 } from "geocomb";

or

const geocomb = require("geocomb");
const Icosahedron = geocomb.Icosahedron;
const Point3 = geocomb.Point3;
const HashProperties = geocomb.HashProperties;

2. create Icosahedron object

// ┏→ map orientation (default is "ECEF")
// ┃ rotation method (default is "gnomonic") ←┓
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━┓         ┏━━━━━┛ 
const ico = new Icosahedron("ECEF", "gnomonic");

3. create point from coordinates

const lat = 71; // latitude  (must be in range [-90, 90])
const lon = 27; // longitude (must be in range [-180, 180])
const point = ico.pointFromCoords(lat, lon);

4. get geocomb hash properties for point (specifies hexagon locaion on geocomb grid for resolution)

const props = ico.hash(point, res);

hash properties store:

  • rm - rotation mathod
  • mo - map orientation
  • res - resolution
  • row - phex row
  • col - phex column

5. figure out way to store hash properties (sorry for this one lol)

geocomb doesn't have a default hash encoder/decoder yet

phase 2: convert hash properties back to coordinates

1. convert however you store hash properties to hash properties obj

you're on your own here, but it'll probably look something like this:

const props = functionThatConvertsObjToHashProperties(yourObj);

whatever is inside that function is your secret sauce

4. re-create icosahedron

in order to parse a hash, you need an icosahedron so, once again:

const ico = new Icosahedron("ECEF", "gnomonic");

Note: icosahedron map orientation and rotation method will override hash property map orientation and rotation method. This will most likely be fixed in an upcoming update, but for now just make sure to be consistent.

3. parse hash

const parsedPoint = ico.parseHash(props);

4. celebrate

that's pretty much it for storing and recovering locations. The returned point, parsedPoint, is a phex center for the given resolution.

Package Sidebar

Install

npm i geocomb-node

Weekly Downloads

0

Version

0.0.1-alpha.0.1

License

MIT

Unpacked Size

106 kB

Total Files

23

Last publish

Collaborators

  • shmibblez