Skip to content

API Reference

/

Values

Geometry

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

A geographic point with longitude and latitude coordinates.

type GeometryPoint struct {
    Longitude float64
    Latitude  float64
}

CBOR tag: 88

  • .GetCoordinates() - returns [2]float64{Longitude, Latitude}

point := models.GeometryPoint{Longitude: -0.118, Latitude: 51.509}

A line consisting of two or more points.

type GeometryLine []GeometryPoint

CBOR tag: 89

A polygon consisting of one or more closed line rings.

type GeometryPolygon []GeometryLine

CBOR tag: 90

A collection of points.

type GeometryMultiPoint []GeometryPoint

CBOR tag: 91

A collection of lines.

type GeometryMultiLine []GeometryLine

CBOR tag: 92

A collection of polygons.

type GeometryMultiPolygon []GeometryPolygon

CBOR tag: 93

A heterogeneous collection of geometry objects.

type GeometryCollection []any

CBOR tag: 94

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},
    },
}

Was this page helpful?