Bidirectional UTM-WGS84 converter for golang :earth_africa: :globe_with_meridians:

Overview

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

You might also like...
Markdown - Markdown converter for golang

markdown 🗣 Talks 💬 Join 🩸 Youtube ❤️ Sponsor Install via nami nami install ma

Numtow - Golang number to words converter

numtow golang library to convert number to words. Supported languages: kazakh, e

Simple ANSi to PNG converter written in pure Go

AnsiGo Description AnsiGo is a simple ANSi to PNG converter written in pure Go. It converts files containing ANSi sequences (.ANS) into PNG images. Fo

A CLI markdown converter written in Go.

MDConv is a markdown converter written in Go. It is able to create PDF and HTML files from Markdown without using LaTeX. Instead MDConv u

Client for KCORES CSPS to ATX Converter
Client for KCORES CSPS to ATX Converter

KCORES Link 描述 该 KCORES Link 软件是为 KCORES CSPS to ATX Converter (CSPS转ATX转换器) 而编写的软件界面, 通过接入串口通信读取CSPS输出的信息, 最终实时展示到WEB界面上. 下载并运行 Windows 用户直接下载本项目, 运行

go-playground-converter is formatter error response inspiration like express-validator in nodejs build on top go-playground-validator.

Go Playground Converter go-playground-converter is formatter error response inspiration like express-validator in nodejs build on top in go-playground

Hugo-to-Gemini Markdown converter

Hugo-to-Gemini converter This repo holds a converter of Hugo Markdown posts to text/gemini (also named Gemtext in this README). The converter is suppo

Universal JSON, BSON, YAML, CSV, XML converter with templates
Universal JSON, BSON, YAML, CSV, XML converter with templates

Universal JSON, BSON, YAML, CSV, XML translator to ANY format using templates Key features Various input formats (json, bson, yaml, csv, xml) Flexible

Simple Markdown to Html converter in Go.

Markdown To Html Converter Simple Example package main import ( "github.com/gopherzz/MTDGo/pkg/lexer" "github.com/gopherzz/MTDGo/pkg/parser" "fm

PCM converter - Resample part relies on SOXR.

Resample part relies on SOXR. To install make sure you have libsoxr installed, then run: go get -u github.com/ZhangJYd/pcm_convertor example: package

Quick and dirty Minecraft player head to SVG converter

Head SVG Quick and dirty Minecraft player head to SVG converter. Can be used to generate player head icons. Usage usage: Head SVG [-h|--help] -n|--nam

Link converter service converts URLs to deeplinks or deeplinks to URLs.

Link converter Link converter service converts URLs to deeplinks or deeplinks to URLs. The service responds to the incoming request and first checks w

Serial to Keyboard converter for Polar's card readers

polar-serial-to-keyboard Serial to Keyboard converter for Polar's card readers Configuration This program is intended to be run as a background proces

Eightbit - A converter to create shitty 8-bit like images

eightbit A converter to create shitty 8-bit like images. Usage To install: go in

Very simple SVG to PNG converter library using the Inkscape.

svg2png Description Very simple SVG to PNG converter library using the Inkscape.

JPEG-MPO Decoder / Converter Library and CLI Tool

MPO Decoder Library Simple Go JPEG MPO (Multi Picture Object) Decoder - Library and CLI Tool The library and CLI tool contain the ability to convert M

Typescript type declaration to PostgreSQL CREATE TABLE converter

ts2psql NOTE: This is WIP. Details in this readme are ideal state. Current usage: go build && ./ts2psql (or go build && ts2psql if on Windows OS). A s

hls converter.

hlsconv hls converter. 外部依赖 ffmpeg: 4.2.1 使用方式 linix/macos # 转换单个文件 bin/hlsconv -i video/in.mp4 -o outvideo/ # 批量转换文件 bin/hlsconv -i video/ -o outvide

T80nxbt - Thurastmaster-T80 to ProCon Converter

t80nxbt Thurastmaster-T80 to ProCon Converter. connection T80----usb----Raspberr

Comments
  • Is the conversion done right?

    Is the conversion done right?

    Hey guys,

    nice library easy to use, thank you for sharing:) I'm intending to use the library to convert latitude and longitude coordinates in Denmark, ie.UTM zone 32U.

    https://epsg.io/ as a benchmark I've created some tests to make sure that the conversions happen as expected. However, I don't get the expected results. I'm not sure if I missed something or there is a bug.

    Maybe you can see what's going on.

    With northing True i get the following, where x and y is the output from FromLatLon()

    longitude: 12.563896, x = 346855.561137268, want 724098.71
    latitude: 55.686714, y = 6.1739023650601385e+06, want 6.17717561e+06
    

    epsg.io Equivalent

    Have I missed something?

    opened by SAThomsen 2
  • `float64` for Coordinate{} ?

    `float64` for Coordinate{} ?

    Hi! Nice work on im7mortal/UTM! It's a sweet library :) Thanks!

    I was just wondering if there was any reason you chose int over float64 for UTM coordinates (Coordinate{})? My use case would benefit from a accuracy slightly better than 1 meter.

    Here's a pull request to use float64 instead. Please let me know what you think!

    opened by songgao 1
Releases(1.2.2)
Owner
Petr
Science fan. DIY enthusiast.
Petr
Go (golang) wrapper for GDAL, the Geospatial Data Abstraction Library

------------- About ------------- The gdal.go package provides a go wrapper for GDAL, the Geospatial Data Abstraction Library. More information about

null 232 Nov 12, 2022
OpenStreetMap PBF golang parser

pbf OpenStreetMap PBF golang encoder/decoder A golang based OpenStreetMap PBF encoder/decoder with a handy command line utility, pbf. pbf Command Line

Alan D. Cabrera 40 Oct 23, 2022
Totem - A Go library that can turn a single gRPC stream into bidirectional unary gRPC servers

Totem is a Go library that can turn a single gRPC stream into bidirectional unar

Joe Kralicky 2 Oct 12, 2022
XML to MAP converter written Golang

xml2map XML to MAP converter written Golang Sometimes there is a need for the representation of previously unknown structures. Such a universal repres

Babiv Sergey 42 Nov 25, 2022
Golang HTML to PDF Converter

Golang HTML to PDF Converter For reading any document, one prefers PDF format over any other formats as it is considered as a standard format for any

MindInventory 265 Nov 7, 2022
☄ The golang convenient converter supports Database to Struct, SQL to Struct, and JSON to Struct.

Gormat - Cross platform gopher tool The golang convenient converter supports Database to Struct, SQL to Struct, and JSON to Struct. 中文说明 Features Data

永林 288 Nov 18, 2022
Video converter with golang

Requirements Debian-like system (ubuntu, mint, etc...) with apt package manager Golang >1.15 Command tool make (use sudo apt install make -y to instal

Anaxita 2 Sep 10, 2022
Ethconvert: Ethereum unit converter written in golang

ethconvert Ethereum unit converter written in go. Install go get github.com/jon4

Jonah 1 Jul 24, 2022