Convert latitude, longitude & altitude to local ENU coordinates

https://stackoverflow.com/questions/53408780/convert-latitude-longitude-altitude-to-local-enu-coordinates-in-python

Transformations between ECEF and ENU coordinates

https://www.nsstc.uah.edu/users/phillip.bitzer/python_doc/pyltg/_modules/pyltg/utilities/latlon.html

Convert WGS-84 geodetic locations (GPS readings) to Cartesian coordinates in a local tangent plane (Geodetic to ECEF to ENU)

coordinate transformations between geodetic, ecef and enu in python

具体实现代码:

csharp 复制代码
"""
This script provides coordinate transformations from Geodetic -> ECEF, ECEF -> ENU
and Geodetic -> ENU (the composition of the two previous functions). Running the script
by itself runs tests.
based on https://gist.github.com/govert/1b373696c9a27ff4c72a.
"""
import math

a = 6378137
b = 6356752.3142
f = (a - b) / a
e_sq = f * (2-f)

def geodetic_to_ecef(lat, lon, h):
    # (lat, lon) in WSG-84 degrees
    # h in meters
    lamb = math.radians(lat)
    phi = math.radians(lon)
    s = math.sin(lamb)
    N = a / math.sqrt(1 - e_sq * s * s)

    sin_lambda = math.sin(lamb)
    cos_lambda = math.cos(lamb)
    sin_phi = math.sin(phi)
    cos_phi = math.cos(phi)

    x = (h + N) * cos_lambda * cos_phi
    y = (h + N) * cos_lambda * sin_phi
    z = (h + (1 - e_sq) * N) * sin_lambda

    return x, y, z

def ecef_to_enu(x, y, z, lat0, lon0, h0):
    lamb = math.radians(lat0)
    phi = math.radians(lon0)
    s = math.sin(lamb)
    N = a / math.sqrt(1 - e_sq * s * s)

    sin_lambda = math.sin(lamb)
    cos_lambda = math.cos(lamb)
    sin_phi = math.sin(phi)
    cos_phi = math.cos(phi)

    x0 = (h0 + N) * cos_lambda * cos_phi
    y0 = (h0 + N) * cos_lambda * sin_phi
    z0 = (h0 + (1 - e_sq) * N) * sin_lambda

    xd = x - x0
    yd = y - y0
    zd = z - z0

    xEast = -sin_phi * xd + cos_phi * yd
    yNorth = -cos_phi * sin_lambda * xd - sin_lambda * sin_phi * yd + cos_lambda * zd
    zUp = cos_lambda * cos_phi * xd + cos_lambda * sin_phi * yd + sin_lambda * zd

    return xEast, yNorth, zUp

def geodetic_to_enu(lat, lon, h, lat_ref, lon_ref, h_ref):
    x, y, z = geodetic_to_ecef(lat, lon, h)
    
    return ecef_to_enu(x, y, z, lat_ref, lon_ref, h_ref)

if __name__ == '__main__':
    def are_close(a, b):
        return abs(a-b) < 1e-4

    latLA = 34.00000048
    lonLA = -117.3335693
    hLA = 251.702

    x0, y0, z0 = geodetic_to_ecef(latLA, lonLA, hLA)
    x = x0 + 1
    y = y0
    z = z0
    xEast, yNorth, zUp = ecef_to_enu(x, y, z, latLA, lonLA, hLA)
    assert are_close(0.88834836, xEast)
    assert are_close(0.25676467, yNorth)
    assert are_close(-0.38066927, zUp)

    x = x0
    y = y0 + 1
    z = z0
    xEast, yNorth, zUp = ecef_to_enu(x, y, z, latLA, lonLA, hLA)
    assert are_close(-0.45917011, xEast)
    assert are_close(0.49675810, yNorth)
    assert are_close(-0.73647416, zUp)

    x = x0
    y = y0
    z = z0 + 1
    xEast, yNorth, zUp = ecef_to_enu(x, y, z, latLA, lonLA, hLA)
    assert are_close(0.00000000, xEast)
    assert are_close(0.82903757, yNorth)
    assert are_close(0.55919291, zUp)

代码来源:https://gist.github.com/sbarratt/a72bede917b482826192bf34f9ff5d0b

等效于:

python中pymap3d函数或MATLAB中geodetic2enu函数。

相关推荐
_.Switch1 小时前
FastAPI 的进阶应用与扩展技术:异步编程与协程、websocket、celery
网络·数据库·python·websocket·网络协议·性能优化·fastapi
咖猫2 小时前
Guava 库中的 `Multimap` 是一个允许一个键对应多个值的集合 Guava `Multimap` 的基本代码示例:
开发语言·python·guava
觅远3 小时前
python实现Word转PDF(comtypes、win32com、docx2pdf)
python·pdf·自动化·word
CV猿码人4 小时前
在已经加载的页面中动态显示一段话或者一张图片
python
宸码4 小时前
【项目实战】ISIC 数据集上的实验揭秘:UNet + SENet、Spatial Attention 和 CBAM 的最终表现
人工智能·python·深度学习·神经网络·机器学习·计算机视觉
lly_csdn1235 小时前
【路径规划】原理及实现
python·算法·路径规划
豌豆花下猫5 小时前
Python 潮流周刊#82:美国 CIA 如何使用 Python?(摘要)
后端·python·ai
资源补给站6 小时前
大恒相机开发(1)—Python调用采集彩色图像并另存为本地
开发语言·python·数码相机
旷野..6 小时前
GPT 时代,精进编程思维 + 熟练 Prompt 是否是新的编程范式?
python·gpt·prompt
m0_748249546 小时前
利用 FastAPI 和 Jinja2 模板引擎快速构建 Web 应用
前端·python·fastapi