geo

package
v2.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package geo provides geo-spatial indexing and search capabilities for cortexdb

Index

Constants

View Source
const (
	// EarthRadiusKM is the Earth's radius in kilometers
	EarthRadiusKM = 6371.0
	// EarthRadiusMiles is the Earth's radius in miles
	EarthRadiusMiles = 3959.0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundingBox

type BoundingBox struct {
	MinLat float64 `json:"min_lat"`
	MaxLat float64 `json:"max_lat"`
	MinLng float64 `json:"min_lng"`
	MaxLng float64 `json:"max_lng"`
}

BoundingBox represents a rectangular geographic area

type Coordinate

type Coordinate struct {
	Lat float64 `json:"lat"`
	Lng float64 `json:"lng"`
}

Coordinate represents a geographic coordinate

type DistanceUnit

type DistanceUnit string

DistanceUnit represents the unit for distance calculations

const (
	Kilometers DistanceUnit = "km"
	Miles      DistanceUnit = "miles"
	Meters     DistanceUnit = "meters"
)

type GeoIndex

type GeoIndex struct {
	// contains filtered or unexported fields
}

GeoIndex provides geo-spatial indexing and search

func NewGeoIndex

func NewGeoIndex() *GeoIndex

NewGeoIndex creates a new geo-spatial index

func (*GeoIndex) Clear

func (g *GeoIndex) Clear()

Clear removes all points from the index

func (*GeoIndex) Delete

func (g *GeoIndex) Delete(id string) bool

Delete removes a point from the index

func (*GeoIndex) GetPoint

func (g *GeoIndex) GetPoint(id string) (*GeoPoint, bool)

GetPoint retrieves a point by ID

func (*GeoIndex) Insert

func (g *GeoIndex) Insert(point GeoPoint) error

Insert adds a geo point to the index

func (*GeoIndex) SearchBoundingBox

func (g *GeoIndex) SearchBoundingBox(bbox BoundingBox) ([]GeoPoint, error)

SearchBoundingBox finds all points within a bounding box

func (*GeoIndex) SearchKNN

func (g *GeoIndex) SearchKNN(center Coordinate, k int) ([]GeoSearchResult, error)

SearchKNN finds the k nearest neighbors to a point

func (*GeoIndex) SearchPolygon

func (g *GeoIndex) SearchPolygon(polygon []Coordinate) ([]GeoPoint, error)

SearchPolygon finds all points within a polygon (simplified for convex polygons)

func (*GeoIndex) SearchRadius

func (g *GeoIndex) SearchRadius(center Coordinate, radius float64, unit DistanceUnit) ([]GeoSearchResult, error)

SearchRadius finds all points within a given radius from a center point

func (*GeoIndex) Size

func (g *GeoIndex) Size() int

Size returns the number of points in the index

type GeoPoint

type GeoPoint struct {
	ID         string                 `json:"id"`
	Coordinate Coordinate             `json:"coordinate"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
}

GeoPoint represents a point with ID and coordinates

type GeoSearchResult

type GeoSearchResult struct {
	Point    GeoPoint `json:"point"`
	Distance float64  `json:"distance"`
}

GeoSearchResult represents a search result with distance

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL