• Stars
    star
    443
  • Rank 98,504 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bidirectional UTM-WGS84 converter for python

utm

Bidirectional UTM-WGS84 converter for python

Usage

>>> import utm

Latitude/Longitude to UTM

Convert a (latitude, longitude) tuple into an UTM coordinate:

>>> utm.from_latlon(51.2, 7.5)
(395201.3103811303, 5673135.241182375, 32, 'U')

The syntax is utm.from_latlon(LATITUDE, LONGITUDE).

The return has the form (EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER).

You can also use NumPy arrays for LATITUDE and LONGITUDE. In the result EASTING and NORTHING will have the same shape. ZONE_NUMBER and ZONE_LETTER are scalars and will be calculated for the first point of the input. All other points will be set into the same UTM zone. Therefore it's a good idea to make sure all points are near each other.

>>> utm.from_latlon(np.array([51.2, 49.0]), np.array([7.5, 8.4]))
(array([395201.31038113, 456114.59586214]),
 array([5673135.24118237, 5427629.20426126]),
 32,
 'U')

UTM to Latitude/Longitude

Convert an UTM coordinate into a (latitude, longitude) tuple:

>>> utm.to_latlon(340000, 5710000, 32, 'U')
(51.51852098408468, 6.693872395145327)

The syntax is utm.to_latlon(EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER).

The return has the form (LATITUDE, LONGITUDE).

You can also use NumPy arrays for EASTING and NORTHING. In the result LATITUDE and LONGITUDE will have the same shape. ZONE_NUMBER and ZONE_LETTER are scalars.

>>> utm.to_latlon(np.array([395200, 456100]), np.array([5673100, 5427600]), 32, 'U')
(array([51.19968297, 48.99973627]), array([7.49999141, 8.3998036 ]))

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. Have a look at the unit tests to see how it can be used.

The UTM coordinate system is explained on this Wikipedia page.

Speed

The library has been compared to the more generic pyproj library by running the unit test suite through pyproj instead of utm. These are the results:

  • with pyproj (without projection cache): 4.0 - 4.5 sec
  • with pyproj (with projection cache): 0.9 - 1.0 sec
  • with utm: 0.4 - 0.5 sec

NumPy arrays bring another speed improvement (on a different computer than the previous test). Using utm.from_latlon(x, y) to convert one million points:

  • one million calls (x and y are floats): 1,000,000 Γ— 90Β΅s = 90s
  • one call (x and y are numpy arrays of one million points): 0.26s

Development

Create a new virtualenv and install the library via pip install -e .. After that install the pytest package via pip install pytest and run the unit test suite by calling pytest.

Changelog

see CHANGELOG.rst file

Authors

License

Copyright (C) 2012 Tobias Bieniek <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

sidebar-v2

A responsive sidebar with tabs for Leaflet, OpenLayers, Google Maps, ...
CSS
814
star
2

leaflet-sidebar

A responsive sidebar for Leaflet maps
JavaScript
487
star
3

webpack-notifier

webpack + node-notifier = build status system notifications
TypeScript
306
star
4

intellij-emberjs

Ember.js support for JetBrains IDEs (IntelliJ, WebStorm, ...)
Kotlin
215
star
5

aerofiles

waypoint, task, tracklog readers and writers for aviation
Python
45
star
6

Android-Action-Bar-Icon-Pack-Font

The offical Android Action Bar Icon Pack as an iconic webfont
JavaScript
43
star
7

apwlibrary

Android PDF Writer
Java
42
star
8

eslint-plugin-chai-expect

ESLint plugin that checks for common chai.js expect() mistakes
JavaScript
27
star
9

PasParse

Delphi port of the DGrok (C#) Delphi parser
Pascal
27
star
10

igc-parser

IGC flight log parser
TypeScript
27
star
11

flat-projection-rs

Fast geodesic distance approximations via flat surface projection
Rust
19
star
12

aeroscore

Gliding Competition Scoring
TypeScript
16
star
13

setup.py

setup.py cheatsheet
CSS
16
star
14

ember-qr-scanner

QR Code scanner component for Ember.js
JavaScript
12
star
15

ogn-web-gateway

OpenGliderNet Web-Gateway
Rust
11
star
16

chai-roughly

deep equals assertions with tolerance for chai
JavaScript
11
star
17

flight-club

an online glider simulator
Java
9
star
18

ogn-web-viewer

OpenGliderNet WebViewer
JavaScript
8
star
19

ember-cli-rollup

JavaScript
7
star
20

auto-dist-tag

Automatically rewrites the "publishConfig.tag" setting in your "package.json" file for you
JavaScript
7
star
21

aprs-parser-rs

APRS message parser for Rust
Rust
7
star
22

ember-cli-deploy-ftp

ember-cli-deploy wrapper for ftp-deploy
JavaScript
6
star
23

united-flarmnet

Merging FlarmNet, OGN and WeGlide live tracking data into a single FlarmNet file
Rust
6
star
24

cabwiz

Native Linux replacement for Microsoft's cabwiz.exe
Python
6
star
25

openvario-protocol

OpenVario serial port protocol specification
6
star
26

hosted-git-info-rs

Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab
JavaScript
6
star
27

chai-files

file system assertions for chai
JavaScript
5
star
28

github-labels

labels.json file for github-label-sync
5
star
29

toptherm-forecast-format

Reverse-engineered description of the DWD TopTherm forecast file format
4
star
30

igc-filename-parser

IGC flight log filename parser
JavaScript
4
star
31

open-flight-planner

Flight planning tool for glider pilots
JavaScript
3
star
32

flight-recorder-manufacturers

Flight Recorder Manufacturers and their assigned IGC codes
JavaScript
3
star
33

flarmnet.py

Python
3
star
34

DGrok

Delphi Parser
C#
3
star
35

segelflug-classifieds

Segelflug.de Kleinanzeigen Telegram Bot
HTML
2
star
36

skylines-ios-tracker

SkyLines tracking client for iOS
Objective-C
2
star
37

esp8266-nonos

Rust
2
star
38

libfap

(Unmaintained!) unofficial git mirror of libfap - APRS parser
Shell
2
star
39

openaip

OpenAIP file parser
JavaScript
2
star
40

semver-cargo

Parser and evaluator for Cargo's flavor of Semantic Versioning ... in JavaScript
TypeScript
2
star
41

flupp-rs

FluPP flight log file reader for Rust
Rust
2
star
42

FluPP

Pascal
1
star
43

sliding-menu

a sliding menu for Bootstrap 2.3
CSS
1
star
44

py-gpolyencode

Python modules for Google Maps polyline encoding
C++
1
star
45

multifix

Run simple fixes on multiple repositories
Rust
1
star
46

renovate-config

Shareable config presets for Renovate
JavaScript
1
star
47

mergejs.py

Standalone distribution of the mergejs tool of the OpenLayers project.
Python
1
star
48

actix-ogn

OpenGliderNetwork client for Rust based on actix
Rust
1
star
49

rust-igc

IGC file parser for Rust
Rust
1
star
50

lva-camo-status.vue

Vue
1
star
51

chrome-devtools-theme-firacode

Chrome DevTools theme with Fira Code font
JavaScript
1
star
52

avia-converter

Vereinsflieger.de to ameavia flight log converter
Python
1
star
53

strepla-api

scoring*StrePla "API" wrapper
HTML
1
star