karimbahgat / PyCRS

Projection creation, and conversion to misc formats
MIT License
98 stars 20 forks source link

Point transform issue #42

Closed wsf1990 closed 5 years ago

wsf1990 commented 5 years ago

Hi, I found a new issue,I have a location which is (lon, lat) (215018.25, 4824066.75), and the CRS is EPSG:32650. When I transform this location to epsg:4326 use this code:

lon, lat = 215018.25, 4824066.75
to_proj = pycrs.parse.from_ogc_wkt('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]').to_proj4()
from_proj = pycrs.parse.from_epsg_code(32650).to_proj4()
t_lon, t_lat = pyproj.transform(pyproj.Proj(from_proj), pyproj.Proj(to_proj), lon, lat)
print(t_lon, t_lat)

I got this result: -6.5258322207676605 43.51516233549309.

Which the lat is right, but the lon is wrong(the correct lon is about 113°),I think the question is located in the CRS’s center of Longitude.

wsf1990 commented 5 years ago

I use gdaltransform got the correct answer:

gdaltransform -s_srs EPSG:32650 -t_srs EPSG:4326
215018.25 4824066.75

which print:

113.474167779232 43.5151623354931 0
micahcochran commented 5 years ago

What version of pyproj are you using? I'm using pyproj 2.1.3, CRS is a new class in pyproj. If I need to change the code for a specific pyproj version I certainly can.

from pyproj import CRS, transform

wgs84 = CRS.from_epsg(4326)
utm50 = CRS.from_epsg(32650)

transform(utm50, wgs84, lon, lat)

Result:

(43.51516233549308, 113.47416777923233)

The current version of pyproj CRS takes a lot of CRS representation.

Pyproj version 2+ can do a lot of this kind of CRS handling because the underlying C library PROJ does a lot of this now, which makes PyCRS library less necessary.

wsf1990 commented 5 years ago

My pyproj version is 1.9.6.Do your result correct? Should the lon lat reverse?

micahcochran commented 5 years ago

CRS won't work in pyproj version 1.9.6.

Here's code for 1.9.6.

from pyproj import transform, Proj
wgs84 = Proj(init="epsg:4326")
utm50 = Proj(init="epsg:32650")
lon, lat = 215018.25, 4824066.75

transform(utm50, wgs84, lon, lat)

Result:

(113.47416777923233, 43.51516233549308)

Should the lon lat reverse? I don't know what is going on there.

wsf1990 commented 5 years ago

Thanks! I'll upgrade the pyproj version.But I think there is something wrong with the transform fn in pyproj 2.1.3.

wsf1990 commented 5 years ago

I have test the two methods. And got the same answer as you.The result of two methods was reverse.

micahcochran commented 5 years ago

If this is happening on the latest release, 2.2.1, it would be well worth reporting it to pyproj's repo.

The only issue with upgrade pyproj is that you will have to upgrade PROJ, too.

wsf1990 commented 5 years ago

I'll try. What's your meaning of upgrade PROJ?

micahcochran commented 5 years ago

PROJ is the C library that is under the hood of pyproj. pyproj 1.9.6 has PROJ 4.9.3(I think). pyproj version 2+ required PROJ version 6+ . Unless you have PROJ 6+, you won't be able install pyproj 2+.

karimbahgat commented 5 years ago

So was this a pyproj or pycrs issue?

wsf1990 commented 5 years ago

Maybe it's caused by pyproj.

karimbahgat commented 5 years ago

Sounds good, closing the issue then.