# Straight-line distance between places

> Index of the TerraLab docs for agents: [llms.txt](https://terra-lab.ai/docs/llms.txt). Every docs page is also served as markdown: add .md to its URL.

Straight-line geodesic distance between 2 or more places or points, with the midpoint and bearing for two, or the length of a line.

| | |
| --- | --- |
| REST | `POST https://mcp.terra-lab.ai/v1/tools/measure_distance` |
| MCP tool | `measure_distance` on `https://mcp.terra-lab.ai/mcp` |
| Group | Layer operations |

## Request

```bash
curl -X POST https://mcp.terra-lab.ai/v1/tools/measure_distance \
  -H "Authorization: Bearer $TERRALAB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"points":["Paris, France","Geneva, Switzerland"]}'
```

```python
import os
import requests

response = requests.post(
    "https://mcp.terra-lab.ai/v1/tools/measure_distance",
    headers={"Authorization": f"Bearer {os.environ['TERRALAB_API_KEY']}"},
    json={
        "points": ["Paris, France", "Geneva, Switzerland"],
    },
    timeout=120,
)
response.raise_for_status()
print(response.json()["structuredContent"])
```

```javascript
const response = await fetch('https://mcp.terra-lab.ai/v1/tools/measure_distance', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.TERRALAB_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "points": [
      "Paris, France",
      "Geneva, Switzerland"
    ]
  }),
});
const data = await response.json();
console.log(data.structuredContent);
```

Other valid request bodies:

```json
{"geometry":{"type":"LineString","coordinates":[[2.35,48.85],[2.36,48.86]]}}
```

## Parameters

A JSON object in the request body; in an MCP client, the arguments of the tool call.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `points` | array of string or object | No | Points or place names in order, 2 or more. The place the user asks about, not the user's own location. 2 to 500 items. |
| `geometry` | object | No | A drawn LineString or MultiLineString as GeoJSON (WGS 84 longitude, latitude), instead of points. |
| `geometry.type` | string | No |  |
| `geometry.coordinates` | array | No |  |
| `geometry.geometry` | object | No |  |
| `formats` | array of string | No | Download formats. Default `["geojson","kml"]`. |

## Response

`structuredContent` holds the result, `content` the same result as text for a model, and `isError` is `true` when the tool refused the request or failed; then `structuredContent.code`, `message` and `hint` say what to change.

```json
{
  "structuredContent": {
    "sources": [{ "name": "...", "licence": "...", "url": "..." }],
    "downloads": [{ "label": "...", "format": "...", "url": "...", "name": "..." }]
  },
  "content": [{ "type": "text", "text": "..." }],
  "isError": false
}
```

Every result lists its `sources` with their licence. File results come as `downloads`: each link builds its file when opened.

## Errors

A missing key answers `401`, an empty balance `402`, too many calls `429`. A call that fails or finds nothing is not counted. See [Errors and rate limits](https://terra-lab.ai/docs/errors).

## Description for agents

The text the server gives an agent to decide when to call this tool:

> Use this when the user wants the straight-line (as the crow flies) distance between 2 or more places or points, with the midpoint and bearing for two, or the length of a drawn line. Geodesic on the WGS 84 ellipsoid, in m, km and miles. Not a road or travel distance (get_route), not an elevation profile (get_elevation). Returns the figures, a map and GeoJSON, KML, Shapefile zip or CSV downloads. Never use the user's current location unless they type it. Give the place as the user names it (place name, address or coordinates): this tool locates it, so find_places is not needed first. Download links build their file when opened; no file is saved. The user opens the file in QGIS or any GIS: this server cannot load it into the user's own QGIS or any app on their computer. Never pass these links to open_gis_file: list every format the user needs in formats, in this one call.


Source: https://terra-lab.ai/docs/api/measure_distance · Updated 2026-11-15
