spatial

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spatial provides APOC spatial/geographic functions.

This package implements all apoc.spatial.* functions for working with geographic coordinates and spatial data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Area

func Area(polygon []*Point) float64

Area calculates area of a polygon.

Example:

apoc.spatial.area(polygon) => area in square meters

func Bearing

func Bearing(p1, p2 *Point) float64

Bearing calculates initial bearing between two points.

Example:

apoc.spatial.bearing(point1, point2) => bearing in degrees

func BoundingBox

func BoundingBox(points []*Point) map[string]float64

BoundingBox calculates bounding box for points.

Example:

apoc.spatial.boundingBox(points) => {minLat, maxLat, minLon, maxLon}

func Contains

func Contains(bbox1, bbox2 map[string]float64) bool

Contains checks if bbox1 contains bbox2.

Example:

apoc.spatial.contains(bbox1, bbox2) => true/false

func Distance

func Distance(p1, p2 *Point) float64

Distance calculates distance between two points using Haversine formula.

Example:

apoc.spatial.distance(point1, point2) => distance in meters

func EncodeGeohash

func EncodeGeohash(point *Point, precision int) string

EncodeGeohash encodes point to geohash.

Example:

apoc.spatial.encodeGeohash(point, 9) => 'u4pruydqq'

func HaversineDistance

func HaversineDistance(lat1, lon1, lat2, lon2 float64) float64

HaversineDistance calculates great-circle distance.

Example:

apoc.spatial.haversineDistance(lat1, lon1, lat2, lon2) => distance in km

func Intersects

func Intersects(bbox1, bbox2 map[string]float64) bool

Intersects checks if two bounding boxes intersect.

Example:

apoc.spatial.intersects(bbox1, bbox2) => true/false

func ToGeoJSON

func ToGeoJSON(point *Point) map[string]interface{}

ToGeoJSON converts point to GeoJSON.

Example:

apoc.spatial.toGeoJSON(point) => GeoJSON string

func VincentyDistance

func VincentyDistance(lat1, lon1, lat2, lon2 float64) float64

VincentyDistance calculates distance using Vincenty formula (more accurate).

Example:

apoc.spatial.vincentyDistance(lat1, lon1, lat2, lon2) => distance in meters

func Within

func Within(point *Point, bbox map[string]float64) bool

Within checks if a point is within a bounding box.

Example:

apoc.spatial.within(point, bbox) => true/false

Types

type Point

type Point struct {
	Latitude  float64
	Longitude float64
	Height    float64 // Optional elevation
}

Point represents a geographic point.

func Centroid

func Centroid(points []*Point) *Point

Centroid calculates centroid of points.

Example:

apoc.spatial.centroid(points) => centroid point

func DecodeGeohash

func DecodeGeohash(geohash string) *Point

DecodeGeohash decodes geohash to point.

Example:

apoc.spatial.decodeGeohash('u4pruydqqvj') => point

func Destination

func Destination(start *Point, bearing, distance float64) *Point

Destination calculates destination point given start, bearing, and distance.

Example:

apoc.spatial.destination(point, 45, 100) => destination point

func FromGeoJSON

func FromGeoJSON(geoJSON map[string]interface{}) *Point

FromGeoJSON parses GeoJSON to point.

Example:

apoc.spatial.fromGeoJSON(geoJSON) => point

func KNearest

func KNearest(target *Point, points []*Point, k int) []*Point

KNearest finds k nearest points.

Example:

apoc.spatial.kNearest(target, points, 5) => 5 nearest points

func Midpoint

func Midpoint(p1, p2 *Point) *Point

Midpoint calculates midpoint between two points.

Example:

apoc.spatial.midpoint(point1, point2) => midpoint

func Nearest

func Nearest(target *Point, points []*Point) *Point

Nearest finds nearest point to a target.

Example:

apoc.spatial.nearest(target, points) => nearest point

func WithinDistance

func WithinDistance(center *Point, points []*Point, maxDistance float64) []*Point

WithinDistance finds points within distance.

Example:

apoc.spatial.withinDistance(center, points, 1000) => points within 1km

Jump to

Keyboard shortcuts

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