@earthgenome/majortom-ts
v1.0.0
Published
TypeScript implementation of the ESA Major TOM equal-area grid system
Readme
majortom-ts
A TypeScript implementation of the ESA Major TOM equal-area grid system. This is a port of the Python and Go implementations and produces bit-for-bit compatible cell IDs and geometries (validated by a shared cross-language reference dataset).
Installation
npm install @earthgenome/majortom-tsUsage
import { MajorTomGrid } from "@earthgenome/majortom-ts";
import type { Polygon } from "geojson";
// generate an overlapping grid with cells of 320m square
const grid = new MajorTomGrid(320, true);
// polygon 1/10 of a degree square
const aoi: Polygon = {
type: "Polygon",
coordinates: [
[
[0, 0],
[0, 0.1],
[0.1, 0.1],
[0.1, 0],
[0, 0],
],
],
};
// iterate over the cells that cover the area
for (const cell of grid.generateGridCells(aoi)) {
console.log(`cell id is ${cell.id()}`);
console.log(`cell geom is ${JSON.stringify(cell.geom)}`);
}API
new MajorTomGrid(d = 320, overlap = true)— create a grid with cell sized(meters) and optional half-cell overlap. Throws ifd <= 0.grid.generateGridCells(geom)— return theGridCell[]that intersect a GeoJSONPolygon,MultiPolygon, orFeature.grid.cellFromId(id)— resolve aGridCellfrom its (>=11 char) geohash ID.grid.migrateCellId(oldId)— map a cell ID from a prior grid version onto the current grid, returning the primary cell containing the decoded centroid.GridCell— hasgeom(GeoJSONPolygon),isPrimary(boolean), andid()(11-char geohash string).
Development
npm install
npm testLicense
Distributed under the terms of the MIT license.
