Python – Fixing Wrong Coordinates When Converting UTM to Lon/Lat with Proj

pyprojpython

I have tried many ways to convert UTM to lon/lat, and getting always the same weird result.

Getting UTM and lon/lat for a point using GoogleEarth:

from pyproj import Proj

lon = -40.729124
lat = -20.967705

z = 24
l = 'k'
posx = 320235.13
posy = 7680455.66

myProj = Proj("+proj=utm +zone=24K, +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs")

clon, clat = myProj(posx, posy, inverse=True)

print(clon, clat)

I get…

-43.534213641680765 69.17434868536577

What do I missing?

Best Answer

try "+proj=utm +zone=24 +south +datum=WGS84 +units=m +no_defs ". use epsg.io to identify the appropriate proj4 input, look at the bottom of the page.

another alternative is just use epsg code which is easier like this,

Proj('EPSG:32724')


alternatively using geopandas

from geopandas import GeoSeries
from shapely.geometry import Point

posx = 320235.13
posy = 7680455.66

# utm 24s is equivalent to epsg:32724
lon, lat = GeoSeries([Point(posx, posy)], crs='EPSG:32724').to_crs('epsg:4326')[0].coords[0] 

print(lon, lat)

# this prints -20.967705012999282 -40.729123995168585  
Related Question