Inaccuracy of the UTM to/from lat, lon conversion
See original GitHub issueWhen 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:
- Created 5 years ago
- Comments:13 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
and
now gives
Looks like PRs #46 and #47 have the same issue.