-
Notifications
You must be signed in to change notification settings - Fork 0
/
llatoxyz.py
26 lines (19 loc) · 938 Bytes
/
llatoxyz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# convert lla to xyz
# we list as lon lat alt
import pyproj
from math import sqrt
lon0, lat0, alt0 = {-16.424020795, 64.013078821, 31.473}
lon, lat, alt = {-16.424020922, 64.013078898, 31.483}
def geodetic_to_cartesian(longitude, latitude, altitude):
# Define the input and output coordinate systems
input_crs = pyproj.CRS("EPSG:4326") # WGS84 geodetic coordinates
output_crs = pyproj.CRS("EPSG:4978") # Cartesian coordinates (X, Y, Z)
# Create a pyproj transformer
transformer = pyproj.Transformer.from_crs(input_crs, output_crs, always_xy=True)
# Convert geodetic coordinates to Cartesian coordinates
x, y, z = transformer.transform(longitude, latitude, altitude)
return x, y, z
# Convert to cartesian
x1, y1, z1 = geodetic_to_cartesian(lon0,lat0, alt0)
x0, y0, z0 = geodetic_to_cartesian(lon, lat, alt)
print(sqrt( (x0 - x1) ** 2) + (y0 - y1) ** 2 + (z0 - z1) ** 2)