wgs84转ENU的代码
时间: 2024-05-12 10:19:42 浏览: 14
以下是将WGS84坐标系转换为ENU坐标系的Python代码:
```python
import math
def wgs84_to_enu(lat, lon, alt, ref_lat, ref_lon, ref_alt):
# Convert all coordinates to radians
lat = math.radians(lat)
lon = math.radians(lon)
alt = alt
ref_lat = math.radians(ref_lat)
ref_lon = math.radians(ref_lon)
ref_alt = ref_alt
# WGS84 constants
a = 6378137.0
b = 6356752.3142
f = (a - b) / a
e_sq = f * (2 - f)
# Intermediate calculation
N = a / math.sqrt(1 - e_sq * math.sin(ref_lat)**2)
# Convert to ECEF
x = (alt + N) * math.cos(lat) * math.cos(lon)
y = (alt + N) * math.cos(lat) * math.sin(lon)
z = (alt + (1 - e_sq) * N) * math.sin(lat)
ref_x = (ref_alt + N) * math.cos(ref_lat) * math.cos(ref_lon)
ref_y = (ref_alt + N) * math.cos(ref_lat) * math.sin(ref_lon)
ref_z = (ref_alt + (1 - e_sq) * N) * math.sin(ref_lat)
dx = x - ref_x
dy = y - ref_y
dz = z - ref_z
# Convert to ENU
east = -math.sin(ref_lon) * dx + math.cos(ref_lon) * dy
north = -math.sin(ref_lat) * math.cos(ref_lon) * dx - math.sin(ref_lat) * math.sin(ref_lon) * dy + math.cos(ref_lat) * dz
up = math.cos(ref_lat) * math.cos(ref_lon) * dx + math.cos(ref_lat) * math.sin(ref_lon) * dy + math.sin(ref_lat) * dz
return east, north, up
```
其中,`lat`、`lon`和`alt`表示待转换点的纬度、经度和高度,`ref_lat`、`ref_lon`和`ref_alt`表示参考点的纬度、经度和高度,返回值为相对于参考点的ENU坐标系中的东、北、天向坐标。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)