Documentation
¶
Overview ¶
Package geodesic and an API for the geodesic routines in Go
This an implementation in Go of the geodesic algorithms described in:
C. F. F. Karney, Algorithms for geodesics, J. Geodesy 87, 43--55 (2013); DOI: 10.1007/s00190-012-0578-z; addenda: https://geographiclib.sourceforge.io/geod-addenda.html; link: https://doi.org/10.1007/s00190-012-0578-z;
Copyright (c) Charles Karney (2012-2021) <charles@karney.com> and licensed under the MIT/X11 License. For more information, see https://geographiclib.sourceforge.io/
Also contains spherical algorithms derived from the Geodesy project.
Geodesy representation conversion functions (c) Chris Veness 2002-2019 MIT Licence www.movable-type.co.uk/scripts/latlong.html www.movable-type.co.uk/scripts/js/geodesy/geodesy-library.html#dms
Ported to Go by Joshua Baker <joshbaker77@gmail.com> and licensed under the MIT License.
Index ¶
- Variables
- type Ellipsoid
- func (e *Ellipsoid) Direct(lat1, lon1, azi1, s12 float64, lat2, lon2, azi2 *float64)
- func (e *Ellipsoid) DirectLine(lat1, lon1, azi1, s12 float64, caps Mask) Line
- func (e *Ellipsoid) Flattening() float64
- func (e *Ellipsoid) GenDirect(lat1, lon1, azi1 float64, flags Flags, s12_a12 float64, ...) float64
- func (e *Ellipsoid) GenDirectLine(lat1, lon1, azi1 float64, flags Flags, s12_a12 float64, caps Mask) Line
- func (e *Ellipsoid) GenInverse(lat1 float64, lon1 float64, lat2 float64, lon2 float64, s12 *float64, ...) float64
- func (e *Ellipsoid) Inverse(lat1, lon1, lat2, lon2 float64, s12, azi1, azi2 *float64)
- func (e *Ellipsoid) InverseLine(lat1, lon1, lat2, lon2 float64, caps Mask) Line
- func (e *Ellipsoid) LineInit(lat1, lon1, azi1 float64, caps Mask) Line
- func (e *Ellipsoid) PolygonInit(polyline bool) Polygon
- func (e *Ellipsoid) Radius() float64
- func (e *Ellipsoid) Spherical() bool
- type Flags
- type Line
- func (l *Line) A13() float64
- func (l *Line) Azi1() float64
- func (l *Line) GenPosition(flags Flags, s12_a12 float64, ...) float64
- func (l *Line) GenSetDistance(flags Flags, s13_a13 float64)
- func (l *Line) Lat1() float64
- func (l *Line) Lon1() float64
- func (l *Line) Position(s12 float64, lat2, lon2, azi2 *float64)
- func (l *Line) S13() float64
- func (l *Line) SetDistance(s13 float64)
- type Mask
- type Polygon
- func (p *Polygon) AddEdge(azi, s float64)
- func (p *Polygon) AddPoint(lat, lon float64)
- func (p *Polygon) Clear()
- func (p *Polygon) Compute(clockwise, sign bool, area, perimeter *float64) uint
- func (p *Polygon) TestEdge(azi, s float64, reverse, sign bool, area, perimeter *float64) uint
- func (p *Polygon) TestPoint(lat, lon float64, reverse, sign bool, area, perimeter *float64) uint
Constants ¶
This section is empty.
Variables ¶
var Globe = NewSpherical(6378137)
Globe is a pre-initialized spherical representing Earth as a terrestrial globe.
var WGS84 = NewEllipsoid(6378137, float64(1.)/298.257223563)
WGS84 conforming ellispoid https://en.wikipedia.org/wiki/World_Geodetic_System
Functions ¶
This section is empty.
Types ¶
type Ellipsoid ¶
type Ellipsoid struct {
// contains filtered or unexported fields
}
Ellipsoid is an object for performing geodesic operations.
func NewEllipsoid ¶
NewEllipsoid initializes a new geodesic ellipsoid object.
Param radius is the equatorial radius (meters). Param flattening is the flattening factor of the ellipsoid.
The WGS84 pacakge-level variable is a pre-initialized ellipsoid representing Earth.
func NewSpherical ¶
NewSpherical initializes a new geodesic ellipsoid object that uses simplified operations on a sphere.
The Inverse and Direct operations will often be more computationally efficient than NewEllipsoid because it uses simplier great-circle calculations such as the Haversine formula.
Param radius is the equatorial radius (meters).
The Globe package-level variable is a pre-initialized spherical representing Earth as a terrestrial globe.
func (*Ellipsoid) Direct ¶
Direct solves the direct geodesic problem.
Param g is a pointer to the geod_geodesic object specifying the ellipsoid. Param lat1 is the latitude of point 1 (degrees). Param lon1 is the longitude of point 1 (degrees). Param azi1 is the azimuth at point 1 (degrees). Param s12 is the distance from point 1 to point 2 (meters). negative is ok. Out param plat2 is a pointer to the latitude of point 2 (degrees). Out param plon2 is a pointer to the longitude of point 2 (degrees). Out param pazi2 is a pointer to the (forward) azimuth at point 2 (degrees).
lat1 should be in the range [-90,+90]. The values of lon2 and azi2 returned are in the range [-180,+180]. Any of the "return" arguments, plat2, etc., may be replaced with nil, if you do not need some quantities computed.
func (*Ellipsoid) DirectLine ¶ added in v0.3.2
DirectLine initializes a geodesic Line object in terms of the direct geodesic problem.
Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param azi1 azimuth at point 1 (degrees). Param s12 distance from point 1 to point 2 (meters); it can be negative. Param caps bitor'ed combination of Mask values specifying the capabilities the geodesic Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition()
This function sets point 3 of the geodesic Line to correspond to point 2 of the direct geodesic problem. See LineInit() for more information.
func (*Ellipsoid) GenDirect ¶ added in v0.3.2
func (e *Ellipsoid) GenDirect( lat1, lon1, azi1 float64, flags Flags, s12_a12 float64, lat2, lon2, azi2 *float64, s12, m12 *float64, M12, M21 *float64, S12 *float64, ) float64
GenDirect solves the general direct geodesic problem.
Param lat1 is the latitude of point 1 (degrees). Param lon1 is thelongitude of point 1 (degrees). Param azi1 is theazimuth at point 1 (degrees). Param flags is the bitor'ed combination of Flags; flags & ArgMode determines the meaning of s12_a12 and flags & LongUnroll "unrolls" lon2. Param s12_a12 if flags & ArcMode is 0, this is the distance from point 1 to point 2 (meters); otherwise it is the arc length from point 1 to point 2 (degrees); it can be negative. Out param lat2 is a pointer to the latitude of point 2 (degrees). Out param lon2 is a pointer to the longitude of point 2 (degrees). Out param azi2 is a pointer to the (forward) azimuth at point 2 (degrees). Out param s12 is a pointer to the distance from point 1 to point 2 (meters). Out param m12 is a pointer to the reduced length of geodesic (meters). Out param M12 is a pointer to the geodesic scale of point 2 relative to point 1 (dimensionless). Out param M21 is a pointer to the geodesic scale of point 1 relative to point 2 (dimensionless). Out param S12 is a pointer to the area under the geodesic (meters-squared). Returns a12 arc length from point 1 to point 2 (degrees).
lat1 should be in the range [-90,+90]. The function value a12 equals s12_a12 if flags & ArcMode. Any of the "return" arguments, plat2, etc., may be replaced by nil, if you do not need some quantities computed.
With flags & LongUnroll bit set, the longitude is "unrolled" so that the quantity lon2 - lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.
func (*Ellipsoid) GenDirectLine ¶ added in v0.3.2
func (e *Ellipsoid) GenDirectLine( lat1, lon1, azi1 float64, flags Flags, s12_a12 float64, caps Mask, ) Line
GenDirectLine initializes a geodesic Line object in terms of the direct geodesic problem specified in terms of either distance or arc length.
Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param azi1 azimuth at point 1 (degrees). Param flags either NoFlags or ArcMode to determining the meaning of the s12_a12. Param s12_a12 if flags = NoFlags, this is the distance from point 1 to point 2 (meters); if flags = ArcMode, it is the arc length from point 1 to point 2 (degrees); it can be negative. Param caps bitor'ed combination of Mask values specifying the capabilities the geodesic Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition().
This function sets point 3 of the geodesic Line to correspond to point 2 of the direct geodesic problem. See LineInit() for more information.
func (*Ellipsoid) GenInverse ¶ added in v0.3.2
func (e *Ellipsoid) GenInverse( lat1 float64, lon1 float64, lat2 float64, lon2 float64, s12 *float64, azi1 *float64, azi2 *float64, m12 *float64, M12 *float64, M21 *float64, S12 *float64, ) float64
The general inverse geodesic calculation.
Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param lat2 latitude of point 2 (degrees). Param lon2 longitude of point 2 (degrees). Out param s12 pointer to the distance from point 1 to point 2 (meters). Out param azi1 pointer to the azimuth at point 1 (degrees). Out param azi2 pointer to the (forward) azimuth at point 2 (degrees). Out param m12 pointer to the reduced length of geodesic (meters). Out param M12 pointer to the geodesic scale of point 2 relative to point 1 (dimensionless). Out param M21 pointer to the geodesic scale of point 1 relative to point 2 (dimensionless). Out param S12 pointer to the area under the geodesic (meters-squared). Returns a12 arc length from point 1 to point 2 (degrees).
lat1 and lat2 should be in the range [-90, +90]. Any of the "return" arguments s12, etc., may be replaced by nil, if you do not need some quantities computed.
func (*Ellipsoid) Inverse ¶
Inverse solve the inverse geodesic problem.
Param lat1 is latitude of point 1 (degrees). Param lon1 is longitude of point 1 (degrees). Param lat2 is latitude of point 2 (degrees). Param lon2 is longitude of point 2 (degrees). Out param ps12 is a pointer to the distance from point 1 to point 2 (meters). Out param pazi1 is a pointer to the azimuth at point 1 (degrees). Out param pazi2 is a pointer to the (forward) azimuth at point 2 (degrees).
lat1 and lat2 should be in the range [-90,+90]. The values of azi1 and azi2 returned are in the range [-180,+180]. Any of the "return" arguments, ps12, etc., may be replaced with nil, if you do not need some quantities computed.
The solution to the inverse problem is found using Newton's method. If this fails to converge (this is very unlikely in geodetic applications but does occur for very eccentric ellipsoids), then the bisection method is used to refine the solution.
func (*Ellipsoid) InverseLine ¶ added in v0.3.2
InverseLine initializes a geodesic Line object in terms of the inverse geodesic problem.
Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param lat2 latitude of point 2 (degrees). Param lon2 longitude of point 2 (degrees). Param caps bitor'ed combination of Mask values specifying the capabilities the Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition().
This function sets point 3 of the Line to correspond to point 2 of the inverse geodesic problem. See LineInit() for more information.
func (*Ellipsoid) LineInit ¶ added in v0.3.2
LineInit initializes a geodesic Line object.
Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param azi1 azimuth at point 1 (degrees). Param caps bitor'ed combination of Mask values specifying the capabilities the geodesic Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition().
lat1 should be in the range [-90, +90].
The Mask values are: - caps |= Latitude for the latitude lat2; this is added automatically, - caps |= Longitude for the latitude lon2, - caps |= Azimuth for the latitude azi2; this is added automatically, - caps |= Distance for the distance s12, - caps |= ReducedLength for the reduced length m12, - caps |= GeodesicScale for the geodesic scales M12 and M21, - caps |= Area for the area S12, - caps |= DistanceIn permits the length of the geodesic to be given in terms of s12; without this capability the length can only be specified in terms of arc length.
A value of caps = 0 is treated as Latitude | Longitude | Azimuth | DistanceIn (to support the solution of the "standard" direct problem).
func (*Ellipsoid) PolygonInit ¶
PolygonInit initializes a polygon. Param polyline for polyline instead of a polygon.
If polyline is not set, then the sequence of vertices and edges added by Polygon.AddPoint() and Polygon.AddEdge() define a polygon and the perimeter and area are returned by Polygon.Compute(). If polyline is set, then the vertices and edges define a polyline and only the perimeter is returned by Polygon.Compute().
The area and perimeter are accumulated at two times the standard floating point precision to guard against the loss of accuracy with many-sided polygons. At any point you can ask for the perimeter and area so far.
type Line ¶ added in v0.3.2
type Line struct {
// contains filtered or unexported fields
}
Line is an object containing information about a single geodesic. This must be by LineInit(), DirectLine(), GenDirectLine(), or InverseLine() before use.
func (*Line) GenPosition ¶ added in v0.3.2
func (l *Line) GenPosition( flags Flags, s12_a12 float64, lat2, lon2, azi2, s12, m12, M12, M21, S12 *float64, ) float64
GenPosition is the general position function.
Param flags bitor'ed combination of Flags; flags & ArcMode determines the meaning of s12_a12 and flags & LongUnroll "unrolls" lon2; if flags & ArcMode is 0, then l must have been initialized with caps |= DistanceIn. Param s12_a12 if flags & ArcMode is 0, this is the distance from point 1 to point 2 (meters); otherwise it is the arc length from point 1 to point 2 (degrees); it can be negative. Out param lat2 pointer to the latitude of point 2 (degrees). Out param lon2 pointer to the longitude of point 2 (degrees); requires that l was initialized with caps |= Longitude. Out param azi2 pointer to the (forward) azimuth at point 2 (degrees). Out param s12 pointer to the distance from point 1 to point 2 (meters); requires that l was initialized with caps |= Distance. Out param m12 pointer to the reduced length of geodesic (meters); requires that l was initialized with caps |= ReducedLength. Out param M12 pointer to the geodesic scale of point 2 relative to point 1 (dimensionless); requires that l was initialized with caps |= GeodesicScale. Out param M21 pointer to the geodesic scale of point 1 relative to point 2 (dimensionless); requires that l was initialized with caps |= GeodesicScale. Out param S12 pointer to the area under the geodesic (meters<sup>2</sup>); requires that l was initialized with caps |= GEOD_AREA. Returns a12 arc length from point 1 to point 2 (degrees).
l must have been initialized with a call to geod_lineinit() with caps |= DistanceIn. The value azi2 returned is in the range [-180, +180]. Any of the "return" arguments plat2, etc., may be replaced by nil, if you do not need some quantities computed. Requesting a value which l is not capable of computing is not an error; the corresponding argument will not be altered.
With flags & LongUnroll bit set, the longitude is "unrolled" so that the quantity lon2 - lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.
func (*Line) GenSetDistance ¶ added in v0.3.2
GenSetDistance specifies position of point 3 in terms of either distance or arc length.
Param flags; either NoFlags or ArcMode to determining the meaning of the s13_a13. Param s13_a13; if flags = NoFlags, this is the distance from point 1 to point 3 (meters); if flags = ArcMode, it is the arc length from point 1 to point 3 (degrees); it can be negative.
If flags = NoFlags, this calls Line.SetDistance(). If flags = ArcMode, the s13 is only set if the Line object has been constructed with caps |= Distance.
func (*Line) Position ¶ added in v0.3.2
Position computes the position along a geodesic Line.
Param s12 distance from point 1 to point 2 (meters); it can be negative. Out param lat2 pointer to the latitude of point 2 (degrees). Out param lon2 pointer to the longitude of point 2 (degrees); requires that l was initialized with caps |= Longitude. Out param azi2 pointer to the (forward) azimuth at point 2 (degrees).
l must have been initialized with a call, e.g., to LineInit(), with caps |= DistanceIn (or caps = 0). The values of lon2 and azi2 returned are in the range [-180, +180]. Any of the "return" arguments plat2, etc., may be replaced by nil, if you do not need some quantities computed.
func (*Line) SetDistance ¶ added in v0.3.2
SetDistance specifies position of point 3 in terms of distance.
Param s13 si the distance from point 1 to point 3 (meters); it can be negative.
This is only useful if the line object has been constructed with caps |= DistanceIn.
type Mask ¶ added in v0.3.2
type Mask uint
Mask values for the caps argument to InverseLine
const ( None Mask = 0 /**< Calculate nothing */ Latitude Mask = 1 << 7 /**< Calculate latitude */ Longitude Mask = 1<<8 | 1<<3 /**< Calculate longitude */ Azimuth Mask = 1 << 9 /**< Calculate azimuth */ Distance Mask = 1<<10 | 1<<0 /**< Calculate distance */ DistanceIn Mask = 1<<11 | 1<<0 | 1<<1 /**< Allow distance as input */ ReducedLength Mask = 1<<12 | 1<<0 | 1<<2 /**< Calculate reduced length */ GeodesicScale Mask = 1<<13 | 1<<0 | 1<<2 /**< Calculate geodesic scale */ Area Mask = 1<<14 | 1<<4 /**< Calculate reduced length */ All Mask = 0x7F80 | 0x1F /**< Calculate everything */ )
type Polygon ¶
type Polygon struct {
// contains filtered or unexported fields
}
Polygon struct for accumulating information about a geodesic polygon. Used for computing the perimeter and area of a polygon. This must be initialized from Ellipsoid.PolygonInit before use.
func (*Polygon) AddEdge ¶
AddEdge adds an edge to the polygon or polyline.
Param azi is the azimuth at current point (degrees). Param s is the distance from current point to next point (meters).
func (*Polygon) AddPoint ¶
AddPoint adds a point to the polygon or polyline.
Param lat is the latitude of the point (degrees). Param lon is the longitude of the point (degrees).
func (*Polygon) Clear ¶
func (p *Polygon) Clear()
Clear the polygon, allowing a new polygon to be started.
func (*Polygon) Compute ¶
Compute the results for a polygon
Param reverse, if set then clockwise (instead of counter-clockwise) traversal counts as a positive area. Param sign, if set then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. Out param area is a pointer to the area of the polygon (meters-squared); Out param perimeter is a pointer to the perimeter of the polygon or length of the polyline (meters). Returns the number of points.
The area and perimeter are accumulated at two times the standard floating point precision to guard against the loss of accuracy with many-sided polygons. Arbitrarily complex polygons are allowed. In the case of self-intersecting polygons the area is accumulated "algebraically", e.g., the areas of the 2 loops in a figure-8 polygon will partially cancel. There's no need to "close" the polygon by repeating the first vertex. Set pA or pP to nil, if you do not want the corresponding quantity returned.
More points can be added to the polygon after this call.
func (*Polygon) TestEdge ¶ added in v0.3.2
TestEdge returns the results assuming a tentative final test point is added via an azimuth and distance; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if Polygon.AddEdge() and Polygon.Compute() are used. Param azi is the azimuth at current point (degrees). Param s is the distance from current point to final test point (meters). Param reverse if set then clockwise (instead of counter-clockwise) traversal counts as a positive area. Param sign if set then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. Out param area is a pointer to the area of the polygon (meters-squared); only set if polyline is non-zero in the call to PolygonInit(). Out param perimeter is a pointer to the perimeter of the polygon or length of the polyline (meters). Returns the number of points
func (*Polygon) TestPoint ¶ added in v0.3.2
TestPoint returns the results assuming a tentative final test point is added; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if Polygon.AddPoint() and Polygon.Compute() are used.
Param lat is the latitude of the test point (degrees). Param lon is the longitude of the test point (degrees). Param reverse if set then clockwise (instead of counter-clockwise) traversal counts as a positive area. Param sign if set then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. Out param area is a pointer to the area of the polygon (meters-squared); only set if polyline is non-zero in the call to PolygonInit(). Out apram perimeter is a pointer to the perimeter of the polygon or length of the polyline (meters). Returns the number of points.
lat should be in the range [-90,+90].