geodesy

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 5 Imported by: 1

README

go-geodesy

An incomplete transliteration of chrisveness/geodesy from JavaScript to Go


The original work (c) 2005-2019 Chris Veness and released under the MIT License


This is work in progress. Only needed functions have been translated.

Refer to https://github.com/recombinant/go-geodesy-test for tests.

Documentation

Index

Constants

View Source
const (
	CardinalPrecision compassPrecision = iota + 1
	InterCardinalPrecision
	SecondaryInterCardinalPrecision
)
View Source
const (
	RadToDeg = 180 / math.Pi
	DegToRad = math.Pi / 180
)

RadToDeg for conversion from degrees to radians DegToRad for conversion from radians to degrees

Variables

View Source
var (
	EllipsoidWGS84         = &Ellipsoid{a: 6378137, b: 6356752.314245, f: 1 / 298.257223563}
	EllipsoidAiry1830      = &Ellipsoid{a: 6377563.396, b: 6356256.909, f: 1 / 299.3249646}
	EllipsoidAiryModified  = &Ellipsoid{a: 6377340.189, b: 6356034.448, f: 1 / 299.3249646}
	EllipsoidBessel1841    = &Ellipsoid{a: 6377397.155, b: 6356078.962818, f: 1 / 299.1528128}
	EllipsoidClarke1866    = &Ellipsoid{a: 6378206.4, b: 6356583.8, f: 1 / 294.978698214}
	EllipsoidClarke1880IGN = &Ellipsoid{a: 6378249.2, b: 6356515.0, f: 1 / 293.466021294}
	EllipsoidGRS80         = &Ellipsoid{a: 6378137, b: 6356752.314140, f: 1 / 298.257222101}
	EllipsoidIntl1924      = &Ellipsoid{a: 6378388, b: 6356911.946, f: 1 / 297} // aka Hayford
	EllipsoidWGS72         = &Ellipsoid{a: 6378135, b: 6356750.5, f: 1 / 298.26}
)
View Source
var (
	// transforms: t in metres, s in ppm, r in arcseconds
	ED50       = &Datum{ellipsoid: EllipsoidIntl1924, transform: &Transform{tx: 89.5, ty: 93.8, tz: 123.1, s: -1.2, rx: 0.0, ry: 0.0, rz: 0.156}}                     // epsg.io/1311
	Irl1975    = &Datum{ellipsoid: EllipsoidAiryModified, transform: &Transform{tx: -482.530, ty: 130.596, tz: -564.557, s: -8.150, rx: 1.042, ry: 0.214, rz: 0.631}} // epsg.io/1954
	NAD27      = &Datum{ellipsoid: EllipsoidClarke1866, transform: &Transform{tx: 8, ty: -160, tz: -176, s: 0, rx: 0, ry: 0, rz: 0}}
	NAD83      = &Datum{ellipsoid: EllipsoidGRS80, transform: &Transform{tx: 0.9956, ty: -1.9103, tz: -0.5215, s: -0.00062, rx: 0.025915, ry: 0.009426, rz: 0.011599}}
	NTF        = &Datum{ellipsoid: EllipsoidClarke1880IGN, transform: &Transform{tx: 168, ty: 60, tz: -320, s: 0, rx: 0, ry: 0, rz: 0}}
	OSGB36     = &Datum{ellipsoid: EllipsoidAiry1830, transform: &Transform{tx: -446.448, ty: 125.157, tz: -542.060, s: 20.4894, rx: -0.1502, ry: -0.2470, rz: -0.8421}} // epsg.io/1314
	Potsdam    = &Datum{ellipsoid: EllipsoidBessel1841, transform: &Transform{tx: -582, ty: -105, tz: -414, s: -8.3, rx: 1.04, ry: 0.35, rz: -3.08}}
	TokyoJapan = &Datum{ellipsoid: EllipsoidBessel1841, transform: &Transform{tx: 148, ty: -507, tz: -685, s: 0, rx: 0, ry: 0, rz: 0}}
	WGS72      = &Datum{ellipsoid: EllipsoidWGS72, transform: &Transform{tx: 0, ty: 0, tz: -4.5, s: -0.22, rx: 0, ry: 0, rz: 0.554}}
	WGS84      = &Datum{ellipsoid: EllipsoidWGS84, transform: &Transform{tx: 0.0, ty: 0.0, tz: 0.0, s: 0.0, rx: 0.0, ry: 0.0, rz: 0.0}}
)

Datums; with associated ellipsoid, and Helmert transform parameters to convert from WGS 84 into given datum.

Note that precision of various datums will vary, and WGS-84 (original) is not defined to be accurate to better than ±1 metre. No transformation should be assumed to be accurate to better than a meter; for many datums somewhat less.

View Source
var Separator = ""

Separator character to be used to separate degrees, minutes, seconds, and cardinal directions.

Set to '\u202f' (narrow no-break space) for improved formatting.

@example

var p = new LatLon(51.2, 0.33);  // 51°12′00.0″N, 000°19′48.0″E
Separator = '\u202f';        // narrow no-break space
var pʹ = new LatLon(51.2, 0.33); // 51° 12′ 00.0″ N, 000° 19′ 48.0″ E

Functions

func CompassPoint1

func CompassPoint1(bearing float64) string

func CompassPoint2

func CompassPoint2(bearing float64, precision compassPrecision) string

Returns compass point (to given precision) for supplied bearing.

@param {number} bearing - Bearing in degrees from north. @param {number} [precision=3] - Precision (1:cardinal / 2:intercardinal / 3:secondary-intercardinal). @returns {string} Compass point for supplied bearing.

@example

var point = compassPoint(24)    // point = 'NNE'
var point = compassPoint(24, 1) // point = 'N'

func ParseDMS

func ParseDMS(dmsStr string) float64

Parses string representing degrees/minutes/seconds into numeric 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 (eg 3° 37′ 09″W). Seconds and minutes may be omitted.

@param {string|number} dmsStr - Degrees or deg/min/sec in variety of formats. @returns {number} Degrees as decimal number.

@example

var lat = ParseDMS('51° 28′ 40.12″ N')
var lon = ParseDMS('000° 00′ 05.31″ W')
var p1 = LatLon{lat, lon} // 51.4778°N, 000.0015°W

func ToBrng

func ToBrng(deg float64, format DmsFormat, dp uint) string

Converts numeric degrees to deg/min/sec as a bearing (0°..360°)

@param {number} deg - Degrees to be formatted as specified. @param {string} [format=dms] - Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec. @param {number} [dp=0|2|4] - Number of decimal places to use – default 0 for dms, 2 for dm, 4 for d. @returns {string} Degrees formatted as deg/min/secs according to specified format.

func ToDMS1

func ToDMS1(deg float64) *string

func ToDMS2

func ToDMS2(deg float64, format DmsFormat) *string

Converts decimal degrees to deg/min/sec format

  • degree, prime, double-prime symbols are added, but sign is discarded, though no compass direction is added.

@param {number} deg - Degrees to be formatted as specified. @param {string} [format=dms] - Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec. @param {number} [dp=0|2|4] - Number of decimal places to use – default 0 for dms, 2 for dm, 4 for d. @returns {string} Degrees formatted as deg/min/secs according to specified format.

func ToDMS3

func ToDMS3(deg float64, format DmsFormat, dp uint) *string

func ToLat2

func ToLat2(deg float64, format DmsFormat) string

func ToLat3

func ToLat3(deg float64, format DmsFormat, dp uint) string

Converts numeric degrees to deg/min/sec latitude (2-digit degrees, suffixed with N/S).

@param {number} deg - Degrees to be formatted as specified. @param {string} [format=dms] - Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec. @param {number} [dp=0|2|4] - Number of decimal places to use – default 0 for dms, 2 for dm, 4 for d. @returns {string} Degrees formatted as deg/min/secs according to specified format.

func ToLon2

func ToLon2(deg float64, format DmsFormat) string

func ToLon3

func ToLon3(deg float64, format DmsFormat, dp uint) string

Convert numeric degrees to deg/min/sec longitude (3-digit degrees, suffixed with E/W)

@param   {number} deg - Degrees to be formatted as specified.
@param   {string} [format=dms] - Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec.
@param   {number} [dp=0|2|4] - Number of decimal places to use – default 0 for dms, 2 for dm, 4 for d.
@returns {string} Degrees formatted as deg/min/secs according to specified format.

Types

type Datum

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

type DmsFormat

type DmsFormat int
const (
	FmtDMS DmsFormat = iota
	FmtDM
	FmtD
)

type Ellipsoid

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

Ellipsoid parameters; major axis (a), minor axis (b), and flattening (f) for each ellipsoid.

type LatLon

type LatLon struct {
	Lat, Lon float64
	Datum    *Datum
}

LatLon (polar) point with latitude & longitude values, on a specified datum.

Lat - Geodetic latitude in degrees.
Lon - Longitude in degrees.
Datum=WGS84 - Datum this point is defined within.

@example
	var p1 = LatLon{51.4778, -0.0016, WGS84}

Latitude was accurate many years before accurate timepieces were developed to enable the accurate measurement of longitude. Hence Lat/Lon. (Somewhat counter-intuitive for people used to x/y axes).

func NewLatLon

func NewLatLon(lat float64, lon float64) *LatLon

func (*LatLon) LatLonToOsGrid

func (point *LatLon) LatLonToOsGrid() OsGridRef

LatLonToOsGrid converts latitude/longitude to Ordnance Survey grid reference easting/northing coordinate.

Note formulation implemented here due to Thomas, Redfearn, etc is as published by OS, but is inferior to Krüger as used by e.g. Karney 2011.

@param   {LatLon}    point - latitude/longitude.
@returns {OsGridRef} OS Grid Reference easting/northing.

@example
	var p = new LatLon(52.65798, 1.71605);
	var grid = OsGridRef.latLonToOsGrid(p); // grid.toString(): TG 51409 13177
	// for conversion of (historical) OSGB36 latitude/longitude point:
	var p = new LatLon(52.65757, 1.71791, OSGB36);

func (*LatLon) ToString

func (point *LatLon) ToString(format DmsFormat, dp uint) string

Returns a string representation of ‘this’ point, formatted as degrees, degrees+minutes, or degrees+minutes+seconds.

@param   {string} [format=dms] - Format point as 'd', 'dm', 'dms'.
@param   {number} [dp=0|2|4] - Number of decimal places to use - default 0 for dms, 2 for dm, 4 for d.
@returns {string} Comma-separated latitude/longitude.

type OsGridRef

type OsGridRef struct {
	Easting, Northing float64
}

OsGridRef for Ordnance Survey (OS) grid references.

easting - Easting in metres from OS false origin.
northing - Northing in metres from OS false origin.

@example
	var grid = new OsGridRef(651409, 313177);

func NewOsGridRef

func NewOsGridRef(easting float64, northing float64) *OsGridRef

func (*OsGridRef) OsGridToLatLon

func (gridRef *OsGridRef) OsGridToLatLon(datum *Datum) *LatLon

Converts Ordnance Survey grid reference easting/northing coordinate to latitude/longitude (SW corner of grid square).

Note formulation implemented here due to Thomas, Redfearn, etc is as published by OS, but is inferior to Krüger as used by e.g. Karney 2011.

@param   {OsGridRef}    gridref - Grid ref E/N to be converted to lat/long (SW corner of grid square).
@param   {LatLon.datum} [datum=WGS84] - Datum to convert grid reference into.
@returns {LatLon}       Latitude/longitude of supplied grid reference.

@example
	var gridref = new OsGridRef(651409.903, 313177.270);
	var pWgs84 = OsGridRef.osGridToLatLon(gridref);            // 52°39′28.723″N, 001°42′57.787″E
	// to obtain (historical) OSGB36 latitude/longitude point:
	var pOsgb = OsGridRef.osGridToLatLon(gridref, OSGB36);     // 52°39′27.253″N, 001°43′04.518″E

func (*OsGridRef) ToString

func (gridRef *OsGridRef) ToString(digits uint) string

*

  • Converts ‘gridRef’ numeric grid reference to standard OS grid reference. *
  • @param {number} [digits=10] - Precision of returned grid reference (10 digits = metres);
  • digits=0 will return grid reference in numeric format.
  • @returns {string} This grid reference in standard format. *
  • @example
  • var ref = new OsGridRef(651409, 313177).toString(); // TG 51409 13177

type Transform

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL