Movatterモバイル変換


[0]ホーム

URL:


geo

package
v1.92.2Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:8Imported by:0

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package geo provides functionality to represent and process geographicallocations on a spherical Earth.

Index

Constants

View Source
const (DegreeDegrees  = 1RadianRadians  = 1TurnTurns    = 1MeterDistance = 1)
View Source
const (// EarthMeanRadius is the volumetric mean radius of the Earth.EarthMeanRadius = 6_371_000 *Meter// EarthMeanCircumference is the volumetric mean circumference of the Earth.EarthMeanCircumference = 2 *math.Pi *EarthMeanRadius)

Earth Fact Sheethttps://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html

View Source
const MinSeparation = 50_000 *Meter

MinSeparation is the minimum separation between two points after quantizing.Point.Quantize guarantees that two points will either be snapped to exactlythe same point, which conflates multiple positions together, or that the twopoints will be far enough apart that successfully performing most reverselookups would be highly improbable.

Variables

View Source
var ErrBadPoint =errors.New("not a valid point")

ErrBadPoint indicates that the point is malformed.

Functions

This section is empty.

Types

typeDegrees

type Degreesfloat64

Degrees represents a latitude or longitude, in decimal degrees.

funcMustParseDegrees

func MustParseDegrees(sstring)Degrees

MustParseDegrees parses s as decimal degrees, but panics on error.

funcParseDegrees

func ParseDegrees(sstring) (Degrees,error)

ParseDegrees parses s as decimal degrees.

func (Degrees)AppendText

func (dDegrees) AppendText(b []byte) ([]byte,error)

AppendText implementsencoding.TextAppender. The output is formatted indecimal degrees, prefixed by either the appropriate + or - sign.

func (Degrees)AppendZeroPaddedText

func (dDegrees) AppendZeroPaddedText(b []byte, nintint) []byte

AppendZeroPaddedText appends d formatted as decimal degrees to b. The number ofinteger digits will be zero-padded to nint.

func (Degrees)Radians

func (dDegrees) Radians()Radians

Radians converts d into radians.

func (Degrees)String

func (dDegrees) String()string

String implements the [Stringer] interface. The output is formatted indecimal degrees, prefixed by either the appropriate + or - sign, and suffixedby a ° degree symbol.

func (Degrees)Turns

func (dDegrees) Turns()Turns

Turns converts d into a number of turns.

typeDistance

type Distancefloat64

Distance represents a great-circle distance in meters.

funcDistanceOnEarth

func DistanceOnEarth(tTurns)Distance

DistanceOnEarth converts t turns into the great-circle distance, in meters.

funcMustParseDistance

func MustParseDistance(sstring)Distance

MustParseDistance parses s as distance in meters, but panics on error.

funcParseDistance

func ParseDistance(sstring) (Distance,error)

ParseDistance parses s as distance in meters.

func (Distance)String

func (dDistance) String()string

String implements the [Stringer] interface.

typePoint

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

Point represents a pair of latitude and longitude coordinates.

funcMakePoint

func MakePoint(latitude, longitudeDegrees)Point

MakePoint returns a Point representing a given latitude and longitude ona WGS 84 ellipsoid. The Coordinate Reference System is EPSG:4326.Latitude is wrapped to [-90°, +90°] and longitude to (-180°, +180°].

func (Point)AppendBinary

func (pPoint) AppendBinary(b []byte) ([]byte,error)

AppendBinary implementsencoding.BinaryAppender. The output consists of twofloat32s in big-endian byte order: latitude and longitude offset by 180°.If p is not a valid, the output will be an 8-byte zero value.

func (Point)AppendText

func (pPoint) AppendText(b []byte) ([]byte,error)

AppendText implementsencoding.TextAppender. The output is a pointformatted as OGC Well-Known Text, as "POINT (longitude latitude)" wherelongitude and latitude are in decimal degrees. If p is not valid, the outputwill be "POINT EMPTY".

func (Point)DistanceTo

func (pPoint) DistanceTo(qPoint) (Distance,error)

DistanceTo reports the great-circle distance between p and q, in meters.

func (Point)EqualApprox

func (pPoint) EqualApprox(qPoint, tolfloat64)bool

EqualApprox reports if p and q are approximately equal: that is the absolutedifference of both latitude and longitude are less than tol. If tol isnegative, then tol defaults to a reasonably small number (10⁻⁵). If tol iszero, then p and q must be exactly equal.

func (Point)IsZero

func (pPoint) IsZero()bool

IsZero reports if p is the zero value.

func (Point)LatLng

func (pPoint) LatLng() (lat, lngDegrees, errerror)

LatLng reports the latitude and longitude.

func (Point)LatLngFloat64

func (pPoint) LatLngFloat64() (lat, lngfloat64, errerror)

LatLng reports the latitude and longitude in float64. If err is nil, then latand lng will never both be 0.0 to disambiguate between an empty struct andNull Island (0° 0°).

func (Point)MarshalBinary

func (pPoint) MarshalBinary() ([]byte,error)

MarshalBinary implementsencoding.BinaryMarshaller. The output matches thatof callingPoint.AppendBinary.

func (Point)MarshalText

func (pPoint) MarshalText() ([]byte,error)

MarshalText implementsencoding.TextMarshaller. The output matches thatof callingPoint.AppendText.

func (Point)MarshalUint64

func (pPoint) MarshalUint64() (uint64,error)

MarshalUint64 produces the same output as MashalBinary, encoded in a uint64.

func (Point)Quantize

func (pPoint) Quantize()Point

Quantize returns a newPoint after throwing away enough location data in pso that it would be difficult to distinguish a node among all the other nodesin its general vicinity. One caveat is that if there’s only one point in anobscure location, someone could triangulate the node using additional data.

This method is stable: given the same p, it will always return the sameresult. It is equivalent to snapping to points on Earth that are at leastMinSeparation apart.

func (Point)SphericalAngleTo

func (pPoint) SphericalAngleTo(qPoint) (Radians,error)

SphericalAngleTo returns the angular distance from p to q, calculated on aspherical Earth.

func (Point)String

func (pPoint) String()string

String returns a space-separated pair of latitude and longitude, in decimaldegrees. Positive latitudes are in the northern hemisphere, and positivelongitudes are east of the prime meridian. If p was not initialized, thiswill return "nowhere".

func (*Point)UnmarshalBinary

func (p *Point) UnmarshalBinary(data []byte)error

UnmarshalBinary implementsencoding.BinaryUnmarshaler. It expects inputthat was formatted byPoint.AppendBinary: in big-endian byte order, afloat32 representing latitude followed by a float32 representing longitudeoffset by 180°. If latitude and longitude fall outside valid ranges, thenan error is returned.

func (*Point)UnmarshalUint64

func (p *Point) UnmarshalUint64(vuint64)error

UnmarshalUint64 expects input formatted by MarshalUint64.

func (Point)Valid

func (pPoint) Valid()bool

Valid reports if p is a valid point.

typeRadians

type Radiansfloat64

Radians represents a latitude or longitude, in radians.

funcMustParseRadians

func MustParseRadians(sstring)Radians

MustParseRadians parses s as radians, but panics on error.

funcParseRadians

func ParseRadians(sstring) (Radians,error)

ParseRadians parses s as radians.

func (Radians)Degrees

func (rRadians) Degrees()Degrees

Degrees converts r into decimal degrees.

func (Radians)String

func (rRadians) String()string

String implements the [Stringer] interface.

func (Radians)Turns

func (rRadians) Turns()Turns

Turns converts r into a number of turns.

typeTurns

type Turnsfloat64

Turns represents a number of complete revolutions around a sphere.

func (Turns)Degrees

func (oTurns) Degrees()Degrees

Degrees converts t into decimal degrees.

func (Turns)Radians

func (oTurns) Radians()Radians

Radians converts t into radians.

func (Turns)String

func (oTurns) String()string

String implements the [Stringer] interface.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp