Geographic Information Systems Asked by Anarach on November 1, 2021
I am trying to convert a set of local co ordinates into lat/long and vice versa and I have the code for it taken from this site itself , the issue is When I do these conversions they are not resulting the same.
converting local co ordinates to lat long:
import pyproj
import utm
x = -20509.2462745155
y = -125891.862952247
p = pyproj.Proj("+proj=tmerc +lat_0=34.863361375 +lon_0=138.273186441 +k_0=1.000008632 +a=6378137.0 +b=6356752.314200002 +x_0=-20737.317 +y_0=-126072.022 +units=m +no_defs")
lon, lat = p(x, y, inverse=True)
print(lat,lon) = 34.864985295652794 138.27568068953587
I also tried the inverse of the above code and it is not working as well.
lat =34.864985295652794
lon= 138.27568068953587
p = pyproj.Proj("+proj=tmerc +lat_0=34.863361375 +lon_0=138.273186441 +k_0=1.000008632 +a=6378137.0 +b=6356752.314200002 +x_0=-20737.317 +y_0=-126072.022 +units=m +no_defs")
nx,ny=p(lat,lon,inverse=True)
print(nx,ny) = 138.50356927081015 36.00068760121446
converting lat long into local coordinates using UTM package.
x, y, zone, ut = utm.from_latlon(34.864985295652794, 138.27568068953587)
print(x,y) = 250960.9300530484 3861456.658975485
as you can see the second piece of code is not exactly returning the X and Y values from the first code snippet.
I am not sure why this is happening , also I can notice that the first couple of values match.
If this is not the proper way to perform this operation then , I would like to know how to approach this.
You are mixing and matching two distinct projections which why they don't match. You need to do something like this:
>>> import pyproj
>>> x = -20509.2462745155
>>> y = -125891.862952247
>>> lon, lat = p(x, y, inverse=True)
>>> print(lat,lon)
(34.864985295652794, 138.27568068953587)
>>> nx, ny = p(lon, lat, inverse=False)
>>> print(nx, ny)
(-20509.246274514833, -125891.8629522473)
>>> print (nx-x, ny-y)
(6.657501216977835e-10, -3.055902197957039e-10)
>>>
Which seems close enough to me.
Answered by Ian Turton on November 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP