Python根据经纬度求两点间距离
来源:互联网 发布:数据脱敏与数据匿名 编辑:程序博客网 时间:2024/05/17 06:14
Python程序根据经纬度求两点之间距离。
#!/usr/bin/python# -*- coding: UTF-8import mathdef get_distance(lon_1, lat_1, lon_2, lat_2): '''计算两点之间直线距离''' lon_a = lon_1 lat_a = lat_1 lon_b = lon_2 lat_b = lat_2 if not type(lon_a) in (int, float): lon_a = float(lon_a) if not type(lat_a) in (int, float): lat_a = float(lat_a) if not type(lon_b) in (int, float): lon_b = float(lon_b) if not type(lat_b) in (int, float): lat_b = float(lat_b) '''根据两点经纬度求直线距离''' if abs(lon_a - lon_b) < 0.000001 and abs(lat_a - lat_b) < 0.000001: return 0 re = 6378140 # 赤道半径 (m) rp = 6356755 # 极半径 (m) oblateness = (re - rp) / re # 地球扁率 rad_lat_a = math.radians(lat_a) rad_lon_a = math.radians(lon_a) rad_lat_b = math.radians(lat_b) rad_lon_b = math.radians(lon_b) atan_a = math.atan(rp / re * math.tan(rad_lat_a)) atan_b = math.atan(rp / re * math.tan(rad_lat_b)) tmp = math.acos(math.sin(atan_a) * math.sin(atan_b) + math.cos(atan_a) * math.cos(atan_b) * math.cos(rad_lon_a - rad_lon_b)) if tmp == 0: return 0 c1 = (math.sin(tmp) - tmp) * (math.sin(atan_a) + math.sin(atan_b)) ** 2 / math.cos(tmp / 2) ** 2 c2 = (math.sin(tmp) + tmp) * (math.sin(atan_a) - math.sin(atan_b)) ** 2 / math.sin(tmp / 2) ** 2 dr = oblateness / 8 * (c1 - c2) distance = re * (tmp + dr) return distanceif __name__ == '__main__': print(get_distance(116.314789,39.885771, 116.313549,39.889674))
0 0
- Python根据经纬度求两点间距离
- 根据经纬度求两点间距离实现源码(C#)
- 根据经纬度求两点间距离实现源码(C#)
- 根据经纬度求两点间距离实现源码(java)
- 根据经纬度求地球表面两点间距离的实现--JAVA
- 根据经纬度求两点间距离实现源码(java)
- C#根据经纬度求两点间距离的函数代码
- 根据经纬度计算两点间距离
- 根据经纬度计算两点间距离
- php 根据两点经纬度 获取两点间距离
- Android-根据两点间经纬度坐标,计算两点间距离
- 根据经纬度求两点间距离实现源码(C#)-非常精确
- 用C#根据经纬度求两点间距离的函数代码
- ArcGIS上根据经纬度求地球表面两点间距离的实现
- 求两点间距离
- 求两点间距离
- 求两点间距离
- 求两点间距离
- Vim使用笔记
- C++第一次实验1-1
- 快速开发框架androidannotations
- 03.C++学习笔记------C++默默编写哪些函数
- 二叉树 非递归遍历
- Python根据经纬度求两点间距离
- BIT2014级软件学院程序设计-12 编程珠玑
- 属性动画相关使用
- Highcharts技巧总结(持续更新)
- iOS(学习) UITableView
- Android开发中实现多点触摸
- IIS发布asp.net项目,要做的准备工作及添加项目
- java小游戏第三弹 贪吃蛇
- TCP/IP参考模型