# Geo without a map

> Canonical URL: https://docs.mountaya.com/en/sdks/typescript/geo/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Measure distances, build elevation profiles, read slope and aspect, and convert units with the map-free entries of @mountaya/elements.

Four entries of `@mountaya/elements` do the maths a map does, with no map: `./geo`, `./profile`, `./units` and `./i18n`. They load no renderer and make no request, so they run on a server, in a worker, or in a test.

## Measure and format distances

```ts
import { haversineMeters } from "@mountaya/elements/geo";
import { formatDistance } from "@mountaya/elements/profile";

const chamonix: [number, number] = [6.8712, 45.9231];
const argentiere: [number, number] = [6.9271, 45.9822];

const meters = haversineMeters(chamonix, argentiere); // 7865.2…
formatDistance(meters, { language: "fr", length: "metric" }); // "7,9 km"
formatDistance(meters, { language: "en", length: "imperial" }); // "4.9 mi"
```

Positions are `[longitude, latitude]`, as GeoJSON writes them. Formatting follows the reader's language and units.

- `haversineMeters(a, b)` is the great-circle distance in meters on the mean sphere (`EARTH_RADIUS_METERS`). A position missing a coordinate answers `NaN`, never a distance to the equator.
- `metersToRoute(point, lines)` answers how far a point stands from the nearest of a set of `LineString`s, in meters; `distanceToSegmentMeters` is the same for one segment. `extractLineStrings(geometry)` flattens an itinerary's geometry into its lines first.
- An itinerary's geometry comes in more than one shape: a waypoint is a bare `Point`, a linestring segment a `LineString` or a `GeometryCollection` of that line and a `MultiPoint`, a directions segment a `GeometryCollection` of the routed line and its vias. `extractLineStrings`, `extractVias` and `flattenGeometries` read every shape. `boundsOf([geometry])` answers the `BoundingBox` a `fitBounds` takes, `[west, south, east, north]`, or `null`. The box around Chamonix and Argentière is `[6.80, 45.85, 7.00, 46.00]`, which MapLibre's `[[6.80, 45.85], [7.00, 46.00]]` spells corner by corner.
- `formatDistance(meters, { language, length }, format?)` writes a distance for a reader, in kilometers or miles; `formatNavDistance` writes a distance at a turn-by-turn scale: whole meters below a kilometer, then kilometers to two decimals (`300 m`, `8.65 km`), and whole feet below a tenth of a mile, then miles. `formatLngLat(position)` writes a position for a reader, or `null` for one that names no place. Every formatter answers `""` for an absent value, and reads a preference outside its union as the member `defaultUnits` holds.
- `@mountaya/elements/profile` re-exports `haversineMeters`, so a module already importing the profile maths needs no second entry.

## Build an elevation series

`buildElevationSeries` reads the third coordinate of each position into a profile:

```ts
import type { LineString } from "geojson";
import { buildElevationSeries, formatElevation, profileTotals } from "@mountaya/elements/profile";

const route: LineString = {
  coordinates: [
    [6.8712, 45.9231, 1035],
    [6.8936, 45.9829, 2352],
    [6.9271, 45.9822, 1252],
  ],
  type: "LineString",
};

const { ascent, descent, distance } = profileTotals(buildElevationSeries(route));
// ascent 1317, descent 1100, distance 9460.9…
formatElevation(ascent, { language: "en", length: "imperial" }); // "4,321 ft"
```

It takes a `Feature`, a `FeatureCollection` or a bare geometry, and ignores anything that is not a line.

- `buildElevationSeries(input, maxPoints?)` answers `{ points, totalDistance, hasElevation, minElevation, maxElevation }`: meters from the start against meters above sea level, `MultiLineString` and every line of a collection on one distance axis. A vertex with no third coordinate advances the distance and draws no point. The series is downsampled to `MAX_PROFILE_POINTS` by default.
- `profileTotals(series)` answers `{ distance, ascent, descent, elevationMin, elevationMax, gradeMax }`, each `null` where the series holds no elevation. Ascent and descent apply a noise hysteresis (`ELEVATION_NOISE_THRESHOLD_METERS`), because elevations sampled from a terrain model count every meter of sampling error twice: treat them as an estimate, and prefer the server's own figures where you hold them (an itinerary's `characteristics`).
- `elevationAt(series.points, distance)`, `gradeAt`, `detectClimbs` and `classifySteepness` read a series further; `itinerarySegmentRows` and `itineraryWaypointRows` are the rows the itinerary tables draw. The React `ItineraryProfile` is drawn on these same rules.

## Read the terrain at a point

From the heights around a point, `slopeAspectFromNeighbours` answers how steep the ground is and which way it faces:

```ts
import { aspectCardinal, slopeAspectFromNeighbours } from "@mountaya/elements/geo";
import { formatSlope } from "@mountaya/elements/profile";

// Heights in meters, 0.0001° north, south, east and west of a point at 45.9°N.
const { aspect, slope } = slopeAspectFromNeighbours(
  { east: 2401, north: 2404, south: 2400, west: 2403 },
  45.9,
  0.0001,
);

formatSlope(slope, { language: "en", slope: "degrees" }); // "12°"
aspectCardinal(aspect); // "SE"
```

From elevation tiles you have decoded, `terrainFromElevationTiles` answers the elevation, slope and aspect at a point in one call.

- `slopeAspectFromNeighbours(neighbours, latitude, spacingDegrees)` answers `{ slope, aspect }` in degrees: a central-difference gradient on the mean sphere, the east-west span shrunk by the cosine of the latitude. `aspect` is the compass bearing the ground falls towards, within `[0, 360)`, or `null` on flat ground. `aspectCardinal(degrees)` answers one of `N`, `NE`, `E`, `SE`, `S`, `SW`, `W`, `NW`, or `null`.
- `terrainFromElevationTiles(position, source, tiles)` answers `{ elevation, slope, aspect }` from tiles you already hold: `source` is `{ encoding, tileSize, zoom }` (the Tile API's elevation source, `encoding` `mapbox` or `terrarium`, `zoom` its `maxzoom`), and each tile is `{ x, y, z, rgba }`, the pixels a canvas decodes it into. `elevationTilesAt(position, source)` names the tiles a point needs. It answers `null` where a tile is missing, past Web Mercator's latitude, or for an encoding it cannot read. `decodeElevation(pixel, encoding)` reads one pixel.
- These rules fetch nothing. To ask the network instead, the Data API's terrain operations (`mountaya.data.terrainSamples`, `terrainProfile`, `terrainGrid`) answer the same readings with a session token, and `map.elevationAt(lngLat)` asks the Data API from a map. See [terrain](https://docs.mountaya.com/en/apis/data/terrain.md).

## Units and languages

```ts
import { resolveElementsStrings } from "@mountaya/elements/i18n";
import { frElementsStrings } from "@mountaya/elements/i18n/fr";
import { convertLength, convertSpeed } from "@mountaya/elements/units";

convertLength(1, "mile", "foot"); // 5280
convertSpeed(4.5, "kilometer-per-hour", "minute-per-kilometer"); // 13.33…, a 13:20 pace

const words = resolveElementsStrings("fr", undefined, { fr: frElementsStrings });
words.profile.ascent; // "Dénivelé +"
```

Every unit id is the one `Intl.NumberFormat` takes. English is built in, and each other language is an entry of its own.

- `@mountaya/elements/units` holds every unit conversion the SDK makes: `convertLength`, `convertSpeed` (paces included), `convertDuration`, `convertTemperature`, `convertSlope` (`degrees`, `percentage`, `ratio`), `convertProportion` (`ratio`, `percent`) and `convertDataSize`. Each takes a value and two unit ids and formats nothing. A conversion runs through the exact value that defines each unit. An unknown unit throws `MountayaElementsError` naming the conversion, the parameter and the units it accepts; a value converts as IEEE arithmetic does, so `NaN` stays `NaN`.
- `kilobyte` and `megabyte` are decimal; `kibibyte` and `mebibyte` binary (1,024), the units the API states its body ceilings in, which `Intl.NumberFormat` refuses as a `unit`: format a binary size as a plain number.
- A reader's units are a `UnitFormatOptions` (`language`, `length` `metric` or `imperial`, `pace`, `slope`, `temperature`); `defaultUnits` holds every field. `distanceUnitFor`, `elevationUnitFor` and `speedUnitFor` resolve the unit a preference asks for, as `convertLength(12_430, "meter", distanceUnitFor("imperial"))` (7.72…).
- `resolveElementsStrings(language, overrides, translations)` answers the elements' words in a language: English is built in, each other language is imported from its own entry (`@mountaya/elements/i18n/fr`), and a language asked for and not handed over reads in English and says so once in development. `translatedLanguages(translations)` answers what a language picker offers (`["en", "fr"]`). `MAP_LANGUAGES` lists the map label languages, and `dataLanguageFor` the language the Data API answers in for each.
- Which entries load no renderer: every subpath of `@mountaya/elements` but `./editor`, `./testing`, `./video` and `./view`. `./style` type-checks only with `maplibre-gl` installed, since its builders answer MapLibre style objects. The package root brings MapLibre: import these names from their subpath.

## Next steps

- [Turn-by-turn navigation](https://docs.mountaya.com/en/sdks/typescript/navigation.md): Follow a route with the same maths.
- [Show an elevation profile](https://docs.mountaya.com/en/sdks/typescript/elevation-profile.md): The profile drawn in React.
