Geometry types
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 []GeometryPoint
CBOR tag: 89
GeometryPolygon
A polygon consisting of one or more closed line rings.
type GeometryPolygon []GeometryLine
CBOR tag: 90
GeometryMultiPoint
A collection of points.
type GeometryMultiPoint []GeometryPoint
CBOR tag: 91
GeometryMultiLine
A collection of lines.
type GeometryMultiLine []GeometryLine
CBOR tag: 92
GeometryMultiPolygon
A collection of polygons.
type GeometryMultiPolygon []GeometryPolygon
CBOR tag: 93
GeometryCollection
A heterogeneous collection of geometry objects.
type GeometryCollection []any
CBOR 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