coco

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: MIT Imports: 5 Imported by: 0

README

coco

Package for converting coordinates between WGS84 Lon Lat, UTM and MGRS/UTMREF.

GoDoc

Supported conversions

utm.ToLL()   : converts from UTM to LL
utm.ToMGRS() : converts from UTM to MGRS
ll.ToUTM()   : converts from LL to UTM
ll.ToMGRS()  : converts from LL to MGRS
mgrs.ToUTM() : converts from MGRS to UTM
mgrs.ToLL()  : converts from MGRS to LL

Data objects

UTM  : ZoneNumber ZoneLetter Easting Northing
LL   : Longitude Latitude
MGRS : String

Abbreviations

Lon    : Longitude
Lat    : Latitude
MGRS   : Military Grid Reference System (same as UTMREF)
UTM    : Universal Transverse Mercator
UTMREF : UTM Reference System (same as MGRS)
WGS84  : World Geodetic System 1984 (same as EPSG:4326)

Remarks

  • Partial ported from JavaScript mgrs library.
  • See utility coordconv for standalone program.

Documentation

Overview

Package coco (coordinate conversion) provides methods for converting coordinates between WGS84 Lon Lat, UTM and MGRS/UTMREF.

Supported conversions:

utm.ToLL()   : converts from UTM to LL
utm.ToMGRS() : converts from UTM to MGRS
ll.ToUTM()   : converts from LL to UTM
ll.ToMGRS()  : converts from LL to MGRS
mgrs.ToUTM() : converts from MGRS to UTM
mgrs.ToLL()  : converts from MGRS to LL

Data objects:

UTM  : ZoneNumber ZoneLetter Easting Northing
LL   : Longitude Latitude
MGRS : String

Abbreviations:

Lon    : Longitude
Lat    : Latitude
MGRS   : Military Grid Reference System (same as UTMREF)
UTM    : Universal Transverse Mercator
UTMREF : UTM Reference System (same as MGRS)
WGS84  : World Geodetic System 1984 (same as EPSG:4326)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LL

type LL struct {
	Lat float64
	Lon float64
}

LL defines coordinate in Longitude / Latitude

func (LL) String

func (ll LL) String() string

String returns stringified LL object (order according to ISO-6709, precision 0.11 meter).

func (LL) ToMGRS

func (ll LL) ToMGRS(accuracy int) (MGRS, error)

ToMGRS converts Lon Lat to MGRS. accuracy holds the wanted accuracy in meters. Possible values are 1, 10, 100, 1000 or 10000 meters.

Example
ll := LL{Lon: -88.53, Lat: 51.95}
accuracy := 10 // meters
mgrs, err := ll.ToMGRS(accuracy)
if err != nil {
	log.Fatalf("error <%v> at ll.ToMGRS()", err)
}
fmt.Printf("%s -> %s (accuracy %d meters)\n", ll, mgrs, accuracy)
Output:

51.950000 -88.530000 -> 16UCC94855658 (accuracy 10 meters)

func (LL) ToUTM

func (ll LL) ToUTM() UTM

ToUTM converts Lon Lat to UTM.

Example
ll := LL{Lon: -115.08209766, Lat: 36.23612346}
utm := ll.ToUTM()
fmt.Printf("%s -> %s\n", ll, utm)
Output:

36.236123 -115.082098 -> 11S 672349 4011843

type MGRS

type MGRS string

MGRS defines cordinate in MGRS/UTMREF

func (MGRS) ToLL

func (mgrs MGRS) ToLL() (LL, int, error)

ToLL converts MGRS/UTMREF to Lon Lat.

Example
mgrs := MGRS("11SPA7234911844")
ll, accuracy, err := mgrs.ToLL()
if err != nil {
	log.Fatalf("error <%v> at mgrs.ToLL()", err)
}
fmt.Printf("%s (with accuracy %d meters) -> %s\n", mgrs, accuracy, ll)
Output:

11SPA7234911844 (with accuracy 1 meters) -> 36.236123 -115.082098

func (MGRS) ToUTM

func (mgrs MGRS) ToUTM() (UTM, int, error)

ToUTM converts MGRS/UTMREF to UTM.

Example
mgrs := MGRS("32ULC989564")
utm, accuracy, err := mgrs.ToUTM()
if err != nil {
	log.Fatalf("error <%v> at mgrs.ToUTM()", err)
}
fmt.Printf("%s -> %s (accuracy %d meters)\n", mgrs, utm, accuracy)
Output:

32ULC989564 -> 32U 398900 5756400 (accuracy 100 meters)

type UTM

type UTM struct {
	ZoneNumber int
	ZoneLetter byte
	Easting    float64
	Northing   float64
}

UTM defines coordinate in Universal Transverse Mercator

func (UTM) String

func (utm UTM) String() string

String returns stringified UTM object.

func (UTM) ToLL

func (utm UTM) ToLL() (LL, error)

ToLL converts UTM to Lon Lat.

Example
utm := UTM{ZoneNumber: 23, ZoneLetter: 'K', Easting: 611733, Northing: 7800614}
ll, err := utm.ToLL()
if err != nil {
	log.Fatalf("error <%v> at utm.ToLL()", err)
}
fmt.Printf("%s -> %s\n", utm, ll)
Output:

23K 611733 7800614 -> -19.887498 -43.932664

func (UTM) ToMGRS

func (utm UTM) ToMGRS(accuracy int) MGRS

ToMGRS converts UTM to MGRS/UTMREF. accuracy holds the wanted accuracy in meters. Possible values are 1, 10, 100, 1000 or 10000 meters.

Example
utm := UTM{ZoneNumber: 31, ZoneLetter: 'U', Easting: 700373, Northing: 5704554}
accuracy := 1 // meters
mgrs := utm.ToMGRS(accuracy)
fmt.Printf("%s -> %s\n", utm, mgrs)
Output:

31U 700373 5704554 -> 31UGT0037304554

Jump to

Keyboard shortcuts

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