The SDK provides typed geometry structs that map to SurrealDB's GeoJSON-based geometry types. Each type handles CBOR encoding with the appropriate tag number.
Package: github.com/surrealdb/surrealdb.go/pkg/models
Source: pkg/models/geometry.go
Types
GeometryPoint
A geographic point with longitude and latitude coordinates.
type GeometryPoint struct {
Longitude float64
Latitude float64
}CBOR tag: 88
Methods
.GetCoordinates()— returns[2]float64{Longitude, Latitude}
Examples
point := models.GeometryPoint{Longitude: -0.118, Latitude: 51.509} GeometryLine
A line consisting of two or more points.
type GeometryLine []GeometryPointCBOR tag: 89
GeometryPolygon
A polygon consisting of one or more closed line rings.
type GeometryPolygon []GeometryLineCBOR tag: 90
GeometryMultiPoint
A collection of points.
type GeometryMultiPoint []GeometryPointCBOR tag: 91
GeometryMultiLine
A collection of lines.
type GeometryMultiLine []GeometryLineCBOR tag: 92
GeometryMultiPolygon
A collection of polygons.
type GeometryMultiPolygon []GeometryPolygonCBOR tag: 93
GeometryCollection
A heterogeneous collection of geometry objects.
type GeometryCollection []anyCBOR tag: 94
Usage
import "github.com/surrealdb/surrealdb.go/pkg/models"
type Location struct {
ID *models.RecordID `json:"id,omitempty"`
Name string `json:"name"`
Position models.GeometryPoint `json:"position"`
Boundary models.GeometryPolygon `json:"boundary"`
}
line := models.GeometryLine{
{Longitude: -0.118, Latitude: 51.509},
{Longitude: -0.076, Latitude: 51.508},
}
polygon := models.GeometryPolygon{
models.GeometryLine{
{Longitude: -0.12, Latitude: 51.50},
{Longitude: -0.08, Latitude: 51.50},
{Longitude: -0.08, Latitude: 51.52},
{Longitude: -0.12, Latitude: 51.52},
{Longitude: -0.12, Latitude: 51.50},
},
}See also
RecordID for the record identifier type
Value types for the full type mapping
Data manipulation for using geometry values in CRUD operations
SurrealQL geometry types for the underlying data model