My input is a point given as
x, y and an SRS name which specifies how to interpret the numbers. My goal is to convert these into
lon, lat in degrees.
I convert this by using this piece of code:
projection = pyproj.Proj(srs_name) lon, lat = projection(x, y, inverse=True)
A typical input is coordinates in meters and the name of an SRS which has meters as unit. The code above works fine in this case.
Sometimes the input is the SRS name "EPSG:4326", and the input coordinates then are given in degrees. From what I understand about EPSG:4326 this is correct, too. Since the input already is in degrees, the conversion done by
pyproj should not change anything, i. e.
projection(x, y, inverse=True) should return a
lon, lat with
lon == x and
lat == y.
Unfortunately this is not the case.
I figured by now that the
projection = pyproj.Proj('EPSG:4326') converts the input from degrees to radians. So if I use the
inverse=True variant, it converts radians to degrees. Since my input is not given in radians, the result will be nonsense (in degrees).
What I Tried
I played around with the kwargs
preserve_units=True. I tried giving it to the
pyproj.Proj() and to the call of the conversion (
projection(x, y, invers=True, radians=False)). None of the combinations I tried had any influence. The
inverse=True conversion always assumes radians as input.
I also tried figuring out if there is some kind of global switch in
pyproj to make it use degrees instead of radians. I didn't find any.
pyproj 2.2.0. From the git log of the project (as in Github) I understand that there have been some changes made in the recent past concerning the kwargs
radians. Version 2.2.0 could be older than these, and the changes could be a fix for my case.
I also found on https://epsg.io/4326 that the unit of EPSG:4326 is specified as
UNIT["degree",0.0174532925199433, ...] and this number is the factor between radians and degrees. This now looks like the unit of this EPSG in fact is radians. Should this be the case, then I wonder why my input is in degrees instead of radians if the SRS is EPSG:4326. Maybe the client (providing the input) does it wrong?
How do I have to change my use of
pyproj in order to not run into the problem anymore?