• Start

Geospatial

Spatial queries

Combine geometry fields with SurrealQL SELECTs and geo functions to answer contains, intersects, and distance-style questions over location data.

Geospatial workloads usually start with a question in plain language, such as "which stores are inside this polygon?", "which trips cross this corridor?", or "which assets are within 10 km of this point?". They are then translated into spatial relationships between stored geometries.

  • Contains / within: Is a point inside a polygon, or is one region inside another?

  • Intersects: Do two geometries share any area or touch along an edge?

  • Touches / disjoint: Boundary contact only, or no overlap at all?

SurrealDB exposes these ideas through geometry values and the geo:: function family.

Example of geo:: function

let $london = (-0.04592553673505285, 51.555282574465764);
let $harare = (30.463880214538577, -17.865161568822085);
RETURN geo::distance($london, $harare);

Exact operators available to your version are documented alongside geometry types and index definitions. You can also use EXPLAIN to confirm your query plan when tuning performance.

As location queries are rarely done in isolation, you can combine spatial predicates with ordinary fields to form queries for tasks like "coffee shops in this polygon that are open now", not every record in the table.

Was this page helpful?