Skip to main content

@math.gl/earth/geoid

From v3.4

The @math.gl/earth module evaluates geoid heights from Earth gravity model grids.

Usageโ€‹

import { parsePGM } from "@math.gl/earth/geoid";
import gridUrl from "@math.gl/earth/geoid-geoid-egm96-hi.pgm?url";

const response = await fetch(gridUrl);
if (!response.ok) throw new Error(`Grid request failed: ${response.status}`);
const geoid = parsePGM(new Uint8Array(await response.arrayBuffer()), {
cubic: true,
});
const N = geoid.getHeight(51.5, 0); // latitude, longitude; meters

Featuresโ€‹

FeatureSupportNotes
GeographicLib PGM grid parsingโœ…parsePGM decodes supported geoid grids without a renderer or Arrow runtime.
Bilinear and cubic interpolationโœ…Geoid samples grid heights with the documented units, wrapping and interpolation behavior.
Explicit ellipsoidal/orthometric height relationโœ…Geoid undulation N supports the model-specific relation h = H + N; applications select the correct datum/model.
Decoded-grid constructionโœ…createGeoidFromGrid accepts raw Uint16 samples, dimensions, offset and scale.
Optional EGM96 assets and other supplied gridsโœ…Bundled low/high EGM96 grids are separate assets; other supported PGM grids can be supplied by the application.
Automatic vertical-datum/epoch operation selectionโŒA grid sampler does not choose a valid vertical transformation, authority operation, epoch or source dataset.
Gravity potential, acceleration and magnetic fieldsโŒGrid undulation is implemented; coefficient-backed field synthesis remains separate Earth-model scope.
Global uncertainty or tide-system propagationโŒNo general uncertainty propagation, tidal synthesis, or automatic tide-system reconciliation is provided by the grid API.

Geoid globeโ€‹

Loading geoid globeโ€ฆ

Open the live example to rotate the globe, inspect signed heights, and compare grid resolutions and interpolation methods.

Geoid heightโ€‹

The geoid approximates an equipotential surface near mean sea level. Its height N relative to the WGS84 ellipsoid varies around the globe. It is not terrain elevation. Ellipsoidal height h and orthometric height H satisfy h = H + N. geoid.getHeight(latitude, longitude) returns N in meters.

Optional EGM96 dataโ€‹

Package exportGridSize
@math.gl/earth/geoid-geoid-egm96-low.pgm1ยฐ preview, 360 ร— 181130 KB
@math.gl/earth/geoid-geoid-egm96-hi.pgm15โ€ฒ original, 1440 ร— 7212.08 MB

Data remain separate from the JavaScript entry point. The low grid is downsampled for visualization; use the high grid for height conversion. The original grid's interpolation error estimates do not apply to the preview.

With a bundler supporting asset URL imports (such as Vite):

In Node.js, resolve the asset with import.meta.resolve('@math.gl/earth/geoid-geoid-egm96-hi.pgm') and read it using readFile from node:fs/promises. Other GeographicLib PGM grids can also be passed to parsePGM.

Decoded grid inputโ€‹

Use createGeoidFromGrid with a complete Uint16Array of raw samples, grid dimensions, offset and scale. Parquet decoding stays in the application; the geoid module requires no Arrow dependency.

Attributionโ€‹

NGA EGM96 model data are public domain. The grids come from GeographicLib; the package includes provenance, generation instructions, and checksum metadata in data/.

The JavaScript implementation is a port of selected GeographicLib 1.50.1 code, copyright Charles Karney, under the MIT license.

See Attributions for the project-wide source inventory and acknowledgments.