geocalc

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: GPL-3.0 Imports: 1 Imported by: 0

README

Geocalc

Go Report Card PkgGoDev

Go minimalist library to compute earth points. Implementation of https://www.movable-type.co.uk/scripts/latlong.html. Angle are in Rad and distance in meters.

Features in v1.3.3

  • Earth points in Rad/Degree
  • Get distance between two Points
  • Create Walk line
  • Get bearing between two Points
  • Rad/Degree conversion functions

Getting start

Creating Points
// Point creation is in Rad
p1 := geocalc.NewPoint(math.Pi, 0)
p2 := geocalc.NewPoint(0, 0)
// Get degree values for p1
latDegree, lonDegree := p1.Degree()
Bearing and distance
// Get bearing in Rad between two Points
bearing := p1.Bearing(p2)
bearing := p2.Bearing(p1)
// Distance in meters
distance := geocalc.Distance(p1, p2)
Unit conversion
rad := math.Pi
degree := geocalc.RadToDegree(rad) // 180
rad = geocalc.DegreeToRad(degree)  // math.Pi
Walking on the earth surface

Walk from a starting point to a final point with a bearing of 0 Rad and a distance of 1000m

startPoint := geocalc.NewPoint(0, 0)
finalPoint := startPoint.Walk(0, 1000) // Return a new point 
Intermediate Points

Intermediate calculate an intermediate point at any fraction along the great circle path between p1 and p2. Start path at p1, if fraction=0, returned Point is p1. If fraction=1, returned Point is p2.

p1 := geocalc.NewPoint(math.Pi, 0)
p2 := geocalc.NewPoint(0, 0)
fraction := 0.5 // We want a Point in the middle of the other two Points
p3 := geocalc.Intermediate(p1, p2, fraction)

Documentation

Index

Constants

View Source
const (
	// EarthRadius in meters
	EarthRadius = 6371e3
	// EarthCircumference in meters
	EarthCircumference = 2 * EarthRadius * math.Pi
)

Variables

This section is empty.

Functions

func DegreeToRad

func DegreeToRad(deg float64) float64

DegreeToRad convert given arc in degree to rad

func Distance

func Distance(p1, p2 Point) float64

Distance return the distance between two earth Point in meters

func RadToDegree

func RadToDegree(rad float64) float64

RadToDegree convert given arc in rad to degree

Types

type Point

type Point struct {
	Lat float64 // Latitude of the point in rad
	Lon float64 // Longitude of the point in rad
}

Point define an Earth point

func Intermediate

func Intermediate(p1, p2 Point, fraction float64) Point

Intermediate calculate an intermediate point at any fraction along the great circle path between p1 and p2. Start path at p1, if fraction=0, returned Point is p1. If fraction=1, returned Point is p2.

func NewPoint

func NewPoint(lat, lon float64) Point

NewPoint create and return an new Point from given coordinates lat and lon in radians

func (Point) Bearing

func (p Point) Bearing(pt Point) float64

Bearing return the bearing in rad between current and given Point

func (Point) Degree

func (p Point) Degree() (float64, float64)

Degree return degree value of latitude, longitude

func (Point) Walk

func (p Point) Walk(bearing, dist float64) Point

Walk return destination Point given dist and bearing from start p Point. bearing in rad (clockwise from north) and dist in meters

Jump to

Keyboard shortcuts

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