geo
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package geo provides functionality to represent and process geographicallocations on a spherical Earth.
Index¶
- Constants
- Variables
- type Degrees
- type Distance
- type Point
- func (p Point) AppendBinary(b []byte) ([]byte, error)
- func (p Point) AppendText(b []byte) ([]byte, error)
- func (p Point) DistanceTo(q Point) (Distance, error)
- func (p Point) EqualApprox(q Point, tol float64) bool
- func (p Point) IsZero() bool
- func (p Point) LatLng() (lat, lng Degrees, err error)
- func (p Point) LatLngFloat64() (lat, lng float64, err error)
- func (p Point) MarshalBinary() ([]byte, error)
- func (p Point) MarshalText() ([]byte, error)
- func (p Point) MarshalUint64() (uint64, error)
- func (p Point) Quantize() Point
- func (p Point) SphericalAngleTo(q Point) (Radians, error)
- func (p Point) String() string
- func (p *Point) UnmarshalBinary(data []byte) error
- func (p *Point) UnmarshalUint64(v uint64) error
- func (p Point) Valid() bool
- type Radians
- type Turns
Constants¶
const (DegreeDegrees = 1RadianRadians = 1TurnTurns = 1MeterDistance = 1)
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
const MinSeparation = 50_000 *MeterMinSeparation 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¶
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¶
MustParseDegrees parses s as decimal degrees, but panics on error.
funcParseDegrees¶
ParseDegrees parses s as decimal degrees.
func (Degrees)AppendText¶
AppendText implementsencoding.TextAppender. The output is formatted indecimal degrees, prefixed by either the appropriate + or - sign.
func (Degrees)AppendZeroPaddedText¶
AppendZeroPaddedText appends d formatted as decimal degrees to b. The number ofinteger digits will be zero-padded to nint.
typeDistance¶
type Distancefloat64
Distance represents a great-circle distance in meters.
funcDistanceOnEarth¶
DistanceOnEarth converts t turns into the great-circle distance, in meters.
funcMustParseDistance¶
MustParseDistance parses s as distance in meters, but panics on error.
funcParseDistance¶
ParseDistance parses s as distance in meters.
typePoint¶
type Point struct {// contains filtered or unexported fields}Point represents a pair of latitude and longitude coordinates.
funcMakePoint¶
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¶
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¶
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¶
DistanceTo reports the great-circle distance between p and q, in meters.
func (Point)EqualApprox¶
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)LatLngFloat64¶
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¶
MarshalBinary implementsencoding.BinaryMarshaller. The output matches thatof callingPoint.AppendBinary.
func (Point)MarshalText¶
MarshalText implementsencoding.TextMarshaller. The output matches thatof callingPoint.AppendText.
func (Point)MarshalUint64¶
MarshalUint64 produces the same output as MashalBinary, encoded in a uint64.
func (Point)Quantize¶
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¶
SphericalAngleTo returns the angular distance from p to q, calculated on aspherical Earth.
func (Point)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¶
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¶
UnmarshalUint64 expects input formatted by MarshalUint64.
typeRadians¶
type Radiansfloat64
Radians represents a latitude or longitude, in radians.
funcMustParseRadians¶
MustParseRadians parses s as radians, but panics on error.