Documentation
¶
Index ¶
- Constants
- func Distance(start, end LatLon, model EarthModel, modelArgs ...interface{}) units.Distance
- func FormatDMS(deg Degrees, format, dp int) string
- func MultiPolygonToMercator(mp orb.MultiPolygon) orb.MultiPolygon
- func SetEarthRadius(r float64)
- type Cartesian
- type Degrees
- func DegreesFromRadians(radians float64) Degrees
- func FinalBearing(start, end LatLon, model EarthModel, modelArgs ...interface{}) Degrees
- func InitialBearing(start, end LatLon, model EarthModel, modelArgs ...interface{}) Degrees
- func ParseDMS(dms string) (Degrees, error)
- func Wrap90(degrees Degrees) Degrees
- func Wrap180(degrees Degrees) Degrees
- func Wrap360(degrees Degrees) Degrees
- type EarthModel
- type Ellipsoid
- type LatLon
- func DestinationPoint(start LatLon, distance float64, bearing Degrees, model EarthModel, ...) LatLon
- func IntermediatePoint(start, end LatLon, fraction float64, model EarthModel, ...) LatLon
- func IntermediatePoints(start, end LatLon, fractions []float64, model EarthModel, ...) []LatLon
- func MidPoint(start, end LatLon, model EarthModel, modelArgs ...interface{}) LatLon
- func NewLatLon(latitude, longitude float64) LatLon
- func ParseLatLon(args ...interface{}) (LatLon, error)
- type LatLonEllipsoidal
- type LatLonEllipsoidalVincenty
- func (llv LatLonEllipsoidalVincenty) DestinationPoint(distance float64, bearing Degrees) LatLon
- func (llv LatLonEllipsoidalVincenty) DistanceTo(dest LatLon) units.Distance
- func (llv LatLonEllipsoidalVincenty) FinalBearingOn(dest LatLon) Degrees
- func (llv LatLonEllipsoidalVincenty) InitialBearingTo(dest LatLon) Degrees
- func (llv LatLonEllipsoidalVincenty) IntermediatePointTo(dest LatLon, fraction float64) LatLon
- func (llv LatLonEllipsoidalVincenty) IntermediatePointsTo(dest LatLon, fractions []float64) []LatLon
- func (llv LatLonEllipsoidalVincenty) LatLon() LatLon
- func (llv LatLonEllipsoidalVincenty) MidPointTo(dest LatLon) LatLon
- func (llv LatLonEllipsoidalVincenty) VincentyDirect(distance float64, initialBearing Degrees) (LatLon, Degrees)
- func (llv LatLonEllipsoidalVincenty) VincentyInverse(dest LatLon) (units.Distance, Degrees, Degrees)
- type LatLonPlanar
- func (lls LatLonPlanar) DestinationPoint(distance float64, bearing Degrees) LatLon
- func (lls LatLonPlanar) DistanceTo(dest LatLon) units.Distance
- func (lls LatLonPlanar) FinalBearingOn(ll LatLon) Degrees
- func (lls LatLonPlanar) InitialBearingTo(ll LatLon) Degrees
- func (lls LatLonPlanar) IntermediatePointTo(ll LatLon, fraction float64) LatLon
- func (lls LatLonPlanar) IntermediatePointsTo(ll LatLon, fractions []float64) []LatLon
- func (lls LatLonPlanar) LatLon() LatLon
- func (lls LatLonPlanar) MidPointTo(ll LatLon) LatLon
- type LatLonRhumb
- func (llr LatLonRhumb) DestinationPoint(distance float64, bearing Degrees) LatLon
- func (llr LatLonRhumb) DistanceTo(dest LatLon) units.Distance
- func (llr LatLonRhumb) FinalBearingOn(dest LatLon) Degrees
- func (llr LatLonRhumb) InitialBearingTo(dest LatLon) Degrees
- func (llr LatLonRhumb) IntermediatePointTo(dest LatLon, fraction float64) LatLon
- func (llr LatLonRhumb) IntermediatePointsTo(dest LatLon, fractions []float64) []LatLon
- func (llr LatLonRhumb) LatLon() LatLon
- func (llr LatLonRhumb) MidPointTo(dest LatLon) LatLon
- type LatLonSpherical
- func (lls LatLonSpherical) DestinationPoint(distance float64, bearing Degrees) LatLon
- func (lls LatLonSpherical) DistanceTo(dest LatLon) units.Distance
- func (lls LatLonSpherical) FinalBearingOn(dest LatLon) Degrees
- func (lls LatLonSpherical) InitialBearingTo(dest LatLon) Degrees
- func (lls LatLonSpherical) IntermediatePointTo(dest LatLon, fraction float64) LatLon
- func (lls LatLonSpherical) IntermediatePointsTo(dest LatLon, fractions []float64) []LatLon
- func (lls LatLonSpherical) Intersection(bearing1 Degrees, ll2 LatLon, bearing2 Degrees) LatLon
- func (lls LatLonSpherical) LatLon() LatLon
- func (lls LatLonSpherical) MidPointTo(dest LatLon) LatLon
- type MercatorPoint
- type Model
- type Vector3D
- func (v Vector3D) AngleTo(other Vector3D, n *Vector3D) float64
- func (v Vector3D) Copy() Vector3D
- func (v Vector3D) Cross(other Vector3D) Vector3D
- func (v Vector3D) DividedBy(f float64) Vector3D
- func (v Vector3D) Dot(other Vector3D) float64
- func (v Vector3D) Equals(other Vector3D) bool
- func (v Vector3D) Length() float64
- func (v Vector3D) Minus(other Vector3D) Vector3D
- func (v Vector3D) Negate() Vector3D
- func (v Vector3D) Plus(other Vector3D) Vector3D
- func (v Vector3D) RotateAround(axis Vector3D, angle Degrees) Vector3D
- func (v Vector3D) Str() string
- func (v Vector3D) Times(f float64) Vector3D
- func (v Vector3D) Unit() Vector3D
Constants ¶
const ( FormatDeg = iota // degrees FormatDegMin // degrees+minutes FormatDegMinSec // degrees+minutes+seconds )
FormatDeg, FormatDegMin and FormatDegMinSec are constants the control how FormatDMS should format the degree value.
const MercatorMaxLat = Degrees(85.05112877980644)
Variables ¶
This section is empty.
Functions ¶
func Distance ¶
func Distance(start, end LatLon, model EarthModel, modelArgs ...interface{}) units.Distance
Distance returns the distance in `DistanceUnits` between points `start` and `end` using the given `model`.
Arguments:
start - starting point end - end point (destination) model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns the distance in `DistanceUnits` If the distance cannot be calculated an invalid is returned, which can be tested using `DistanceUnits.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) p2 := geod.NewLatLon(12.1, -23.2) dist := geod.MidPoint(p1, p2, geod.VincentyModel, WGS84) // WGS84 can be omitted, it's the default and only
`Ellipsoid` currently defined
metres := dist.Metres()
func FormatDMS ¶
FormatDMS converts decimal degrees to a string in deg/min/sec format Degree, prime, double-prime symbols are added, but sign is discarded, though no compass direction is added. Degrees are zero-padded to 3 digits; for degrees latitude, use slice [1:] to remove a leading zero.
Arguments:
`deg` - degrees to be formatted as specified. `format` - one of FormatDeg, FormatDegMin or FormatDegMinSec (degrees, degrees+minutes, degrees+minutes+seconds) `dp` - number of decimal places to use - use -1 for defaults: 4 for d, 2 for dm, 0 for dms.
func MultiPolygonToMercator ¶ added in v0.0.5
func MultiPolygonToMercator(mp orb.MultiPolygon) orb.MultiPolygon
func SetEarthRadius ¶
func SetEarthRadius(r float64)
SetEarthRadius can be used to [globally] change the value of Earth's radius (in metres) used for spherical Earth calculations (includes rhumb). Default is 6371000m
Types ¶
type Cartesian ¶
type Cartesian Vector3D
Cartesian represents ECEF (earth-centered earth-fixed) geocentric cartesian coordinates
func (Cartesian) LatLonEllipsoidal ¶
func (c Cartesian) LatLonEllipsoidal(ellipsoid Ellipsoid) LatLonEllipsoidal
LatLonEllipsoidal converts this (geocentric) cartesian (x/y/z) coordinate to a (geodetic) latitude/longitude point on specified ellipsoid. Uses Bowring’s (1985) formulation for μm precision in concise form; `The accuracy of geodetic latitude and height equations' B R Bowring, Survey Review vol 28, 218, Oct 1985.
Argument
ellipsoid - the Ellipsoid to use for the conversion
Returns LatLonEllipsoidal - Latitude/longitude point defined by cartesian coordinates, on given ellipsoid.
Example c := geod.Cartesian{X: 4027893.924, Y: 307041.993, Z: 4919474.294} p := c.LatLon(geod.WGS84()) // 50.7978°N, 004.3592°E
type Degrees ¶
type Degrees float64
Degrees angle Defining it as a type makes it harder to mix Degrees and Radians in your code, you're welcome :)
func DegreesFromRadians ¶
DegreesFromRadians takes an argument in radians and returns it in degrees
func FinalBearing ¶
func FinalBearing(start, end LatLon, model EarthModel, modelArgs ...interface{}) Degrees
FinalBearing returns the final bearing having travelled from `start` to `end` using the given `model`.
Arguments:
start - starting point end - end point (destination) model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns the final bearing in `Degrees` from North If the bearing cannot be calculated NaN value is returned, which can be tested using `Degrees.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) p2 := geod.NewLatLon(12.1, -23.2) bearing := geod.FinalBearing(p1, p2, geod.SphericalModel)
func InitialBearing ¶
func InitialBearing(start, end LatLon, model EarthModel, modelArgs ...interface{}) Degrees
InitialBearing returns the initial bearing going from `start` to `end` using the given `model`.
Arguments:
start - starting point end - end point (destination) model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns the initial bearing in `Degrees` from North If the bearing cannot be calculated NaN value is returned, which can be tested using `Degrees.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) p2 := geod.NewLatLon(12.1, -23.2) bearing := geod.InitialBearing(p1, p2, geod.SphericalModel)
func ParseDMS ¶
ParseDMS parses a string representing Degrees-Minutes-Seconds into decimal degrees This is very flexible on formats, allowing signed decimal degrees, or deg-min-sec optionally suffixed by compass direction (NSEW); a variety of separators are accepted. Examples -3.62, '3 37 12W', '3°37′12″W'. Example: lat := geod.ParseDMS("51° 28′ 40.37″ N") lon := geod.ParseDMS("000° 00′ 05.29″ W") ll := geod.LatLng{Latitude: lat, Longitude: lng} <--- 51.4779°N, 000.0015°W
func Wrap90 ¶
Wrap90 constrains `degrees` to range -90..+90 (e.g. for latitude); -91 --> -89, 91 --> 89.
func Wrap180 ¶
Wrap180 constrains `degrees` to range -180..+180 (e.g. for longitude); -181 --> 179, 181 --> -179.
func Wrap360 ¶
Wrap360 contrains `degrees` to range 0..360 (e.g. for bearings); -1 --> 359, 361 --> 1.
type EarthModel ¶ added in v0.0.5
type Ellipsoid ¶
type Ellipsoid struct {
// contains filtered or unexported fields
}
Ellipsoid parameters The only ellipsoid defined is WGS84, for use in utm/mgrs, vincenty, nvector.
type LatLon ¶
LatLon represents a point on Earth defined by its Latitude and Longitude
func DestinationPoint ¶
func DestinationPoint(start LatLon, distance float64, bearing Degrees, model EarthModel, modelArgs ...interface{}) LatLon
DestinationPoint returns the destination point going from `start` having travelled `distance` on the given initial bearing, using the given `model`.
Arguments:
start - starting point distance - distance travelled, in metres -- Note: I might change this to DistanceUnits in the future (FIXME) bearing - initial bearing in `Degrees` from North model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns the final point (destination) If the point cannot be calculated an invalid point is returned, which can be tested using `LatLon.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) bearing := geod.Degrees(23.2) p2 := geod.Destination(p1, 100000.0, bearing, geod.RhumbModel) // 100kms from p1 heading 23.2 along a rhumb line
func IntermediatePoint ¶
func IntermediatePoint(start, end LatLon, fraction float64, model EarthModel, modelArgs ...interface{}) LatLon
IntermediatePoint returns the point at the given fraction between `start` and `end`.
Arguments:
start - starting point end - end point (destination) fraction - the fraction between the two points (0.0 = `start`, 1.0 = `end`) model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns the intermediate point at the given fraction. If the point cannot be calculated an invalid point is returned, which can be tested using `LatLon.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) p2 := geod.NewLatLon(12.1, -23.2) pInt := geod.IntermediatePoint(p1, p2, 0.24, geod.VincentyModel)
func IntermediatePoints ¶
func IntermediatePoints(start, end LatLon, fractions []float64, model EarthModel, modelArgs ...interface{}) []LatLon
IntermediatePoints returns a slice of points at the given fractions between `start` and `end`. This is far more efficient than multiple `IntermediatePoint` calls in a loop as some of the expensive calculations are reused and each franctional point is calculated in parallel.
Arguments:
start - starting point end - end point (destination) fractions - slice of fractions between the two points (0.0 = `start`, 1.0 = `end`) model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns slice of intermediate points at the given fractions. Points that cannot be calculated are returned as invalid points, can be tested using `LatLon.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) p2 := geod.NewLatLon(12.1, -23.2) pInt := geod.IntermediatePoint(p1, p2, 0.24, geod.VincentyModel)
func MidPoint ¶
func MidPoint(start, end LatLon, model EarthModel, modelArgs ...interface{}) LatLon
MidPoint returns the point halfway between `start` and `end` using the given `model`.
Arguments:
start - starting point end - end point (destination) model - a function that converts a `LatLon` to a structure appropriate for the `Model` to be used
This is how you select the model you wish to use for the calculations. See the description of `Model` for list of available functions.
modelArgs - additional arguments to pass to the `model` function, if needed, for example the `Ellipsoid`
for ellipsoid models.
Returns the halfway point. If the point cannot be calculated an invalid point is returned, which can be tested using `LatLon.Valid()`
Example: p1 := geod.NewLatLon(10.1, -20.0) p2 := geod.NewLatLon(12.1, -23.2) mid := geod.MidPoint(p1, p2, geod.SphericalModel)
func ParseLatLon ¶
ParseLatLon parses a latitude/longitude point from a variety of formats.
Latitude & longitude (in degrees) can be supplied as two separate string parameters or as a single comma-separated lat/lon string
The latitude/longitude values may be signed decimal or deg-min-sec (hexagesimal) suffixed by compass direction (NSEW) a variety of separators are accepted. Examples: -3.62, '3 37 12W', '3°37′12″W'.
Thousands/decimal separators must be comma/dot
Arguments: lat|latlon - Latitude (in degrees), or comma-separated lat/lon [lon] - Longitude (in degrees).
Returns Latitude/longitude point on WGS84 (LatLon)
Example: p1 := ParseLatLon(51.47788, -0.00147) // numeric pair p2 := ParseLatLon("51.47788", "-0.00147") // string pair p3 := ParseLatLon("51°28′40″N, 000°00′05″W") // single dms string p4 := ParseLatLon("51°28′40″N", "000°00′05″W") // dms lat string, dms lon string
func (LatLon) Equals ¶
Equals returns true if `ll` and `other` have identical Latitude and Longitude values
func (LatLon) MercatorPoint ¶ added in v0.0.5
func (ll LatLon) MercatorPoint() MercatorPoint
MercatorPoint converts the Latitude/Longitude pair to a X/Y coordinates using Mercator projection. The resulting coordinates will be in the [0..1] range, so for rendering images, multiply by the horizontal and vertical resolution. Latitudes over MercatorMaxLat are not supported.
type LatLonEllipsoidal ¶
LatLonEllipsoidal represents latitude/longitude points on an ellipsoidal model earth, with ellipsoid parameters and methods for converting points to/from cartesian (ECEF) coordinates.
This is the core struct, which will usually be used via LatLonEllipsoidalDatum or LatLonEllipsoidalReferenceFrame.
func NewLatLonEllipsodial ¶
func NewLatLonEllipsodial(latitude, longitude Degrees, height float64) LatLonEllipsoidal
NewLatLonEllipsodial creates a new LatLonEllipsoidal struct
func ParseLatLonEllipsoidal ¶
func ParseLatLonEllipsoidal(args ...interface{}) (LatLonEllipsoidal, error)
ParseLatLonEllipsoidal parses a latitude/longitude point from a variety of formats
Latitude & longitude (in degrees) can be supplied as two separate string parameters or as a single comma-separated lat/lon string
The latitude/longitude values may be signed decimal or deg-min-sec (hexagesimal) suffixed by compass direction (NSEW) a variety of separators are accepted. Examples: -3.62, '3 37 12W', '3°37′12″W'.
Thousands/decimal separators must be comma/dot
Arguments: lat|latlon - Latitude (in degrees), or comma-separated lat/lon [lon] - Longitude (in degrees). [height] - Height above ellipsoid in metres.
Returns Latitude/longitude point on WGS84 ellipsoidal model earth (LatLonEllipsoidal)
Example: p1 := ParseLatLon(51.47788, -0.00147) // numeric pair p2 := ParseLatLon("51.47788", "-0.00147") // string pair p3 := ParseLatLon("51°28′40″N, 000°00′05″W", 17) // dms string + height p4 := ParseLatLon("51°28′40″N", "000°00′05″W", 17) // dms lat, dms lon, height
func (LatLonEllipsoidal) Cartesian ¶
func (l LatLonEllipsoidal) Cartesian() Cartesian
Cartesian converts the point from (geodetic) latitude/longitude coordinates to (geocentric) cartesian (x/y/z) coordinates Returns the Cartesian point equivalent to lat/lon point, with x, y, z in metres from earth centre.
func (LatLonEllipsoidal) Equals ¶
func (l LatLonEllipsoidal) Equals(other LatLonEllipsoidal) bool
Equals checks if the `other` point is equal to this point
Example p1 := geod.LatLonEllipsoidal{52.205, 0.119, geod.WGS84()} p2 := geod.LatLonEllipsoidal{52.205, 0.119, geod.WGS84()} equal := p1.Equals(p2) // true
type LatLonEllipsoidalVincenty ¶
type LatLonEllipsoidalVincenty struct {
// contains filtered or unexported fields
}
LatLonEllipsoidalVincenty represents a point used for calculations using a the Vincenty method, on an ellipsoidal Earth model.
func NewLatLonEllipsodialVincenty ¶
func NewLatLonEllipsodialVincenty(latitude, longitude float64, ellipsoid Ellipsoid) LatLonEllipsoidalVincenty
NewLatLonEllipsodialVincenty creates a new LatLonEllipsoidalVincenty struct
func (LatLonEllipsoidalVincenty) DestinationPoint ¶
func (llv LatLonEllipsoidalVincenty) DestinationPoint(distance float64, bearing Degrees) LatLon
DestinationPoint returns the destination point having travelled the given `distance` along a geodesic given by `initialBearing` from `llv`, using Vincenty direct solution
Arguments:
distance - Distance travelled along the geodesic in metres initialBearing - Initial bearing in degrees from North
Returns the destination point ¶
Example p1 := geod.NewLatLonEllipsodialVincenty(-37.95103, 144.42487, geod.WGS84()) p2 := p1.DestinationPoint(54972.271, geod.Degrees(306.86816)) // 37.6528°S, 143.9265°E
func (LatLonEllipsoidalVincenty) DistanceTo ¶
func (llv LatLonEllipsoidalVincenty) DistanceTo(dest LatLon) units.Distance
DistanceTo returns the distance along the surface of the earth from `llv` to `dest` using Vincenty Inverse calculation
Argument:
dest - destination point
Returns the `Distance` between this point and destination point in DistanceUnits ¶
Examples: p1 := geod.NewLatLonEllipsodialVincenty(52.205, 0.119, geod.WGS84()) p2 := geod.LatLon{48.857, 2.351} d := p1.DistanceTo(p2).Metre() // 404.3×10³ m m := p1.DistanceTo(p2, 3959).Mile() // 251.2 miles
func (LatLonEllipsoidalVincenty) FinalBearingOn ¶
func (llv LatLonEllipsoidalVincenty) FinalBearingOn(dest LatLon) Degrees
FinalBearingOn returns the final bearing (review azimuth) having travelled along a geodesic from `llv` to `dest` using the Vincenty inverse solution
Arguments:
dest - destination point
Returns the final bearing in degrees from North (0°..360°) or NaN if failed to converge
Example: p1 := geod.NewLatLonEllipsodialVincenty(50.06632, -5.71475, geod.WGS84()) p2 := geod.LatLon{58.64402, -3.07009} b1 := p1.FinalBearingOn(p2) // 11.2972°
func (LatLonEllipsoidalVincenty) InitialBearingTo ¶
func (llv LatLonEllipsoidalVincenty) InitialBearingTo(dest LatLon) Degrees
InitialBearingTo returns the initial bearing (forward azimuth) to travel along a geodesic from `llv` to `dest` using the Vincenty inverse solution
Arguments:
dest - destination point
Returns the initial bearing in degrees from North (0°..360°) or NaN if failed to converge
Example: p1 := geod.NewLatLonEllipsodialVincenty(50.06632, -5.71475, geod.WGS84()) p2 := geod.LatLon{58.64402, -3.07009} b1 := p1.InitialBearingTo(p2) // 9.1419°
func (LatLonEllipsoidalVincenty) IntermediatePointTo ¶
func (llv LatLonEllipsoidalVincenty) IntermediatePointTo(dest LatLon, fraction float64) LatLon
IntermediatePointTo returns the points at the given fraction between `llv` and `dest`.
Arguments:
dest - destination point fraction - Fractions between the two points (0 = `llv`, 1 = `dest`)
Returns the intermediate point.
Example: p1 := geod.NewLatLonEllipsodialVincenty(52.205, 0.119, geod.WGS84()) p2 := geod.LatLon{48.857, 2.351} pInt := p1.IntermediatePointTo(p2, 0.25)
func (LatLonEllipsoidalVincenty) IntermediatePointsTo ¶
func (llv LatLonEllipsoidalVincenty) IntermediatePointsTo(dest LatLon, fractions []float64) []LatLon
IntermediatePointsTo returns the points at the given fractions between `llv` and `dest`.
Arguments:
dest - destination point fraction - Slice of fractions between the two points (0 = `llv`, 1 = `dest`)
Returns an intermediate point for each fraction ¶
Example: p1 := geod.NewLatLonEllipsodialVincenty(52.205, 0.119, geod.WGS84()) p2 := geod.LatLon{48.857, 2.351} pInt := p1.IntermediatePointsTo(p2, []float64{0.25, 0.5, 0.75})
func (LatLonEllipsoidalVincenty) LatLon ¶
func (llv LatLonEllipsoidalVincenty) LatLon() LatLon
LatLon converts LatLonEllipsoidalVincenty to LatLon
func (LatLonEllipsoidalVincenty) MidPointTo ¶
func (llv LatLonEllipsoidalVincenty) MidPointTo(dest LatLon) LatLon
MidPointTo returns the midpoint between `llv` and `dest`.
Argument:
dest - destination point
Returns the middle point ¶
Example: p1 := geod.NewLatLonEllipsodialVincenty(52.205, 0.119, geod.WGS84()) p2 := geod.LatLon{48.857, 2.351} pMid := p1.MidPointTo(p2)
func (LatLonEllipsoidalVincenty) VincentyDirect ¶
func (llv LatLonEllipsoidalVincenty) VincentyDirect(distance float64, initialBearing Degrees) (LatLon, Degrees)
VincentyDirect - Vincenty direct calculation - calculates the destination point and final bearing given the starting point, distance and initial bearing.
Arguments ¶
distance - Distance along bearing in metres initialBearing - Initial bearing in degrees from North
Returns (destination, finalBearing)
func (LatLonEllipsoidalVincenty) VincentyInverse ¶
func (llv LatLonEllipsoidalVincenty) VincentyInverse(dest LatLon) (units.Distance, Degrees, Degrees)
VincentyInverse - Vincenty inverse calculation. Calculates the distance, initial and final bearing going from point `llv` to `dest`, using the Vincenty method.
Arguments:
dest - destination point
Returns (distance from `llv` to `dest`, initial bearing in degrees from North, final bearing in degrees from North)
type LatLonPlanar ¶ added in v0.0.5
type LatLonPlanar struct {
// contains filtered or unexported fields
}
LatLonPlanar represents a point used for calculations on a 2-dimensional plane Longitudes still go -180 to 180 and wrap around and Latitudes go -90 to 90. Works across the antimeridian.
func NewLatLonPlanar ¶ added in v0.0.5
func NewLatLonPlanar(latitude, longitude float64) LatLonPlanar
NewLatLonPlanar creates a new LatLonPlanar struct
func ParseLatLonPlanar ¶ added in v0.0.5
func ParseLatLonPlanar(args ...interface{}) (LatLonPlanar, error)
ParseLatLonPlanar parses a latitude/longitude point from a variety of formats See ParseLatLon for details.
func (LatLonPlanar) DestinationPoint ¶ added in v0.0.5
func (lls LatLonPlanar) DestinationPoint(distance float64, bearing Degrees) LatLon
func (LatLonPlanar) DistanceTo ¶ added in v0.0.5
func (lls LatLonPlanar) DistanceTo(dest LatLon) units.Distance
func (LatLonPlanar) FinalBearingOn ¶ added in v0.0.5
func (lls LatLonPlanar) FinalBearingOn(ll LatLon) Degrees
func (LatLonPlanar) InitialBearingTo ¶ added in v0.0.5
func (lls LatLonPlanar) InitialBearingTo(ll LatLon) Degrees
Returns the initial bearing in Degrees from North (0°..360°)
func (LatLonPlanar) IntermediatePointTo ¶ added in v0.0.5
func (lls LatLonPlanar) IntermediatePointTo(ll LatLon, fraction float64) LatLon
func (LatLonPlanar) IntermediatePointsTo ¶ added in v0.0.5
func (lls LatLonPlanar) IntermediatePointsTo(ll LatLon, fractions []float64) []LatLon
func (LatLonPlanar) LatLon ¶ added in v0.0.5
func (lls LatLonPlanar) LatLon() LatLon
LatLon converts LatLonPlanar to LatLon
func (LatLonPlanar) MidPointTo ¶ added in v0.0.5
func (lls LatLonPlanar) MidPointTo(ll LatLon) LatLon
type LatLonRhumb ¶
type LatLonRhumb struct {
// contains filtered or unexported fields
}
LatLonRhumb represents a point used for calculations using a spherical Earth model, along rhumb lines
func NewLatLonRhumb ¶
func NewLatLonRhumb(latitude, longitude Degrees) LatLonRhumb
NewLatLonRhumb creates a new LatLonRhumb struct
func (LatLonRhumb) DestinationPoint ¶
func (llr LatLonRhumb) DestinationPoint(distance float64, bearing Degrees) LatLon
DestinationPoint returns the destination point from `lls` having travelled the given distance along a rhumb line on the given bearing.
Arguments:
distance - Distance travelled in metres bearing - Bearing in `Degrees` from North
Returns the destination point.
Example: p1 := geod.NewLatLonRhumb(51.127, 1.338) p2 := p1.DestinationPoint(40300, geod.Degrees(116.7)) // 50.9642°N, 001.8530°E
func (LatLonRhumb) DistanceTo ¶
func (llr LatLonRhumb) DistanceTo(dest LatLon) units.Distance
DistanceTo returns the distance along a rhumb line from `llr` to `dest`.
Argument:
dest - destination point
Returns the `Distance` between this point and destination point in Distance units.
Examples: p1 := geod.NewLatLonRhumb(51.127, 1.338) p2 := geod.NewLatLonRhumb(50.964, 1.853) d := p1.DistanceTo(p2).Km() // 40.31 km
func (LatLonRhumb) FinalBearingOn ¶
func (llr LatLonRhumb) FinalBearingOn(dest LatLon) Degrees
FinalBearingOn returns the bearing from `lls` to `dest`. In the case of rhumb lines the bearing is constant, so this is the same as the initial bearing.
Argument:
dest - destination point
Returns the rhumb bearing in `Degrees` from North (0°..360°)
Example: p1 := geod.NewLatLonRhumb(51.127, 1.338) p2 := geod.NewLatLonRhumb(50.964, 1.853) b1 := p1.FinalBearingOn(p2) // 116.7°
func (LatLonRhumb) InitialBearingTo ¶
func (llr LatLonRhumb) InitialBearingTo(dest LatLon) Degrees
InitialBearingTo returns the bearing from `lls` to `dest`. In the case of rhumb lines the bearing is constant, so this is the same as the final bearing.
Argument:
dest - destination point
Returns the rhumb bearing in `Degrees` from North (0°..360°)
Example: p1 := geod.NewLatLonRhumb(51.127, 1.338) p2 := geod.NewLatLonRhumb(50.964, 1.853) b1 := p1.InitialBearingTo(p2) // 116.7°
func (LatLonRhumb) IntermediatePointTo ¶
func (llr LatLonRhumb) IntermediatePointTo(dest LatLon, fraction float64) LatLon
IntermediatePointTo returns the point at the given fraction between `lls` and `dest` along a rhumb line
Arguments:
dest - destination point fraction - Fraction between the two points (0 = `lls`, 1 = `dest`)
Returns the intermediate point.
Example: p1 := geod.NewLatLonRhumb(51.127, 1.338) p2 := geod.NewLatLonRhumb(50.964, 1.853) pMid := p1.IntermediatePointTo(p2, 0.25) // 51.08625°N, 001.46692°E
func (LatLonRhumb) IntermediatePointsTo ¶
func (llr LatLonRhumb) IntermediatePointsTo(dest LatLon, fractions []float64) []LatLon
IntermediatePointsTo returns the points at the given fractions between `llr` and `dest`.
Arguments:
dest - destination point fraction - Slice of fractions between the two points (0 = `llr`, 1 = `dest`)
Returns an intermediate point for each fraction ¶
Example: p1 := geod.NewLatLonRhumb(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} pInt := p1.IntermediatePointsTo(p2, []float64{0.25, 0.5, 0.75})
func (LatLonRhumb) LatLon ¶
func (llr LatLonRhumb) LatLon() LatLon
LatLon converts LatLonRhumb to LatLon
func (LatLonRhumb) MidPointTo ¶
func (llr LatLonRhumb) MidPointTo(dest LatLon) LatLon
MidPointTo returns the loxodromic midpoint (along a rhumb line) between `llr` and `dest`.
Argument:
dest - destination point
Returns the middle point ¶
Example: p1 := geod.NewLatLonRhumb(51.127, 1.338) p2 := geod.NewLatLonRhumb(50.964, 1.853) pMid := p1.MidPointTo(p2) // 51.0455°N, 001.5957°E
type LatLonSpherical ¶
type LatLonSpherical struct {
// contains filtered or unexported fields
}
LatLonSpherical represents a point used for calculations using a spherical Earth model, along great circles
func NewLatLonSpherical ¶
func NewLatLonSpherical(latitude, longitude float64) LatLonSpherical
NewLatLonSpherical creates a new LatLonSpherical struct
func ParseLatLonSpherical ¶
func ParseLatLonSpherical(args ...interface{}) (LatLonSpherical, error)
ParseLatLonSpherical parses a latitude/longitude point from a variety of formats See ParseLatLon for details.
func (LatLonSpherical) DestinationPoint ¶
func (lls LatLonSpherical) DestinationPoint(distance float64, bearing Degrees) LatLon
DestinationPoint returns the destination point from `lls` having travelled the given distance on the given initial bearing (bearing normally varies around path followed).
Arguments:
distance - Distance travelled in metres bearing - Initial bearing in `Degrees` from North
Returns the destination point.
Example: p1 := geod.NewLatLonSpherical(51.47788, -0.00147) p2 := p1.DestinationPoint(7794, geod.Degrees(300.7)) // 51.5136°N, 000.0983°W
func (LatLonSpherical) DistanceTo ¶
func (lls LatLonSpherical) DistanceTo(dest LatLon) units.Distance
DistanceTo returns the distance along the surface of the earth from `lls` to `dest`.
Uses haversine formula: a = sin²(Δφ/2) + cosφ1·cosφ2 · sin²(Δλ/2); d = 2 · atan2(√a, √(a-1)). Use SetEarthRadius() to change the default value.
Argument:
dest - destination point
Returns the `Distance` between this point and destination point in Distance units.
Examples: p1 := geod.NewLatLonSpherical(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} d := p1.DistanceTo(p2).Metres() // 404.3×10³ m m := p1.DistanceTo(p2, 3959).Miles() // 251.2 miles
func (LatLonSpherical) FinalBearingOn ¶
func (lls LatLonSpherical) FinalBearingOn(dest LatLon) Degrees
FinalBearingOn returns the final bearing arriving at `dest` from `lls`; the final bearing will differ from the initial bearing by varying degrees according to distance and latitude.
Argument:
dest - destination point
Returns the initial bearing in `Degrees` from North (0°..360°)
Example: p1 := geod.NewLatLonSpherical(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} b1 := p1.FinalBearingOn(p2) // 157.9°
func (LatLonSpherical) InitialBearingTo ¶
func (lls LatLonSpherical) InitialBearingTo(dest LatLon) Degrees
InitialBearingTo returns the initial bearing from `lls` to `dest`.
Argument:
dest - destination point
Returns the initial bearing in `Degrees` from North (0°..360°)
Example: p1 := geod.NewLatLonSpherical(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} b1 := p1.InitialBearingTo(p2) // 156.2°
func (LatLonSpherical) IntermediatePointTo ¶
func (lls LatLonSpherical) IntermediatePointTo(dest LatLon, fraction float64) LatLon
IntermediatePointTo returns the point at the given fraction between `lls` and `dest`.
Arguments:
dest - destination point fraction - Fraction between the two points (0 = `lls`, 1 = `dest`)
Returns the intermediate point.
Example: p1 := geod.NewLatLonSpherical(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} pInt := p1.IntermediatePointTo(p2, 0.25) // 51.3721°N, 000.7073°E
func (LatLonSpherical) IntermediatePointsTo ¶
func (lls LatLonSpherical) IntermediatePointsTo(dest LatLon, fractions []float64) []LatLon
IntermediatePointsTo returns the points at the given fractions between `lls` and `dest`.
Arguments:
dest - destination point fraction - Slice of fractions between the two points (0 = `lls`, 1 = `dest`)
Returns an intermediate point for each fraction ¶
Example: p1 := geod.NewLatLonSpherical(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} pInt := p1.IntermediatePointsTo(p2, []float64{0.25, 0.5, 0.75})
func (LatLonSpherical) Intersection ¶
func (lls LatLonSpherical) Intersection(bearing1 Degrees, ll2 LatLon, bearing2 Degrees) LatLon
Intersection returns the point of intersection of two paths defined by point and bearing.
Arguments:
bearing1 - Initial bearing in `Degrees` from North from `lls` lls2 - Second point bearing2 - Initial bearing in `Degrees` from North from `lls2`
Returns the point of intersection of the 2 paths. If the intersection point cannot be calculated (e.g. infinite intersections) the returned point has NaN as Latitude and Longitude.
Example: p1 := geod.NewLatLonSpherical(51.8853, 0.2545) brng1 := geod.Degrees(108.547) p2 := geod.LatLon{49.0034, 2.5735} brng2 := geod.Degrees(32.435) pInt := p1.Intersection(brng1, p2, brng2) // 50.9078°N, 004.5084°E
func (LatLonSpherical) LatLon ¶
func (lls LatLonSpherical) LatLon() LatLon
LatLon converts LatLonSpherical to LatLon
func (LatLonSpherical) MidPointTo ¶
func (lls LatLonSpherical) MidPointTo(dest LatLon) LatLon
MidPointTo returns the midpoint between `lls` and `dest`
Argument:
dest - destination point
Returns the middle point ¶
Example: p1 := geod.NewLatLonSpherical(52.205, 0.119) p2 := geod.LatLon{48.857, 2.351} pMid := p1.MidPointTo(p2) // 50.5363°N, 001.2746°E
type MercatorPoint ¶ added in v0.0.5
func (MercatorPoint) LatLon ¶ added in v0.0.5
func (mp MercatorPoint) LatLon() LatLon
MercatorPoint convert a point in Mercator projection the a Latitude/Longitude. The Mercator coordinates must be in the [0..1] range, so divide by the horizontal/vertical resolution.
type Model ¶
type Model interface {
DistanceTo(ll LatLon) units.Distance
InitialBearingTo(ll LatLon) Degrees
FinalBearingOn(ll LatLon) Degrees
DestinationPoint(distance float64, bearing Degrees) LatLon
MidPointTo(ll LatLon) LatLon
IntermediatePointTo(ll LatLon, fraction float64) LatLon
IntermediatePointsTo(ll LatLon, fractions []float64) []LatLon
LatLon() LatLon
}
Model defines the Earth model used for calculations. The following models are implemented:
geod.SphericalModel - spherical Earth, along great circles geod.RhumbModel - spherical Earth, along rhumb lines geod.VincentyModel - ellipsoid Earth, high accuracy, slower than SphericalModel
func PlanarModel ¶ added in v0.0.5
PlanarModel returns a `Model` that wraps geodesy calculations using Planar model (2-dimensional plane) Only suitable for short distances.
func RhumbModel ¶
RhumbModel returns a `Model` that wraps geodesy calculations using spherical Earth model along rhumb lines
func SphericalModel ¶
SphericalModel returns a `Model` that wraps geodesy calculations using spherical Earth model along great circles
func VincentyModel ¶
VincentyModel returns a `Model` that wraps geodesy calculations using the Vincenty method on an ellipsoidal Earth model
type Vector3D ¶
type Vector3D struct {
X, Y, Z float64
}
Vector3D represents a 3 dimensional vector
func (Vector3D) AngleTo ¶
AngleTo calculates the angle between the vector and the `other` vector atan2(|p₁×p₂|, p₁·p₂) or if (extra-planar) `n` is not nil then atan2(n·p₁×p₂, p₁·p₂).
Arguments:
`other` - Vector whose angle is to be determined from the `v` vector `n` - Plane normal: if not nil, angle is signed +ve if `v` is clockwise looking along `n`, -ve in opposite direction
Returns the angle (in radians) between the `v` vector and the `other` vector in range 0..π if n is nil, or range -π..+π if n is not nil.
func (Vector3D) Cross ¶
Cross multiplies the vector by the `other` vector using cross (vector) product, returns the resulting vector
func (Vector3D) DividedBy ¶
DividedBy divides the vector by a scalar value Returns a copy of the divided vector.
func (Vector3D) Equals ¶
Equals returns true if the vector equals the `other` vector, false otherwise
func (Vector3D) Minus ¶
Minus subtracts the `other` vector from the vector Returns a copy of the resulting vector.
func (Vector3D) Negate ¶
Negate negates a vector to point in the opposite direction, returns the resulting vector
func (Vector3D) Plus ¶
Plus adds the `other` vector to the vector Returns a copy of the resulting vector.
func (Vector3D) RotateAround ¶
RotateAround rotates the vector around an axis by a specified angle
Arguments:
`axis` - The axis being rotated around. `angle` - The angle of rotation (in degrees)
Returns the rotated vector
func (Vector3D) Str ¶
Str returns a string representation of the vector, rounded to 3 decimal points