# Terrain

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

Read elevation, slope, and aspect at points, along a line, or across an area.

Three queries read the ground itself, with no route involved: `terrainSamples` at points you know, `terrainProfile` along a line, and `terrainGrid` across an area. All three return the same sample: elevation in meters, slope in degrees, and the direction the slope faces.

## Set up

Every sample on this page reuses this setup. It mints a session token with your secret key, so run it on your server.

**cURL**

```bash
export MOUNTAYA_PUBLISHABLE_KEY="pk_your_publishable_key"
export MOUNTAYA_DATA_TOKEN=$(curl -s -X POST https://api.mountaya.com/v1/sessions \
  -H "X-API-Key: $MOUNTAYA_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"publishable_key\": \"$MOUNTAYA_PUBLISHABLE_KEY\"}" | jq -r .data.token)
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const publishableKey = process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "";
const secretKey = process.env.MOUNTAYA_SECRET_KEY ?? "";

const server = new Mountaya({ credential: { secretKey } });
const { data: session } = await new MountayaAdmin(server).sessions.postSession({
  body: { publishable_key: publishableKey },
});

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken: session.token },
});
```

**Python**

```python
import os
import requests

session = requests.post(
    "https://api.mountaya.com/v1/sessions",
    headers={"X-API-Key": os.environ["MOUNTAYA_SECRET_KEY"]},
    json={"publishable_key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"]},
    timeout=10,
).json()["data"]
```

## Samples at points

Read the ground at Chamonix and at the summit of Mont Blanc.

**cURL**

```bash
curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_DATA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query TerrainSamples($input: TerrainSamplesInput!) { terrainSamples(input: $input) { count coveredCount samples { point elevation slope aspectOctant steepnessBand } } }",
    "variables": {
      "input": { "locations": [[6.8712, 45.9231], [6.8650, 45.8326]] }
    }
  }'
```

**TypeScript**

```typescript
const readings = await mountaya.data.terrainSamples(
  {
    locations: [
      [6.8712, 45.9231],
      [6.865, 45.8326],
    ],
  },
  {
    select: {
      count: true,
      coveredCount: true,
      samples: {
        point: true,
        elevation: true,
        slope: true,
        aspectOctant: true,
        steepnessBand: true,
      },
    },
  },
);

for (const sample of readings.samples) {
  console.log(sample.point, sample.elevation);
}
```

**Python**

```python
query = """
query TerrainSamples($input: TerrainSamplesInput!) {
  terrainSamples(input: $input) {
    count coveredCount
    samples { point elevation slope aspectOctant steepnessBand }
  }
}
"""

result = requests.post(
    "https://data.mountaya.com/graphql",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
    },
    json={
        "query": query,
        "variables": {"input": {"locations": [[6.8712, 45.9231], [6.8650, 45.8326]]}},
    },
    timeout=30,
).json()

if "errors" in result:
    raise RuntimeError(result["errors"])
for sample in result["data"]["terrainSamples"]["samples"]:
    print(sample["point"], sample["elevation"])
```

**Response**

```json
{
  "data": {
    "terrainSamples": {
      "count": 2,
      "coveredCount": 2,
      "samples": [
        {
          "point": [6.8712, 45.9231],
          "elevation": 1037.6000000000006,
          "slope": 5.436244171334218,
          "aspectOctant": "EAST",
          "steepnessBand": null
        },
        {
          "point": [6.865, 45.8326],
          "elevation": 4801.800000000001,
          "slope": 18.393596328301967,
          "aspectOctant": "SOUTH",
          "steepnessBand": null
        }
      ]
    }
  }
}
```

Samples come back in the order you sent them. `steepnessBand` is set only from 25 degrees up, so both points here carry `null`.

> **Average by coveredCount, not by count**
>
> A point outside the elevation model comes back with `null` values. `count` is the points you asked for and `coveredCount` the points that have data, so divide sums by `coveredCount`.

## Profile along a line

Read the ground every kilometer on the straight line from Chamonix to Argentière.

**cURL**

```bash
curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_DATA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query TerrainProfile($input: TerrainProfileInput!) { terrainProfile(input: $input) { count coveredCount samples { distanceMeters elevation slope } } }",
    "variables": {
      "input": {
        "coordinates": [[6.8712, 45.9231], [6.9271, 45.9822]],
        "spacingMeters": 1000
      }
    }
  }'
```

**TypeScript**

```typescript
const profile = await mountaya.data.terrainProfile(
  {
    coordinates: [
      [6.8712, 45.9231],
      [6.9271, 45.9822],
    ],
    spacingMeters: 1000,
  },
  {
    select: {
      count: true,
      coveredCount: true,
      samples: { distanceMeters: true, elevation: true, slope: true },
    },
  },
);

for (const sample of profile.samples) {
  console.log(sample.distanceMeters, sample.elevation);
}
```

**Python**

```python
query = """
query TerrainProfile($input: TerrainProfileInput!) {
  terrainProfile(input: $input) {
    count coveredCount
    samples { distanceMeters elevation slope }
  }
}
"""

result = requests.post(
    "https://data.mountaya.com/graphql",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
    },
    json={
        "query": query,
        "variables": {
            "input": {
                "coordinates": [[6.8712, 45.9231], [6.9271, 45.9822]],
                "spacingMeters": 1000,
            }
        },
    },
    timeout=30,
).json()

if "errors" in result:
    raise RuntimeError(result["errors"])
for sample in result["data"]["terrainProfile"]["samples"]:
    print(sample["distanceMeters"], sample["elevation"])
```

**Response**

```json
{
  "data": {
    "terrainProfile": {
      "count": 9,
      "coveredCount": 9,
      "samples": [
        { "distanceMeters": 0, "elevation": 1037.6000000000006, "slope": 5.436244171334218 },
        { "distanceMeters": 983.1547318196226, "elevation": 1051.3000000000006, "slope": 1.2190580160833666 },
        { "distanceMeters": 1966.3094636406552, "elevation": 1060.2000000000007, "slope": 1.7242231086313489 },
        { "distanceMeters": 2949.4641954601093, "elevation": 1071.6000000000006, "slope": 1.219393890682155 },
        { "distanceMeters": 3932.6189272816146, "elevation": 1088.9000000000005, "slope": 1.724698145275401 },
        { "distanceMeters": 4915.773659101667, "elevation": 1159.7000000000007, "slope": 32.582660614011125 },
        { "distanceMeters": 5898.928390921725, "elevation": 1182.6000000000006, "slope": 3.1079888715479957 },
        { "distanceMeters": 6882.083122743601, "elevation": 1215.1000000000006, "slope": 9.742966980440148 },
        { "distanceMeters": 7865.237854563283, "elevation": 1244.8000000000006, "slope": 0.8630202026282467 }
      ]
    }
  }
}
```

Read each sample's `distanceMeters`: the spacing is a target, so samples land 983 m apart here, not 1,000. To profile a saved route, send its segment geometry as `coordinates`, each position reduced to `[longitude, latitude]`.

## Grid over an area

Read the ground on a regular grid to find high, steep, or north-facing terrain. This 2 by 2 grid covers the Mont Blanc summit area.

**cURL**

```bash
curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_DATA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query TerrainGrid($input: TerrainGridInput!) { terrainGrid(input: $input) { cols rows coveredCount cells { point elevation aspectOctant steepnessBand } } }",
    "variables": {
      "input": { "bbox": [6.85, 45.83, 6.89, 45.86], "cols": 2, "rows": 2 }
    }
  }'
```

**TypeScript**

```typescript
const grid = await mountaya.data.terrainGrid(
  { bbox: [6.85, 45.83, 6.89, 45.86], cols: 2, rows: 2 },
  {
    select: {
      cols: true,
      rows: true,
      coveredCount: true,
      cells: { point: true, elevation: true, aspectOctant: true, steepnessBand: true },
    },
  },
);

for (const cell of grid.cells) {
  console.log(cell.point, cell.elevation, cell.steepnessBand);
}
```

**Python**

```python
query = """
query TerrainGrid($input: TerrainGridInput!) {
  terrainGrid(input: $input) {
    cols rows coveredCount
    cells { point elevation aspectOctant steepnessBand }
  }
}
"""

result = requests.post(
    "https://data.mountaya.com/graphql",
    headers={
        "X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"],
        "X-Session-Token": session["token"],
    },
    json={
        "query": query,
        "variables": {"input": {"bbox": [6.85, 45.83, 6.89, 45.86], "cols": 2, "rows": 2}},
    },
    timeout=30,
).json()

if "errors" in result:
    raise RuntimeError(result["errors"])
for cell in result["data"]["terrainGrid"]["cells"]:
    print(cell["point"], cell["elevation"], cell["steepnessBand"])
```

**Response**

```json
{
  "data": {
    "terrainGrid": {
      "cols": 2,
      "rows": 2,
      "coveredCount": 4,
      "cells": [
        {
          "point": [6.859999999999999, 45.8525],
          "elevation": 3556.600000000001,
          "aspectOctant": "NORTH_EAST",
          "steepnessBand": "FROM_35_TO_40"
        },
        {
          "point": [6.88, 45.8525],
          "elevation": 4018.900000000001,
          "aspectOctant": "NORTH_WEST",
          "steepnessBand": null
        },
        {
          "point": [6.859999999999999, 45.8375],
          "elevation": 4284.400000000001,
          "aspectOctant": "NORTH_WEST",
          "steepnessBand": "FROM_40_TO_45"
        },
        {
          "point": [6.88, 45.8375],
          "elevation": 3864.000000000001,
          "aspectOctant": "NORTH_EAST",
          "steepnessBand": "FROM_35_TO_40"
        }
      ]
    }
  }
}
```

Cells run row by row from the north-west corner, each read at its center. `aspectOctant` and `steepnessBand` use the same values as the aspect and steepness map overlays.

## Elevation tile ceiling

Each query reads at most 256 elevation tiles. If a grid or a long profile is refused, use a smaller box, fewer cells, or a shorter line.

The sample (`TerrainSample`), on all three queries:

- `point`: echo of the sampled `[longitude, latitude]`.
- `elevation`: meters above sea level. `slope`: degrees. Both null outside DEM coverage.
- `aspect`: downhill compass bearing, 0 to 360, where 0 is north. Null outside DEM coverage, and null on flat ground, which has no downhill direction.
- `aspectOctant`: `aspect` as a compass octant: `NORTH` (337.5-22.5 degrees), `NORTH_EAST`, `EAST`, `SOUTH_EAST`, `SOUTH`, `SOUTH_WEST`, `WEST`, `NORTH_WEST`. Null whenever `aspect` is null.
- `steepnessBand`: `FROM_25_TO_30`, `FROM_30_TO_35`, `FROM_35_TO_40`, `FROM_40_TO_45`, or `ABOVE_45`. Null below 25 degrees and outside DEM coverage.
- `distanceMeters`: distance along the geometry from its start. Populated by `terrainProfile` only, and null in a `terrainSamples` or `terrainGrid` result.
- `aspectOctant` and `steepnessBand` use the same vocabulary as the aspect and steepness map overlays, so a value read here matches the legend a user sees on the map.

Every result:

- `count` (points asked for) and `coveredCount` (points the model could answer). A point outside DEM coverage comes back null rather than as a placeholder, so dividing a sum by `count` treats the gaps as zeros. Divide by `coveredCount`, and treat `coveredCount < count` as partial coverage worth reporting.
- `zoom` and `resolutionMeters`: the DEM tile zoom the reading was taken at (chosen by the server, the same for every request) and the ground distance one pixel covers there, so a reading can be reproduced later.

Elevation tile ceiling:

- Each query reads at most 256 distinct elevation tiles at zoom 14. The tiles are counted from the laid-out points before any is fetched: the locations of `terrainSamples`, the samples of `terrainProfile`, the cells of `terrainGrid`. Past the ceiling the query is a `VALIDATION_FAILED` at `["input", "locations"]`, `["input", "coordinates"]` or `["input", "bbox"]`, and nothing is read.
- The 100 locations `terrainSamples` accepts reach at most 100 tiles, so the ceiling binds the other two. A tile covers less ground toward the poles: a full 64 by 64 grid over 100 km² fits up to about 70 degrees of latitude, and nearer the poles it needs a smaller box or fewer cells.

`terrainSamples(input: TerrainSamplesInput!)`:

- `locations`: 1 to 100 `[longitude, latitude]` pairs; any other count is `VALIDATION_FAILED` at `["input", "locations"]`, and a malformed pair at `["input", "locations", i]`.
- `samples`: one entry per requested location, in the order sent.

`terrainProfile(input: TerrainProfileInput!)`:

- `coordinates`: 2 to 10,000 `[longitude, latitude]` pairs (otherwise `VALIDATION_FAILED` at `["input", "coordinates"]`; a malformed pair at `["input", "coordinates", i]`), along a line at most 500 km long measured along its positions. A longer line is `VALIDATION_FAILED` at `["input", "coordinates"]`, refused before any elevation is read. Exactly two numbers per position: reduce a saved segment's `[longitude, latitude, altitude]` positions first.
- `spacingMeters`: target sampling interval, 10 to 1000, default 100 (otherwise `VALIDATION_FAILED` at `["input", "spacingMeters"]`).
- `spacingMeters` is a target in both directions. Every input vertex is retained, so a sample immediately after a bend sits closer than the interval, and a line long enough to need more than 2,000 samples between its vertices is sampled coarser, so one profile holds at most 12,000 samples. Multiplying the index by `spacingMeters` places every sample after the first bend too far along: read `distanceMeters`.
- `TerrainProfileResult` has the same shape as `TerrainSamplesResult`, and its samples carry `distanceMeters`.

`terrainGrid(input: TerrainGridInput!)`:

- `bbox`: `[minLongitude, minLatitude, maxLongitude, maxLatitude]`, each minimum strictly below its maximum, both corners valid, area at most 100 km². A box that breaks any of these is `VALIDATION_FAILED` at or below `["input", "bbox"]`.
- `cols` and `rows`: 2 to 64 each, default 16 (otherwise `VALIDATION_FAILED` at `["input", "cols"]` or `["input", "rows"]`).
- `TerrainGridResult` returns the samples as `cells` rather than `samples`, and echoes `cols` and `rows`. Cells are in row-major order: the cell at (col, row) is at index `row * cols + col`. Row 0 runs along the northern edge and column 0 along the western edge, and each cell is read at its center.

## Next steps

- [Analysis](https://docs.mountaya.com/en/apis/data/analysis.md): Way type, slope, and travel time of a line.
- [Itineraries](https://docs.mountaya.com/en/apis/data/itineraries.md): Read a saved itinerary, then profile its segments.
