Skip to main content

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 <Tobias.Bieniek@gmx.de>

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.

Metadata

Release files for utm 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for utm 0.9.0
File Size Uploaded
utm-0.9.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for utm 0.9.0
File Interpreter ABI Platform
utm-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / utm-0.9.0.tar.gz

Download URL utm-0.9.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1c8ffa6032631379374ceef05e6fea0ad42e9f09be0c3f91f7cc1b23f27be8a7
BLAKE2b-256 checksum
How to use checksums
589ad2cd5fec4f65f963fdd4f7a8a7f8992edeae7830751a1d8bd7261703f3fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / utm-0.9.0-py3-none-any.whl

Download URL utm-0.9.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
767592281e457dfacd71323ac69ff38e2f290d74526af91ca0924637de0e1d53
BLAKE2b-256 checksum
How to use checksums
45d2ccf2f47bfeb607db0c09865dea382f6ec5e6c9b93416f98452633f3c1c8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.1

2 release files

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

2 release files

0.3.0

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page