# Analysis

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

Classify the way type, paving and slope of a line you already have, and time it over that terrain.

`analyzeGeometry` reads a line you already have, such as a GPX track or a line drawn on a map. It tells you what kind of way each stretch follows, how steep it is, and how long the line takes to travel.

Every routed result already carries this analysis under `routes[].analysis`. Call `analyzeGeometry` for a line that came from somewhere else.

## 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"]
```

## Analyze a line

This line climbs a trail toward Montenvers, above Chamonix. Coordinates are `[longitude, latitude]`.

**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 AnalyzeGeometry($input: AnalyzeGeometryInput!) { analyzeGeometry(input: $input) { duration analysis { wayTypeInfo { fromIndex toIndex value } slopeInfo { fromIndex toIndex value } advisories { tollway restrictedAccess } } } }",
    "variables": {
      "input": {
        "activity": "HIKING_AND_TRAIL",
        "coordinates": [
          [6.91692, 45.93976], [6.91732, 45.93898], [6.91722, 45.93799],
          [6.91713, 45.93745], [6.91787, 45.93614], [6.91852, 45.9339],
          [6.91807, 45.93243], [6.91741, 45.93211], [6.91771, 45.93116],
          [6.91826, 45.92968]
        ]
      }
    }
  }'
```

**TypeScript**

```typescript
const analyzed = await mountaya.data.analyzeGeometry(
  {
    activity: "HIKING_AND_TRAIL",
    coordinates: [
      [6.91692, 45.93976],
      [6.91732, 45.93898],
      [6.91722, 45.93799],
      [6.91713, 45.93745],
      [6.91787, 45.93614],
      [6.91852, 45.9339],
      [6.91807, 45.93243],
      [6.91741, 45.93211],
      [6.91771, 45.93116],
      [6.91826, 45.92968],
    ],
  },
  {
    select: {
      duration: true,
      analysis: {
        wayTypeInfo: { fromIndex: true, toIndex: true, value: true },
        slopeInfo: { fromIndex: true, toIndex: true, value: true },
        advisories: { tollway: true, restrictedAccess: true },
      },
    },
  },
);

console.log(analyzed.duration, analyzed.analysis.wayTypeInfo);
```

**Python**

```python
query = """
query AnalyzeGeometry($input: AnalyzeGeometryInput!) {
  analyzeGeometry(input: $input) {
    duration
    analysis {
      wayTypeInfo { fromIndex toIndex value }
      slopeInfo { fromIndex toIndex value }
      advisories { tollway restrictedAccess }
    }
  }
}
"""

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": {
                "activity": "HIKING_AND_TRAIL",
                "coordinates": [
                    [6.91692, 45.93976], [6.91732, 45.93898], [6.91722, 45.93799],
                    [6.91713, 45.93745], [6.91787, 45.93614], [6.91852, 45.9339],
                    [6.91807, 45.93243], [6.91741, 45.93211], [6.91771, 45.93116],
                    [6.91826, 45.92968],
                ],
            }
        },
    },
    timeout=30,
).json()

if "errors" in result:
    raise RuntimeError(result["errors"])
analyzed = result["data"]["analyzeGeometry"]
print(analyzed["duration"], analyzed["analysis"]["wayTypeInfo"])
```

**Response**

```json
{
  "data": {
    "analyzeGeometry": {
      "duration": 3134.0508572402764,
      "analysis": {
        "wayTypeInfo": [
          { "fromIndex": 0, "toIndex": 7, "value": "PATH" },
          { "fromIndex": 7, "toIndex": 8, "value": "FOOTWAY" },
          { "fromIndex": 8, "toIndex": 9, "value": "PATH" }
        ],
        "slopeInfo": [
          { "fromIndex": 0, "toIndex": 1, "value": 11.8 },
          { "fromIndex": 1, "toIndex": 2, "value": 16.9 },
          { "fromIndex": 2, "toIndex": 3, "value": 24.2 },
          { "fromIndex": 3, "toIndex": 4, "value": 23.4 },
          { "fromIndex": 4, "toIndex": 5, "value": 16.7 },
          { "fromIndex": 5, "toIndex": 6, "value": 14.2 },
          { "fromIndex": 6, "toIndex": 7, "value": 27.9 },
          { "fromIndex": 7, "toIndex": 8, "value": -2.9 },
          { "fromIndex": 8, "toIndex": 9, "value": -8.9 }
        ],
        "advisories": {
          "tollway": false,
          "restrictedAccess": false
        }
      }
    }
  }
}
```

Each entry covers the positions from `fromIndex` to `toIndex` in the coordinates you sent. Slopes are in degrees, positive uphill. `duration` is the travel time in seconds over that ground, with the same model `directions` uses.

## What it classifies

| List | Each `value` |
| --- | --- |
| `wayTypeInfo` | The kind of way: `PATH`, `TRACK`, `FOOTWAY`, `STREET`, and more |
| `surfaceInfo` | What the way is paved with: `ASPHALT`, `GRAVEL`, `GROUND`, and more |
| `slopeInfo` | The slope in degrees |
| `trailDifficultyInfo` | The trail's difficulty grade |
| `speedInfo` | The travel speed the model gives that stretch, in km/h |

`advisories` reports any tollway or access-restricted way the line crosses. See [hazards and avoidance](https://docs.mountaya.com/en/apis/data/routing.md#hazards-and-avoidance).

> **Way and paving lists need a road-network activity**
>
> Only hiking and trail running, professional trail, running, and road cycling fill `wayTypeInfo`, `surfaceInfo` and `trailDifficultyInfo`. The winter activities still get slopes, speeds and a `duration`.

| Activity | API value | Wire form | Directions |
| --- | --- | --- | --- |
| Hiking and trail running | `HIKING_AND_TRAIL` | `hiking-and-trail` | Yes |
| Professional trail | `PROFESSIONAL_TRAIL` | `professional-trail` | Yes, off-network |
| Running | `RUNNING` | `running` | Yes |
| Road cycling | `ROAD_CYCLING` | `road-cycling` | Yes |
| Gravel biking | `GRAVEL_BIKE` | `gravel-bike` | Unavailable |
| Mountain biking | `MOUNTAIN_BIKE` | `mountain-bike` | Unavailable |
| Backcountry skiing | `BACKCOUNTRY_SKIING` | `backcountry-skiing` | Freehand line only |
| Ski touring | `SKI_TOURING` | `ski-touring` | Yes, off-network |
| Cross-country skiing | `CROSS_COUNTRY_SKIING` | `cross-country-skiing` | Yes |
| Snowshoe walking | `SNOWSHOE_WALKING` | `snowshoe-walking` | Yes |

Each routed activity uses a profile tuned to its terrain and movement style. Most activities support turn-by-turn routing, road cycling among them. Backcountry skiing is freehand-line only: no query routes it. Gravel biking and mountain biking are unavailable: the activity catalog does not list them, and every query refuses them, `analyzeGeometry` included. The GraphQL `ActivitySlug` enum uses the uppercase value; the Map Studio and Tile APIs use the kebab-case wire form, the same value lowercased with each underscore turned into a hyphen.

- `analyzeGeometry(input: AnalyzeGeometryInput!)` takes a required `activity`, which selects the profile used to interpret way and paving suitability, a required `coordinates` list, and an optional `speed`.
- `coordinates`: `[longitude, latitude]` pairs, between 2 and 10,000 positions, along a line at most 500 km long measured along its positions. A count outside that range or a longer line is `VALIDATION_FAILED` at `["input", "coordinates"]`, refused before any elevation or routing work. Each position is exactly two numbers, longitude -180..180 and latitude -90..90; otherwise `VALIDATION_FAILED` at `["input", "coordinates", i]`. A saved segment's positions carry altitude: reduce each to `[longitude, latitude]` first.
- `speed`: km/h on level ground, a finite number greater than 0 (anything else, NaN and Infinity included, is `VALIDATION_FAILED` at `["input", "speed"]`, never answered at the default). It re-anchors `duration` as it does on `directions`; each stretch's resolved speed is capped at the activity's maximum.
- `GeometryAnalysis` returns `elevation` (an `ElevationSummary`), `elevations`, the segment lists `surfaceInfo` (`value` a `SurfaceType` such as `ASPHALT`, `GRAVEL`, `DIRT`, `GROUND`, `UNPAVED`, `UNKNOWN`), `wayTypeInfo` (`value` a `WayType` such as `PATH`, `TRACK`, `FOOTWAY`, `STREET`, `ROAD`, `STEPS`), `trailDifficultyInfo`, `slopeInfo` (degrees, positive uphill, negative downhill), `speedInfo` (km/h), and `advisories` (`tollway`, `restrictedAccess`, `tollwayInfo`, `roadAccessInfo`, as the union over the whole line).
- Every list entry carries an inclusive `fromIndex` and `toIndex` into the `coordinates` you sent, so a classification maps back onto the exact part of the line it covers.
- `speedInfo`: what the model says each stretch is traveled at, given the activity's flat pace and the ground. Summing each stretch's length over its value reproduces `duration` exactly.
- `duration` sits beside `analysis` rather than inside it, because it belongs to the whole line. It is the travel time in seconds over the terrain analyzed, anchored on the activity's pace on level ground. `directions` and `suggestions` use the same model, so a drawn line and the routed segment it becomes agree.
- Way, paving and trail-difficulty classification needs a road-network profile, so it covers hiking and trail running, professional trail, running and road cycling only. For the four winter activities, `analyzeGeometry` still answers the elevation, slope and speed lists and the `duration`, and leaves the paving, way-type and trail-difficulty lists empty. Gravel biking and mountain biking are unavailable, and `analyzeGeometry` refuses them with `VALIDATION_FAILED` at `["input", "activity"]`. The Directions column of the activity table describes routing availability, a separate capability.
- Send a dense line, such as a GPX track's own points. When several ways fall between two of your positions, the analysis reports each at zero width on one index (`fromIndex` equal to `toIndex`), so a sparse line yields many entries that cannot be placed on it. Measured: a 9-point line over 6.9 km returned 18 way-type entries, 14 of them on indices 0 and 1.
- A stretch the routing engine fails to classify on Mountaya's side is reported as one `UNKNOWN` segment, as a stretch it has no data for is, and the field then carries an `INTERNAL_ERROR` entry in `errors` beside the analysis. Such a request is recorded as a failure (5xx) and counts toward neither the monthly allowance nor an invoice.
- The explorer carries the full `SurfaceType`, `WayType` and `TrailDifficultyType` value lists.

## Next steps

- [Routing](https://docs.mountaya.com/en/apis/data/routing.md): Routes that come with this analysis built in.
- [Terrain](https://docs.mountaya.com/en/apis/data/terrain.md): Elevation, slope, and aspect at points, along a line, or across an area.
