UTM

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: GPL-3.0 Imports: 3 Imported by: 11

README

Build Status Coverage Status GoDoc

UTM

Bidirectional UTM-WGS84 converter for golang. It use logic from UTM python version by Tobias Bieniek

Usage

go get github.com/im7mortal/UTM

Convert a latitude, longitude into an UTM coordinate

    easting, northing, zoneNumber, zoneLetter, err := UTM.FromLatLon(40.71435, -74.00597, false)

Convert an UTM coordinate into a latitude, longitude.

    latitude, longitude, err := UTM.ToLatLon(377486, 6296562, 30, "V")

Since the zone letter is not strictly needed for the conversion you may also the northern parameter instead, which is a named parameter and can be set to either true or false. In this case you should define fields clearly(!). You can't set ZoneLetter or northern both.

    latitude, longitude, err := UTM.ToLatLon(377486, 6296562, 30, "", false)

The UTM coordinate system is explained on this Wikipedia page

Speed

Benchmark Amount of iterations Average speed
ToLatLon 10000000 123 ns/op
ToLatLonWithNorthern 10000000 121 ns/op
FromLatLon 20000000 80.6 ns/op

go test -bench=.

Full example

package main

import (
	"github.com/im7mortal/UTM"
	"fmt"
)

func main() {

	easting, northing, zoneNumber, zoneLetter, err := UTM.FromLatLon(40.71435, -74.00597, false)
	if err != nil {
		panic(err.Error())
	}
	fmt.Println(
		fmt.Sprintf(
			"Easting: %d; Northing: %d; ZoneNumber: %d; ZoneLetter: %s;",
			easting,
			northing,
			zoneNumber,
			zoneLetter,
		))

	easting, northing, zoneNumber, zoneLetter, err = UTM.FromLatLon(40.71435, -74.00597, true)
	if err != nil {
		panic(err.Error())
	}
	fmt.Println(
		fmt.Sprintf(
			"Easting: %d; Northing: %d; ZoneNumber: %d; ZoneLetter: %s;",
			easting,
			northing,
			zoneNumber,
			zoneLetter,
		))

	latitude, longitude, err := UTM.ToLatLon(377486, 6296562, 30, "", true)
	fmt.Println(fmt.Sprintf("Latitude: %.5f; Longitude: %.5f;", latitude, longitude))

	latitude, longitude, err = UTM.ToLatLon(377486, 6296562, 30, "V")
	fmt.Println(fmt.Sprintf("Latitude: %.5f; Longitude: %.5f;", latitude, longitude))

}

Authors

Documentation

Overview

Package UTM is bidirectional UTM-WGS84 converter for golang

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromLatLon

func FromLatLon(latitude, longitude float64, northern bool) (easting, northing float64, zoneNumber int, zoneLetter string, err error)

FromLatLon convert a latitude and longitude to Universal Transverse Mercator coordinates

func FromLatLonF deprecated

func FromLatLonF(lat, lon float64) (easting, northing float64)

Don't use it. It panic and return no error. FromLatLonF convert a latitude and longitude to Universal Transverse Mercator coordinates.

Deprecated: Use FromLatLon functions to converse instead.

func ToLatLon

func ToLatLon(easting, northing float64, zoneNumber int, zoneLetter string, northern ...bool) (latitude, longitude float64, err error)

ToLatLon convert Universal Transverse Mercator coordinates to a latitude and longitude Since the zone letter is not strictly needed for the conversion you may also the “northern“ parameter instead, which is a named parameter and can be set to either true or false. In this case you should define fields clearly You can't set ZoneLetter or northern both.

func ValidateLatLone

func ValidateLatLone(latitude, longitude float64) error

ValidateLatLone check that latitude and longitude are valid.

Types

type Coordinate deprecated

type Coordinate struct {
	Easting    float64
	Northing   float64
	ZoneNumber int
	ZoneLetter string
}

Coordinate contains coordinates in the Universal Transverse Mercator coordinate system

Deprecated: Use ToLatLon functions to convert LatLon instead.

func (*Coordinate) ToLatLon deprecated

func (coordinate *Coordinate) ToLatLon(northern ...bool) (LatLon, error)

ToLatLon convert Universal Transverse Mercator coordinates to a latitude and longitude Since the zone letter is not strictly needed for the conversion you may also the “northern“ parameter instead, which is a named parameter and can be set to either true or false. In this case you should define fields clearly You can't set ZoneLetter or northern both.

Deprecated: Use ToLatLon functions to convert LatLon instead.

type InputError

type InputError error

InputError allow to distinguish if an error is from UTM conversion functions.

type LatLon deprecated

type LatLon struct {
	Latitude  float64
	Longitude float64
}

LatLon contains a latitude and longitude

Deprecated: Use FromLatLon functions to convert LatLon instead.

func (*LatLon) FromLatLon deprecated

func (point *LatLon) FromLatLon() (coord Coordinate, err error)

FromLatLon convert a latitude and longitude to Universal Transverse Mercator coordinates

Deprecated: Use FromLatLon functions to convert LatLon instead.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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