geospatial

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

README

Aerospike Geospatial

Import path: github.com/InsideGallery/core/db/aerospike/geospatial

This package provides small helpers for Aerospike-compatible GeoJSON strings and three-dimensional point math.

Main APIs

  • GeoPoint models a GeoJSON point with type and coordinates fields.
  • GeoPoint.GetPoint converts a GeoPoint to Point.
  • Vector is the coordinate-reading interface used by point math.
  • Point stores up to three coordinates.
  • NewPoint, Coordinate, and Coordinates create and inspect points.
  • Dot, Normal, NormalSquare, DistanceSquare, and Distance perform vector math.
  • PointStr(lat, lon) formats a GeoJSON point string.
  • PolygonStr(points...) formats a GeoJSON polygon string from coordinate slices.
  • FloatPrecision and FloatBitSize control float formatting; current output uses 8 decimal places.

Usage

package example

import "github.com/InsideGallery/core/db/aerospike/geospatial"

func geoValues() (string, string, float64) {
	point := geospatial.PointStr(15.123456789, 12.2)
	polygon := geospatial.PolygonStr(
		[]float64{0, 0},
		[]float64{0, 10},
		[]float64{10, 10},
		[]float64{10, 0},
		[]float64{0, 0},
	)
	distance := geospatial.NewPoint(0, 0).Distance(geospatial.NewPoint(3, 4))

	return point, polygon, distance
}

PointStr takes latitude first and longitude second, then writes GeoJSON coordinates as [lon,lat]. PolygonStr writes points exactly as supplied; the caller is responsible for closing the polygon ring when needed.

Operational Notes

The package does not open Aerospike connections and does not validate GeoJSON geometry. NewPoint fills missing dimensions with zero, ignores dimensions after the third, and Coordinate returns zero for indexes outside 0..2.

Documentation

Index

Constants

View Source
const (
	FloatPrecision = 8
	FloatBitSize   = 64
)

Variables

This section is empty.

Functions

func PointStr

func PointStr(lat, lon float64) string

func PolygonStr

func PolygonStr(points ...[]float64) string

Types

type GeoPoint

type GeoPoint struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
}

func (*GeoPoint) GetPoint

func (p *GeoPoint) GetPoint() Point

type Point

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

Point describe point

func NewPoint

func NewPoint(s ...float64) Point

NewPoint return new point

func (Point) Coordinate

func (p Point) Coordinate(i int) float64

Coordinate return coordinate for dimension (0-x, 1-y, 2-z)

func (Point) Coordinates

func (p Point) Coordinates() [3]float64

Coordinates return all coordinates

func (Point) Distance

func (p Point) Distance(p2 Vector) float64

Distance return distance between positions (euclidean)

func (Point) DistanceSquare

func (p Point) DistanceSquare(p2 Vector) float64

DistanceSquare return distance square between positions (euclidean)

func (Point) Dot

func (p Point) Dot(p2 Vector) float64

Dot scalar multiply

func (Point) Normal

func (p Point) Normal() float64

Normal returns the vector's norm.

func (Point) NormalSquare

func (p Point) NormalSquare() float64

NormalSquare returns the vector's norm square.

type Vector

type Vector interface {
	Coordinate(i int) (r float64)
	Coordinates() [3]float64
}

Vector describe any vector point

Jump to

Keyboard shortcuts

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