2

I'm using pyproj in python and I want to get epsg code based on an existing Proj class. An example in version=1.9.6:

from pyproj import Proj
CGCS2000metre = Proj(init='EPSG:4544')
print(CGCS2000metre.srs)

# +units=m +init=epsg:4544 

As you can see, I can find epsg code 4544 in the return result. But I can't do it in version==2.1.3:

from pyproj import Proj
CGCS2000metre = Proj(init='EPSG:4544')
print(CGCS2000metre.srs)

# +proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs

I just want to get epsg code from an existing Proj.

How can I get epsg code in pyproj with version==2.1.3?

3

Use pyproj.CRS

from pyproj import CRS
CGCS2000metre = CRS('epsg:4544')
print(CGCS2000metre.to_epsg()) # prints "4544"

To get a CRS in the way you're already using pyproj, you can get a CRS object like this:

from pyproj import Proj
CGCS2000metre = Proj(init='EPSG:4544').crs
print(CGCS2000metre.to_epsg()) # prints None
print(CGCS2000metre.to_epsg(min_confidence=25) # prints "4544"

https://pyproj4.github.io/pyproj/stable/api/proj.html#pyproj.proj.Proj.crs

Your misunderstanding is that srs is "the string form of the user input used to create the Proj".

You might need to adjust the min_confidence. There's a Q&A to understand that parameter here: Explaining pyproj to_epsg min_confidence parameter?

  • I get None when I use from pyproj import Proj CGCS2000metre = Proj(init='EPSG:4544').crs print(CGCS2000metre.to_epsg()). – giser_yugang Jun 24 at 9:27
  • It's strange that I get 4544 when I use from pyproj import CRS CGCS2000metre = CRS('epsg:4544') print(CGCS2000metre.to_epsg()). But I can't get epsg code based on an existing Proj in this way. – giser_yugang Jun 24 at 9:46
  • 1
    Try to adjust the min_confidence param. (I've edited the question.) – alphabetasoup Jun 24 at 10:00
  • It works. Thank you very much. – giser_yugang Jun 24 at 10:05
  • I don't understand the min_confidence parameter here, so I made another question: gis.stackexchange.com/questions/326690/… I hope that's OK. – alphabetasoup Jun 24 at 10:19

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.