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

@plotcheck/universal-plot-id

v1.1.2

Published

This code calcuates a unique ID for a GeoJSON polygon geometry. It can be used offiline, and does not require any form of online database.

Downloads

11

Readme

Universal Plot ID Generator

This code calcuates a unique ID for a GeoJSON polygon geometry. It can be used offiline, and does not require any form of online database.

Given a valid GeoJSON polygon like this:

{"type":"Polygon","coordinates":[[[-21.829992,-1.852858],[-21.829992,-13.022224],[-6.973366,-13.022224],[-6.973366,-1.852858],[-21.829992,-1.852858]]]}

you get this Universal Plot ID:

A7EEC333-76407A47-5A4F0F6C

This tool has the following goals:

  • Given the same boundary, it must generate the same ID every time
  • Even a small change in the boundary should result in a completely new ID
  • The boundary cannot be reverse engineered from the ID
  • The ID must be as user friendly as possible while remaining unique (mathematically unlikely that two boundaries would get the same ID even with billions of plots)
  • Option to increase the strength by adding an additional block e.g. A7EEC333-76407A47-5A4F0F6C-XXXXXXXX

Usage

Install

npm install @plotcheck/universal-plot-id
#or
pnpm add @plotcheck/universal-plot-id

Command line

npx tsx cli.ts <input.geojson> <output.geojson>

API

import { getUniversalPlotID } from '@maphubs/universal-plot-id'

const plotPolygon = {
  type: 'Polygon',
  coordinates: [
    [
      [-21.829992, -1.852858],
      [-21.829992, -13.022224],
      [-6.973366, -13.022224],
      [-6.973366, -1.852858],
      [-21.829992, -1.852858]
    ]
  ]
}
const id = getUniversalPlotID(plotPolygon)

Optional arguments

You can increase the size of they key, for example increasing to 128 will add an additional 8-character block to end of the IDs.

If you are creating billions of IDs, the chance of a collison (two plots having the same ID) will increase so you may want to use the longer ID

const bits = 128 // default is 96, can be up to 256 for SHA256
const id = getUniversalPlotID(plotPolygon, 128)

How it works

  • the geometry is standardized, coordinates are truncated to 6 decimal places, and the polygon is rewound for a consistent vertex order
  • only the geometry is used, any attributes or other metadata are ignored
  • the SHA256 hash alogorithm is used to generate a 256 bit hash which is then truncated to the requested size
  • the hash written as text in hexadecimal format, and split into 8-character sections to make it a bit easier to read.

Extending the ID

It may make the ID more useful to add additional information to beginning and end.

As a standard, we also support adding the 2-digit ISO country code and a local ID number to the end.

For example if the plot is in Malaysia and has a local id in our database as 1234, we may store it like this.

MY:A7EEC333-76407A47-5A4F0F6C:1234