Spatial Compute
Measure relationships between geographic features: proximity, counts, coverage, density, gaps, clusters, and comparisons.
Documentation navigation
How Compute works
Compute takes a feature, scopes it to a Region or location, optionally relates it to another feature, and returns a measurement or a set of geographic results. Use it for questions such as how many restaurants are near parks, which sites are uncovered, or how two Regions compare.
| Surface | Entry point |
|---|---|
| JavaScript SDK | e2.compute.feature(...) or e2.compute.run(...) |
| CLI | e2 compute <primitive> <features...> |
| MCP | e2_compute and e2_compare |
| Hosted API | Use managed Compute through an authenticated application integration. |
Choose an interface
compute.ts
const count = await e2.compute.feature("restaurant").region("Manhattan").near("park", 500).count();JavaScript SDK
compute.ts
import { EDK } from "@edk/sdk";
const e2 = new EDK();
const count = await e2.compute.feature("restaurant")
.region("Manhattan")
.near("park", 500)
.count();Build a query with region(), near(), within(), and limit(), then finish with a primitive.
CLI
terminal
e2 compute count restaurant --area Manhattan --near park \
--distance 500 --mode auto --jsonMCP and API
e2_compute.json
{
"primitive": "COUNT",
"feature": ["restaurant"],
"area": "Manhattan",
"near": "park",
"distanceMeters": 500,
"mode": "auto"
}MCP clients submit this schema to e2_compute. Use e2_compare when comparing multiple features or Regions. Hosted Compute follows the same geographic inputs through an authenticated integration.
Primitives
| Primitive | Returns | Example |
|---|---|---|
nearest() | Rows sorted by their nearest related row. | e2.compute.feature("restaurant").area("Manhattan").near("park", 500).nearest() |
distance() | Source IDs, nearest IDs, and distances in meters. | e2.compute.feature("restaurant").area("Manhattan").near("park", 500).distance() |
within() | Rows inside the requested relation distance. | e2.compute.feature("restaurant").area("Manhattan").within("park", 500).within() |
count() | The number of matching rows. | e2.compute.feature("restaurant").area("Manhattan").near("park", 500).count() |
density() | Rows per square kilometre of the relation radius. | e2.compute.feature("restaurant").area("Manhattan").near("park", 500).density() |
coverage() | The fraction of target rows served by source rows. | e2.compute.feature("restaurant").area("Manhattan").within("park", 500).coverage() |
gaps() | Target rows without coverage. | e2.compute.feature("restaurant").area("Manhattan").within("park", 500).gaps() |
cluster() | Radius-based clusters with counts and IDs. | e2.compute.feature("restaurant").area("Manhattan").limit(100).cluster() |
SDK examples
compute.ts
import { EDK } from "@edk/sdk";
const e2 = new EDK();
// NEAREST — rows sorted by their nearest related row
const nearest = await e2.compute.feature("restaurant").area("Manhattan").near("park", 500).nearest();
// DISTANCE — source IDs, nearest IDs, and distances in meters
const distances = await e2.compute.feature("restaurant").area("Manhattan").near("park", 500).distance();
// WITHIN — rows inside the requested relation distance
const inside = await e2.compute.feature("restaurant").area("Manhattan").within("park", 500).within();
// COUNT — the number of matching rows
const count = await e2.compute.feature("restaurant").area("Manhattan").near("park", 500).count();
// DENSITY — rows per square kilometre of the relation radius
const density = await e2.compute.feature("restaurant").area("Manhattan").near("park", 500).density();
// COVERAGE — the fraction of target rows served by source rows
const coverage = await e2.compute.feature("restaurant").area("Manhattan").within("park", 500).coverage();
// GAPS — target rows without coverage
const gaps = await e2.compute.feature("restaurant").area("Manhattan").within("park", 500).gaps();
// CLUSTER — radius-based clusters with counts and IDs
const clusters = await e2.compute.feature("restaurant").area("Manhattan").limit(100).cluster();CLI examples
terminal
earth compute nearest restaurant --area Manhattan --near park --distance 500 --mode auto --json
earth compute distance restaurant --area Manhattan --near park --distance 500 --mode auto --json
earth compute within restaurant --area Manhattan --within park --distance 500 --mode auto --json
earth compute count restaurant --area Manhattan --near park --distance 500 --mode auto --json
earth compute density restaurant --area Manhattan --near park --distance 500 --mode auto --json
earth compute coverage restaurant --area Manhattan --within park --distance 500 --mode auto --json
earth compute gaps restaurant --area Manhattan --within park --distance 500 --mode auto --json
earth compute cluster restaurant --area Manhattan --limit 100 --mode auto --jsonMCP examples
e2_compute.json
{ "primitive": "NEAREST", "feature": ["restaurant"], "area": "Manhattan", "near": "park", "distanceMeters": 500 }
// DISTANCE, COUNT, DENSITY use the same shape with their own primitive:
// { "primitive": "DISTANCE", "feature": ["restaurant"], "area": "Manhattan", "near": "park", "distanceMeters": 500 }
// { "primitive": "WITHIN", "feature": ["restaurant"], "area": "Manhattan", "within": "park", "distanceMeters": 500 }
// { "primitive": "COUNT", "feature": ["restaurant"], "area": "Manhattan", "near": "park", "distanceMeters": 500 }
// { "primitive": "DENSITY", "feature": ["restaurant"], "area": "Manhattan", "near": "park", "distanceMeters": 500 }
// { "primitive": "COVERAGE", "feature": ["restaurant"], "area": "Manhattan", "within": "park", "distanceMeters": 500 }
// { "primitive": "GAPS", "feature": ["restaurant"], "area": "Manhattan", "within": "park", "distanceMeters": 500 }
// { "primitive": "CLUSTER", "feature": ["restaurant"], "area": "Manhattan", "limit": 100 }