Introduction
TerraQuerry is a spatial reasoning layer that sits between your geospatial data and your users (or agents). This guide walks through connecting a dataset, asking your first question, and reading the cited geometry behind every answer.
Quickstart
Install the SDK, point it at a dataset, and ask a question. Three steps.
1$pip install terraquerry 2›from terraquerry import Client 3›tq = Client(api_key="tq_live_…") 4›tq.connect("postgres://gis:…@db.yourco/gis") 5›r = tq.ask("Parcels in flood zone within 2km of Cedar River") 6›r.geojson # FeatureCollection — drop into any map 7›r.summary # "1,247 parcels · 412 acres · est. value $890M" 8›r.plan # the SQL the planner ran, for audit
1$npm i @terraquerry/sdk 2›import { Client } from "@terraquerry/sdk"; 3›const tq = new Client({ apiKey: "tq_live_…" }); 4›await tq.connect("postgres://…"); 5›const r = await tq.ask("Parcels in flood zone…"); 6›r.geojson; // FeatureCollection
1$curl -X POST https://api.terraquerry.ai/v1/ask \ 2 -H "Authorization: Bearer tq_live_…" \ 3 -H "Content-Type: application/json" \ 4 -d '{"q": "Parcels in flood zone within 2km of Cedar River"}'
Core concepts
The Planner
Decomposes natural language into a DAG of spatial primitives. Read the planner reference.
02Spatial primitives
Buffer · Intersect · Within · KNN · Isochrone · Viewshed · ZonalStats — 40+ ops.
03Temporal layer
"Compared to last year." First-class time, with snapshots and back-fill.
04Sovereignty
Air-gapped install, BYO LLM, full audit log. Designed for the SCIF.
API reference · POST /v1/ask
https://api.terraquerry.ai/v1/ask
RATE 60 / min
q | string | Natural-language question. Max 4 KB. |
dataset | string? | Slug of a connected dataset. Defaults to your workspace's primary. |
format | enum? | geojson · parquet · mvt — default geojson. |
crs | string? | EPSG code for output. Default EPSG:4326. |
cite | bool? | Return touched rows + plan. Default true. |
1{ 2 "summary": "1,247 parcels · 412 acres · $890M aev", 3 "geojson": { "type": "FeatureCollection", … }, 4 "plan": { 5 "steps": [ 6 { "op": "ST_DWithin", "args": ["cedar_river", 2000] }, 7 { "op": "ST_Intersects", "args": ["flood_100yr"] } 8 ], 9 "sql": "SELECT p.* FROM parcels p …" 10 }, 11 "meter": { "qu": 1.4, "ms": 312 } 12}
Spatial operators
The planner has direct access to the following primitives. Most queries decompose into 2–4 of these.
ST_Intersectsgeometric overlapST_Containsfully insideST_Withincontained byST_DWithinwithin distanceST_Buffergeometric bufferST_Distancegeodesic / projectedST_KNNk-nearestST_Uniongeometry mergeST_Differenceset differenceST_Centroidgeometric centerST_ConvexHullouter hullIsochronetravel-time polygonViewshedline-of-sightZonalStatsraster × polygonNDVIvegetation indexDBSCANdensity clusters