question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inaccuracy of the UTM to/from lat, lon conversion

See original GitHub issue

When converting coordinates from UTM to lat, lon then back to UTM with utm.to_latlon and utm.from_latlon you don’t end up on the initial point. The error is about 20 to 30 centimeters, depending on the position of the initial point.

import utm
import pyproj
import numpy as np

def utm_latlon_utm_error_with_utm_package(x, y, number, letter):
    lat, lon = utm.to_latlon(x, y, number, letter)
    x1, y1 = utm.from_latlon(lat, lon, force_zone_number=number)[:2]
    return np.linalg.norm([x1 - x, y1 - y])

def utm_latlon_utm_error_with_pyproj_package(x, y, number, letter):
    proj = '{:02d}{}'.format(number, letter)
    lon, lat = pyproj.transform(pyproj.Proj('+proj=utm +zone={}'.format(proj)),
                                pyproj.Proj('+proj=latlong'), x, y)
    x1, y1 = pyproj.transform(pyproj.Proj('+proj=latlong'),
                              pyproj.Proj('+proj=utm +zone={}'.format(proj)),
                              lon, lat)
    return np.linalg.norm([x1 - x, y1 - y])

def lon_lat_to_utm(lon, lat):
    n = utm.latlon_to_zone_number(lat, lon)
    l = utm.latitude_to_zone_letter(lat)
    proj = '{:02d}{}'.format(n, l)
    x, y = pyproj.transform(pyproj.Proj('+proj=latlong'),
                            pyproj.Proj('+proj=utm +zone={}'.format(proj)),
                            lon, lat)
    return x, y, n, l

lat, lon = 2.339404, 48.857767
x, y, n, l = lon_lat_to_utm(lon, lat)
print('Distance after UTM --> (lon, lat) --> UTM conversion')
print('\twith the utm package: {:.6f} m'.format(utm_latlon_utm_error_with_utm_package(x, y, n, l)))
print('\twith the pyproj package: {:.6f} m'.format(utm_latlon_utm_error_with_pyproj_package(x, y, n, l)))

Running this Python snippet gives:

Distance after UTM --> (lon, lat) --> UTM conversion
	with the utm package: 0.280308 m
	with the pyproj package: 0.000000 m

Any idea on where this might come from?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
chlxtcommented, Apr 12, 2020

and

utm.from_latlon(*utm.to_latlon(193185, 1833395, 29, 'Q'))

now gives

(193185.00006130006, 1833395.009825141, 29, 'Q')
0reactions
tjwilli58commented, Apr 18, 2020

Looks like PRs #46 and #47 have the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert between Latitude/Longitude & UTM coordinates
To convert a UTM coordinate to a (WGS-84) latitude/longitude point: ... This method based on Karney 2011 'Transverse Mercator with an accuracy of...
Read more >
Error While Converting UTM data to Lat-Long Coordinate
Now I can convert it using spTransform by the following piece of code and looks like the it correctly transforms the coordinates ,as...
Read more >
GeographicLib::UTMUPS Class Reference
The accuracy of the conversion is about 5nm. UTM eastings are allowed to be in the range [0km, 1000km], northings are allowed to...
Read more >
Lat/Lon and UTM Conversion
Convert Geographic Units. NOTE: UTM and NATO easting and northing values are rounded to the nearest meter. Conversions to NATO coordinates are only...
Read more >
Geographic coordinate conversion - Wikipedia
2.1 From geodetic to ECEF coordinates. 2.1.1 ; 2.2 From ECEF to geodetic coordinates · 2.2.2 ; 2.3 Geodetic to/from ENU coordinates. 2.3.1 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found