A geospatial database is specifically designed (or extended) to store and query data related to the Earth’s surface. Rather than just focusing on numeric or textual data, these systems handle coordinates, polygons, linestrings, and other spatial objects that define locations and shapes. Queries typically revolve around spatial relationships—like finding points within a boundary, measuring distances, or detecting intersections between shapes.
Historically, geospatial capabilities were mostly the domain of specialized systems such as PostGIS (an extension of PostgreSQL) or dedicated GIS software. SurrealDB, offers geospatial features to unify location-related data with other data models (relational, document, graph, vector, etc.) under one roof.
In this guide, you’ll learn how to think like a geospatial database user. Rather than forcing location data into conventional numeric fields, you’ll represent it with geometry or geography types, index it in specialized structures, and leverage advanced queries (e.g., “Find all customers within 5 km of a store”).
Coordinate Reference Systems (CRS) Geospatial coordinates can be stored in different projections. A popular one is WGS84 for latitude/longitude (EPSG:4326), used by GPS. Others exist for local or projected coordinate systems.
Geometry Types
Spatial Relationships Common geospatial operations revolve around relationships like contains, intersects, within, touches, or disjoint.
Distance and Buffer
Distance: The shortest path between two geometries (commonly in meters or kilometers for Earth-based coordinates).
Buffer: Expanding a geometry outward by a certain distance.
Geohashes & Tiles Some systems approximate location with geohash or tile-based indexing. This is especially useful for bounding box queries or hierarchical location lookups.