Skip to content

Geospatial

Geometry types

SurrealDB’s geometry type follows the GeoJSON model in which both (and only) a type and coordinates field must be specified. A tuple shorthand (e.g. (50.0, 75.7)) is also accepted when creating a point.

A GeoJSON object written in a query becomes a geometry. From SurrealDB 4.0, an object built at run time, such as one decoded from JSON, is also converted wherever only a geometry fits, as described in Objects built at run time.

Points are defined with longitude before latitude, as required by the GeoJSON spec. Many map services display latitude first, so be sure to confirm the order when ingesting external data.

-- Full GeoJSON object form
CREATE city:london SET centre = {
    type: "Point",
    coordinates: [-0.118092, 51.509865],
};

-- Tuple shorthand for a point (lon, lat)
CREATE city:london SET centre = (-0.118092, 51.509865);

See the Geometries reference for LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and Collection, including examples for each type.

  • Points capture a single location (venues, vehicles, users).

  • Line strings represent paths (routes, boundaries along a corridor).

  • Polygons represent regions (service areas, countries, floor plans projected to the globe).

Choosing the right type makes spatial predicates (INTERSECTS, CONTAINS, and so on) accurate.

Was this page helpful?