Skip to content

Layer operations

Markdown

Join attributes by location

A spatial join: each feature of a layer takes the attributes of the polygon of a second layer it falls in.

RESTPOST https://mcp.terra-lab.ai/v1/tools/join_by_location
MCP tooljoin_by_location on https://mcp.terra-lab.ai/mcp
GroupLayer operations

Request

curl -X POST https://mcp.terra-lab.ai/v1/tools/join_by_location \
  -H "Authorization: Bearer $TERRALAB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://mcp.terra-lab.ai/dl/geojson/TOKEN/pois.geojson","with_url":"https://mcp.terra-lab.ai/dl/geojson/TOKEN/divisions.geojson","join_fields":["name"]}'
import os
import requests

response = requests.post(
    "https://mcp.terra-lab.ai/v1/tools/join_by_location",
    headers={"Authorization": f"Bearer {os.environ['TERRALAB_API_KEY']}"},
    json={
        "url": "https://mcp.terra-lab.ai/dl/geojson/TOKEN/pois.geojson",
        "with_url": "https://mcp.terra-lab.ai/dl/geojson/TOKEN/divisions.geojson",
        "join_fields": ["name"],
    },
    timeout=120,
)
response.raise_for_status()
print(response.json()["structuredContent"])
const response = await fetch('https://mcp.terra-lab.ai/v1/tools/join_by_location', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.TERRALAB_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://mcp.terra-lab.ai/dl/geojson/TOKEN/pois.geojson",
    "with_url": "https://mcp.terra-lab.ai/dl/geojson/TOKEN/divisions.geojson",
    "join_fields": [
      "name"
    ]
  }),
});
const data = await response.json();
console.log(data.structuredContent);

Parameters

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

NameTypeRequiredDescription
fileobjectNoA file uploaded in the conversation (GeoJSON, KML, KMZ, GPX, zipped Shapefile, CSV or WKT).
file.download_urlstringYes
file.file_idstringYes
file.file_namestringNo
file.mime_typestringNo
urlstringNoA public http(s) link to the features, or a TerraLab download link from an earlier answer.
geojsonobjectNoThe features as a GeoJSON FeatureCollection, Feature or geometry in WGS 84 (longitude, latitude).
with_fileobjectNoThe polygons whose attributes are copied, uploaded in the conversation.
with_file.download_urlstringYes
with_file.file_idstringYes
with_file.file_namestringNo
with_file.mime_typestringNo
with_urlstringNoA link to the polygons whose attributes are copied, or a TerraLab download link.
with_geojsonobjectNoThe polygons whose attributes are copied, as GeoJSON in WGS 84.
join_fieldsarray of stringNoThe fields of the polygons to copy. All of them by default.
formatsarray of stringNoDownload formats. All five by default.
titlestringNoName 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.

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

Description for agents

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

Use this when the user wants a spatial join: each feature of a layer takes the attributes of the polygon of a second layer it falls in (the district of each shop, the zone of each parcel). Both layers can be an uploaded file, a link, inline GeoJSON or a TerraLab download link, up to 20,000 features each. A line or polygon joins where its centroid falls; a field both layers have is written as _2; features outside every polygon are kept with empty joined fields. Returns the count matched, the joined fields, sample rows, a map and GeoJSON, KML, Shapefile zip, GeoPackage and CSV downloads. To count features per polygon instead, use count_in_polygons. 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.

Updated 2026-11-15