Documentation
¶
Overview ¶
Package geo provides functionality to represent and process geographical locations 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 ( Degree Degrees = 1 Radian Radians = 1 Turn Turns = 1 Meter Distance = 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 Sheet https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
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 exactly the same point, which conflates multiple positions together, or that the two points will be far enough apart that successfully performing most reverse lookups 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 ¶
type Degrees ¶
type Degrees float64
Degrees represents a latitude or longitude, in decimal degrees.
func MustParseDegrees ¶
MustParseDegrees parses s as decimal degrees, but panics on error.
func ParseDegrees ¶
ParseDegrees parses s as decimal degrees.
func (Degrees) AppendText ¶
AppendText implements encoding.TextAppender. The output is formatted in decimal degrees, prefixed by either the appropriate + or - sign.
func (Degrees) AppendZeroPaddedText ¶
AppendZeroPaddedText appends d formatted as decimal degrees to b. The number of integer digits will be zero-padded to nint.
type Distance ¶
type Distance float64
Distance represents a great-circle distance in meters.
func DistanceOnEarth ¶
DistanceOnEarth converts t turns into the great-circle distance, in meters.
func MustParseDistance ¶
MustParseDistance parses s as distance in meters, but panics on error.
func ParseDistance ¶
ParseDistance parses s as distance in meters.
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
Point represents a pair of latitude and longitude coordinates.
func MakePoint ¶
MakePoint returns a Point representing a given latitude and longitude on a 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 implements encoding.BinaryAppender. The output consists of two float32s 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 implements encoding.TextAppender. The output is a point formatted as OGC Well-Known Text, as "POINT (longitude latitude)" where longitude and latitude are in decimal degrees. If p is not valid, the output will 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 absolute difference of both latitude and longitude are less than tol. If tol is negative, then tol defaults to a reasonably small number (10⁻⁵). If tol is zero, then p and q must be exactly equal.
func (Point) LatLngFloat64 ¶
LatLng reports the latitude and longitude in float64. If err is nil, then lat and lng will never both be 0.0 to disambiguate between an empty struct and Null Island (0° 0°).
func (Point) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaller. The output matches that of calling Point.AppendBinary.
func (Point) MarshalText ¶
MarshalText implements encoding.TextMarshaller. The output matches that of calling Point.AppendText.
func (Point) MarshalUint64 ¶
MarshalUint64 produces the same output as MashalBinary, encoded in a uint64.
func (Point) Quantize ¶
Quantize returns a new Point after throwing away enough location data in p so that it would be difficult to distinguish a node among all the other nodes in its general vicinity. One caveat is that if there’s only one point in an obscure location, someone could triangulate the node using additional data.
This method is stable: given the same p, it will always return the same result. It is equivalent to snapping to points on Earth that are at least MinSeparation apart.
func (Point) SphericalAngleTo ¶
SphericalAngleTo returns the angular distance from p to q, calculated on a spherical Earth.
func (Point) String ¶
String returns a space-separated pair of latitude and longitude, in decimal degrees. Positive latitudes are in the northern hemisphere, and positive longitudes are east of the prime meridian. If p was not initialized, this will return "nowhere".
func (*Point) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler. It expects input that was formatted by Point.AppendBinary: in big-endian byte order, a float32 representing latitude followed by a float32 representing longitude offset by 180°. If latitude and longitude fall outside valid ranges, then an error is returned.
func (*Point) UnmarshalUint64 ¶
UnmarshalUint64 expects input formatted by MarshalUint64.
type Radians ¶
type Radians float64
Radians represents a latitude or longitude, in radians.
func MustParseRadians ¶
MustParseRadians parses s as radians, but panics on error.