skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.4k stars 211 forks source link

How do I convert back and forth between XYZ and Latitude, Longitude? #652

Closed troyrock closed 2 years ago

troyrock commented 2 years ago

I would like to compute a new latitude and longitude for a location related to an existing latitude and longitude by a distance along the Earth's surface.

x, y, z = wgs84.latlon(lat, long).itrs_xyz.km
x += 100  # km
y += 30  # km

How do I convert the new x,y,z coordinates into a latitude and longitude? Thank you.

brandon-rhodes commented 2 years ago

I would suggest taking a look at the excellent "geopy" library, which supports exactly that kind of calculation. Here's a Stack Overflow answer I just found that should address your use case:

https://stackoverflow.com/a/61460267/85360

Happily, you won't need to leave Earth (and ask Skyfield!) for that particular calculation.

Let me know if the sample code works for you, so I know whether to recommend it in the future!

troyrock commented 2 years ago

That's not the answer I expected at all! I expected Skyfield to have this functionality within it. Nevertheless, this did indeed work for me. Thanks for the useful pointer.