1 Star 1 Fork 4

bitq/CesiumFlight

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
coordinate_conv.py 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
bitq 提交于 3年前 . 首次提交
# -*- coding: utf-8 -*-
# @Time : 2022/10/9 11:12
# @Author : bitQ
# @Site :
# @File : coordinate_conv.py
# @Software: PyCharm
import math
import numpy as np
CONSTANTS_RADIUS_OF_EARTH = 6371000. # meters (m)
'''
经纬度转xy坐标的简单实现
'''
# GPS经纬度转XY坐标
def GPStoXY(lat, lon, ref_lat, ref_lon):
# input GPS and Reference GPS in degrees
# output XY in meters (m) X:North Y:East
lat_rad = math.radians(lat)
lon_rad = math.radians(lon)
ref_lat_rad = math.radians(ref_lat)
ref_lon_rad = math.radians(ref_lon)
sin_lat = math.sin(lat_rad)
cos_lat = math.cos(lat_rad)
ref_sin_lat = math.sin(ref_lat_rad)
ref_cos_lat = math.cos(ref_lat_rad)
cos_d_lon = math.cos(lon_rad - ref_lon_rad)
arg = np.clip(ref_sin_lat * sin_lat + ref_cos_lat * cos_lat * cos_d_lon, -1.0, 1.0)
c = math.acos(arg)
k = 1.0
if abs(c) > 0:
k = (c / math.sin(c))
x = float(k * (ref_cos_lat * sin_lat - ref_sin_lat * cos_lat * cos_d_lon) * CONSTANTS_RADIUS_OF_EARTH)
y = float(k * cos_lat * math.sin(lon_rad - ref_lon_rad) * CONSTANTS_RADIUS_OF_EARTH)
return x, y
# XY坐标转GPS经纬度
def XYtoGPS(x, y, ref_lat, ref_lon):
x_rad = float(x) / CONSTANTS_RADIUS_OF_EARTH
y_rad = float(y) / CONSTANTS_RADIUS_OF_EARTH
c = math.sqrt(x_rad * x_rad + y_rad * y_rad)
ref_lat_rad = math.radians(ref_lat)
ref_lon_rad = math.radians(ref_lon)
ref_sin_lat = math.sin(ref_lat_rad)
ref_cos_lat = math.cos(ref_lat_rad)
if abs(c) > 0:
sin_c = math.sin(c)
cos_c = math.cos(c)
lat_rad = math.asin(cos_c * ref_sin_lat + (x_rad * sin_c * ref_cos_lat) / c)
lon_rad = (ref_lon_rad + math.atan2(y_rad * sin_c, c * ref_cos_lat * cos_c - x_rad * ref_sin_lat * sin_c))
lat = math.degrees(lat_rad)
lon = math.degrees(lon_rad)
else:
lat = math.degrees(ref_lat)
lon = math.degrees(ref_lon)
return lat, lon
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/bitq/cesium-flight.git
git@gitee.com:bitq/cesium-flight.git
bitq
cesium-flight
CesiumFlight
master

搜索帮助