Geometries
A geometry is a type based on the GeoJSON spec that is optimised for working with data pertaining to locations on Earth.
SurrealDB makes working with GeoJSON easy, with support for Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and Collection values. SurrealQL automatically detects GeoJSON objects converting them into a single data type.
| Type | Description |
|---|---|
Point | A geolocation point with longitude and latitude |
LineString | A GeoJSON LineString value for storing a geometric path |
Polygon | A GeoJSON Polygon value for storing a geometric area |
MultiPoint | A value which contains multiple geometry points |
MultiLineString | A value which contains multiple geometry lines |
MultiPolygon | A value which contains multiple geometry polygons |
Collection | A value which contains multiple different geometry types |
The GeoJSON spec
There are two main points to keep in mind when creating a geometry type in SurrealDB. They are:
Points are defined according to the GeoJSON spec, which specificies longitude before latitude. Many sites - including Google Maps - provide location data in the opposite order, so be sure to confirm that any data being used to create a
Pointis in the order(longitude, latitude), and not the other way around.A
geometrycreated from an object must contain atypefield and acoordinatesfield, no more and no less.
This can be shown by calling the type::is_geometry() function on some sample objects.
Point
The simplest form of GeoJSON that SurrealDB supports is a geolocation point. These can be written using two different formats. The first format is that of an object that matches the GeoJSON spec.
The other format is a simple 2-element tuple containing the longitude and the latitude of a location. This output for this format is no different from the above, and is simply a convenience due to the frequency of use of the Point type.
LineString
A GeoJSON LineString value for storing a geometric path.
Polygon
A GeoJSON Polygon value for storing a geometric area.
MultiPoint
MultiPoints can be used to store multiple geometry points in a single value.
MultiLineString
A MultiLineString can be used to store multiple geometry lines in a single value.
MultiPolygon
MultiPolygons can be used to store multiple geometry polygons in a single value.
Collection
Collections can be used to store multiple different geometry types in a single value.