5
from pyproj import Proj

#converting lat/long - UTM
lats = -22.818009494
longs = -47.059235202
alt = 644.2332


myProj = Proj("+proj=utm +zone=23K, +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
x, y = myProj(longs, lats)

print (x, y)

I'm running this code and I'm getting this result below:

enter image description here

The E coordinate is right; however, the N coordinate is wrong

5
  • 1
    Why do you think it is wrong? Because of the negative value? Apr 14, 2021 at 0:06
  • It is wrong because I know the correct answer LOL.... Apr 14, 2021 at 0:14
  • 2
    Could you add the correct one? Apr 14, 2021 at 0:15
  • 288652.545 7475152.818. which is interesting that it worked in my previous UBUNTU. I don't know after uploading it's not working. Apr 14, 2021 at 0:18
  • this is a duplicate of gis.stackexchange.com/questions/370838/…
    – Mike T
    Apr 15, 2021 at 21:31

3 Answers 3

11

It might be related to the proj string you specified. Use CRS instead of the proj string.

from pyproj import Proj, CRS 

#converting lat/long - UTM
lat = -22.818009494
long = -47.059235202

crs = CRS.from_epsg(32723)  # 32723 -> UTM Zone 23S

myProj = Proj(crs)
x, y = myProj(long, lat)

print (x, y)

# OUT: 288652.54449622496 7475152.999493342

What is the best format for describing coordinate reference systems?

0
8

The issue is the stray comma and unnecessary latitude band K. With the proj string, +zone= must be a value between 1-60, so just use 23 without a comma:

myProj = Proj("+proj=utm +zone=23 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
x, y = myProj(longs, lats)
print(x, y)
# 288652.54449622496 7475152.999493342

If you are able to use pyproj version 2 or later, take advantage of the CRS/Transformer classes, as detailed in the other answers.

2
  • Interesting! Are commas ever used in valid proj strings? Apr 14, 2021 at 10:35
  • 1
    Commas are not expected for +zone (so this is partially a bug), but they are valid for multi-parameter terms e.g. +towgs84=-199.87,74.79,246.62
    – Mike T
    Apr 14, 2021 at 21:41
5

You can also use the transform method in Transformer class.

from pyproj import Transformer

# 4326: WGS84 (source), 32723: UTM Zone23S (target)
transformer = Transformer.from_crs(4326, 32723)

lat = -22.818009494
long = -47.059235202

x, y = transformer.transform(lat, long)

print (x, y)

# 288652.54449622496 7475152.999493342

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.