utm

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 4 Imported by: 3

README

WGS84 UTM Conversion

GoDoc

Package for converting to and from the Universal Transverse Mercator coordinate system

Examples:

Lookup a zone by lat/lon, srid code, or text

zone := utm.LatLonZone(50.77535, 6.008)
zone, _ := utm.LookupSRID(32601)
zone, _ := utm.ParseZone("32U")

Convert from lat/lon to UTM

easting, northing := zone.ToUTM(50.77535, 6.008)

Convert from UTM to lat/lon

latitude, longitude := zone.ToLatLon(294408.917, 5628897.997)

Credit:

This was mostly copied from: https://github.com/Turbo87/utm

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Zone

type Zone struct {
	Number int  // Zone number 1 to 60
	Letter rune // Zone letter C to X (omitting O, I)
	North  bool // Zone hemisphere
}

Zone specifies the zone number and hemisphere

func LatLonZone

func LatLonZone(latitude, longitude float64) Zone

LatLonZone returns the Zone for the provided coordinates

Example
package main

import (
	"fmt"

	"github.com/icholy/utm"
)

func main() {
	fmt.Println(utm.LatLonZone(50.77535, 6.008))
}
Output:

32U (north)

func LookupSRID

func LookupSRID(srid int) (Zone, bool)

LookupSRID returns a Zone by its EPSG/SRID code. Since the srid code only specifies the longitude zone number, the zone letter is left unset.

Example
package main

import (
	"fmt"

	"github.com/icholy/utm"
)

func main() {
	if zone, ok := utm.LookupSRID(32617); ok {
		fmt.Println(zone)
	}
}
Output:

17? (north)

func ParseZone

func ParseZone(s string) (Zone, bool)

ParseZone parses a zone number followed by a zone letter

Example
package main

import (
	"fmt"

	"github.com/icholy/utm"
)

func main() {
	if zone, ok := utm.ParseZone("4S"); ok {
		fmt.Println(zone)
	}
}
Output:

4S (north)

func ToUTM

func ToUTM(latitude, longitude float64) (easting, northing float64, zone Zone)

ToUTM convert a EPSG:4326 latitude/longitude to UTM.

Example
package main

import (
	"fmt"

	"github.com/icholy/utm"
)

func main() {
	easting, northing, zone := utm.ToUTM(50.77535, 6.008)
	fmt.Println("Zone:", zone)
	fmt.Printf("Easting: %f\n", easting)
	fmt.Printf("Northing: %f\n", northing)
}
Output:

Zone: 32U (north)
Easting: 289059.493943
Northing: 5629111.846925

func (Zone) CentralMeridian

func (z Zone) CentralMeridian() float64

CentralMeridian returns the zone's center longitude

func (Zone) SRID

func (z Zone) SRID() int

SRID returns the zone EPSG/SRID code

func (Zone) String

func (z Zone) String() string

String returns a text representation of the zone

func (Zone) ToLatLon added in v0.4.0

func (z Zone) ToLatLon(easting, northing float64) (latitude, longitude float64)

ToLatLon converts UTM coordinates to EPSG:4326 latitude/longitude Note: the zone's North field must be correctly set, the letter is ignored

Example
package main

import (
	"fmt"

	"github.com/icholy/utm"
)

func main() {
	zone, _ := utm.LookupSRID(32632)
	latitude, longitude := zone.ToLatLon(289059.493943, 5629111.846925)
	fmt.Printf("Latitude: %f\n", latitude)
	fmt.Printf("Longitude: %f\n", longitude)
}
Output:

Latitude: 50.775350
Longitude: 6.008000

func (Zone) ToUTM added in v0.5.0

func (z Zone) ToUTM(latitude, longitude float64) (easting, northing float64)

ToUTM convert a EPSG:4326 latitude/longitude to UTM.

func (Zone) Valid

func (z Zone) Valid() bool

Valid checks if the zone is valid

Jump to

Keyboard shortcuts

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