# Buffer, clip, join, count or filter features

> 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.

One GIS operation on a set of features: buffer, union, dissolve, intersection, difference, clip or simplify, returned as a file.

| | |
| --- | --- |
| MCP tool | `process_geometry` on `https://mcp.terra-lab.ai/mcp` |
| Group | Map data |

## Use it

Connect the [MCP server](https://terra-lab.ai/docs/mcp) to your assistant and ask in plain words: the assistant picks `process_geometry` when the request fits and fills the arguments below. These are valid arguments:

```json
{"operation":"buffer","geojson":{"type":"LineString","coordinates":[[6.12,45.9],[6.13,45.905]]},"radius_m":200}
```

```json
{"operation":"clip","url":"https://mcp.terra-lab.ai/dl/geojson/TOKEN/buildings.geojson","area":{"place":"Annecy","radius_m":150}}
```

```json
{"operation":"count_within","url":"https://mcp.terra-lab.ai/dl/geojson/TOKEN/pois.geojson","with_url":"https://mcp.terra-lab.ai/dl/geojson/TOKEN/divisions.geojson"}
```

## Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `operation` | string | Yes | The operation to apply. One of `"buffer"`, `"union"`, `"intersection"`, `"difference"`, `"clip"`, `"simplify"`, `"centroid"`, `"area_length"`, `"count_within"`, `"nearest"`, `"select_by_location"`, `"spatial_join"`, `"filter"`. |
| `file` | object | No | A file uploaded in the conversation (GeoJSON, KML, KMZ, GPX, zipped Shapefile, GeoParquet, FlatGeobuf, GeoPackage, CSV or WKT). |
| `file.download_url` | string | Yes |  |
| `file.file_id` | string | Yes |  |
| `file.file_name` | string | No |  |
| `file.mime_type` | string | No |  |
| `url` | string | No | A public http(s) link to the features, or a TerraLab download link from an earlier answer. |
| `geojson` | object | No | The features as a GeoJSON FeatureCollection, Feature or geometry in WGS 84 (longitude, latitude). |
| `with_file` | object | No | The second layer, uploaded in the conversation: for intersection, difference, clip, count_within, nearest, select_by_location and spatial_join. |
| `with_file.download_url` | string | Yes |  |
| `with_file.file_id` | string | Yes |  |
| `with_file.file_name` | string | No |  |
| `with_file.mime_type` | string | No |  |
| `with_url` | string | No | A link to the second layer, or a TerraLab download link. |
| `with_geojson` | object | No | The second layer as GeoJSON in WGS 84. Only its polygons count, except for nearest and select_by_location, which take any geometry. |
| `area` | object | No | For clip: the area to keep, as a bbox or a place with a radius (its bounding box is used). The place the user asks about, not the user's own location. |
| `area.bbox` | array of number | No | [west, south, east, north] in decimal degrees (WGS 84). Exactly 4 items. |
| `area.place` | string or object | No | A place name or address, or a point. |
| `area.radius_m` | number | No | Radius around the place in metres. From 1 to 100000. |
| `radius_m` | number | No | For buffer: the distance in metres (convert km or miles first). From 0.1 to 100000. |
| `dissolve` | boolean | No | For buffer: merge all buffers into one feature, so overlaps count once in the total area. |
| `tolerance_m` | number | No | For simplify: the largest allowed shift of the outline in metres. From 0.01 to 100000. |
| `dissolve_field` | string | No | For union: dissolve into one feature per value of this field instead of one feature. |
| `where` | array of object | No | For filter: the conditions on attributes. A missing field equals null. Text that writes a number plainly ("12", "12.5") compares as a number; other text compares without case, and never orders against a number. |
| `match` | string | No | For filter: keep the features that meet all conditions (default) or any of them. One of `"all"`, `"any"`. |
| `relation` | string | No | For select_by_location: keep the input features that intersect the second layer (default), lie wholly within one of its polygons, or lie within distance_m of it. One of `"intersects"`, `"within"`, `"within_distance"`. |
| `distance_m` | number | No | For select_by_location with relation within_distance: the distance in metres. From 0.1 to 100000. |
| `invert` | boolean | No | For select_by_location: keep the features that do not match instead. |
| `sum_field` | string | No | For count_within: also sum this numeric field of the counted features per polygon, as sum_<field>. |
| `join_fields` | array of string | No | For spatial_join and nearest: the fields of the second layer to copy. By default spatial_join copies all of them and nearest copies name (as nearest_name). |
| `formats` | array of string | No | Download formats. All five by default. |
| `title` | string | No | Name for the map and the output files. |

## 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 one GIS operation on a set of features (an uploaded file, a link, inline GeoJSON, or a download link from another TerraLab answer), with the result as a file. On one layer: buffer by radius_m (dissolve merges the buffers), union (dissolve all features into one, or one per value of dissolve_field), simplify by tolerance_m, centroid of each feature, area_length (adds area_m2, perimeter_m and length_m, geodesic), filter by attribute (where). With a second layer: intersection, difference, clip (or clip to an area: place, place with radius_m, or bbox), count_within (how many input features fall in each polygon, points in polygons, with an optional sum), nearest (the nearest feature of the second layer and its geodesic distance), select_by_location (the features that intersect it, lie within it, or lie within distance_m of it), spatial_join (copy the attributes of the polygon each feature falls in). Overlays and point in polygon run in WGS 84 degrees; buffer, simplify, centroid and distances in a local equidistant projection. Up to 20,000 features and 100,000 vertices per layer (25,000 for buffer). Returns counts, the fields, a few sample rows, total area or length, a map and GeoJSON, KML, Shapefile zip, GeoPackage and CSV downloads. Not for one distance or the area of a shape drawn in the chat: that is measure. Not for reading or converting a file without changing it: that is open_gis_file. Not for styling layers, print layouts or chaining steps on the layers of a QGIS project the user has open: TerraLab AI Agent in QGIS does that. Never use the user's current location unless they type it. 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. TerraLab reads the file or link to answer and keeps no copy.

## Call it over HTTP

The same tool is also callable over HTTP with an [API key](https://terra-lab.ai/docs/authentication): `POST https://mcp.terra-lab.ai/v1/tools/process_geometry` with the arguments as the JSON body.

```bash
curl -X POST https://mcp.terra-lab.ai/v1/tools/process_geometry \
  -H "Authorization: Bearer $TERRALAB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation":"buffer","geojson":{"type":"LineString","coordinates":[[6.12,45.9],[6.13,45.905]]},"radius_m":200}'
```

```python
import os
import requests

response = requests.post(
    "https://mcp.terra-lab.ai/v1/tools/process_geometry",
    headers={"Authorization": f"Bearer {os.environ['TERRALAB_API_KEY']}"},
    json={
        "operation": "buffer",
        "geojson": {
            "type": "LineString",
            "coordinates": [[6.12, 45.9], [6.13, 45.905]],
        },
        "radius_m": 200,
    },
    timeout=120,
)
response.raise_for_status()
print(response.json()["structuredContent"])
```

```javascript
const response = await fetch('https://mcp.terra-lab.ai/v1/tools/process_geometry', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.TERRALAB_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "operation": "buffer",
    "geojson": {
      "type": "LineString",
      "coordinates": [
        [
          6.12,
          45.9
        ],
        [
          6.13,
          45.905
        ]
      ]
    },
    "radius_m": 200
  }),
});
const data = await response.json();
console.log(data.structuredContent);
```


Source: https://terra-lab.ai/docs/mcp/tools/process_geometry · Updated 2026-11-24
