GeodeticToGeocentric.py
1 |
#!/usr/bin/env python
|
---|---|
2 |
# -*- coding: utf-8 -*-
|
3 |
|
4 |
from math import cos, radians, sin, sqrt |
5 |
|
6 |
## Input
|
7 |
lat = 43.21009
|
8 |
lon = -78.120123
|
9 |
h = 124
|
10 |
|
11 |
## Ellipsoid Parameters: semi-major axis, reciprocal flattening
|
12 |
grs80 = 6378137, 298.257222100882711 |
13 |
wgs84 = 6378137, 298.257223563 |
14 |
|
15 |
|
16 |
def geodetic_to_geocentric(spheroid, latitude, longitude, height): |
17 |
"""
|
18 |
Return the Geocentric (Cartesian) Coordinates X, Y, Z
|
19 |
given:
|
20 |
- Datum spheroid given as a pair: semi-major axis, reciprocal flattening
|
21 |
- Geodetic Coordinates latitude, longitude (in degrees)
|
22 |
- Ellipsoid Height h (in metres)
|
23 |
"""
|
24 |
a, rf = spheroid |
25 |
ϕ = radians(latitude) |
26 |
λ = radians(longitude) |
27 |
sin_ϕ = sin(ϕ) |
28 |
e2 = (2 - 1 / rf) / rf # eccentricity squared |
29 |
N = a / sqrt(1 - e2 * sin_ϕ ** 2) # prime vertical radius of curvature |
30 |
r = (N + h) * cos(ϕ) # distance from z axis
|
31 |
X = r * cos(λ) |
32 |
Y = r * sin(λ) |
33 |
Z = ((1 - e2) * N + h) * sin_ϕ
|
34 |
|
35 |
return X, Y, Z
|
36 |
|
37 |
print(geodetic_to_geocentric(wgs84, lat, lon, h)) |