python3-经纬度的相关计算
来源:互联网 发布:php打印九九乘法表 编辑:程序博客网 时间:2024/05/16 10:28
一.计算两个点之间的距离(经纬度的计算)
#from math import radians, cos, sin, asin, sqrtfrom math import *def haversine(lon1, lat1, lon2, lat2): # 经度1,纬度1,经度2,纬度2 (十进制度数) # 将十进制度数转化为弧度 # math.degrees(x):为弧度转换为角度 # math.radians(x):为角度转换为弧度 lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) # haversine公式 dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin( dlat /2 ) **2 + cos(lat1) * cos(lat2) * sin( dlon /2 ) **2 c = 2 * asin(sqrt(a)) r = 6371 # 地球平均半径,单位为公里 return c * r*1000if __name__=='__main__': a=haversine(103.85012,36.03653,103.84085,36.03842) print(a)#注:该结果的数值存在问题
二.计算多个经纬度的中心
#通过经纬度,找出中心点from math import *def center_geolocation(geolocations): x = 0 y = 0 z = 0 lenth = len(geolocations) for lon, lat in geolocations: lon = radians(float(lon)) lat = radians(float(lat)) x += cos(lat) * cos(lon) y += cos(lat) * sin(lon) z += sin(lat) x = float(x / lenth) y = float(y / lenth) z = float(z / lenth) return (degrees(atan2(y, x)), degrees(atan2(z, sqrt(x * x + y * y))))if __name__ == '__main__': locations = [[116.568627, 39.994879], [116.564791, 39.990511], [116.575012, 39.984311]] print(center_geolocation(locations))##结果(116.56947685224392, 39.98990040970147)
阅读全文
0 0
- python3-经纬度的相关计算
- 经纬度相关的一些计算
- 一个经纬度相关计算的C++类
- 一个经纬度相关计算的C++类
- 转:经纬度相关计算
- 经纬度相关计算
- 经纬度相关计算
- 经纬度距离等相关计算的不同语言实现
- 经纬度距离等相关计算的不同语言实现
- 关于经纬度计算的代码
- 经纬度距离的简化计算
- 计算两经纬度的距离
- arcgis 计算经纬度的面积
- 计算两个经纬度的距离
- 两点之间经纬度的计算
- 计算两个经纬度的距离
- 计算经纬度之间的距离
- 计算两点经纬度的距离
- iOS 苹果内购遇到的那些坑
- easyui datagrid 浏览器像素及改变表、列宽问题
- WindowManger与window进阶篇_1(ViewRootImpl深入理解,View测量)
- Surf描述子形成步骤
- 自定义控件总结1(Android开发艺术探索)
- python3-经纬度的相关计算
- 关于Http_build_query的用法
- 实时获取EditText的值并弹出提示
- Educational Codeforces Round 24 题解
- Oracle、Mysql、Hive多行转一列函数实现及异同
- 欢迎使用CSDN-markdown编辑器
- appkey使用时提示SHA1不一致(签名、SHA1、appkey)
- 将文件间的编译依存关系降至最低
- JAVA数据结构之线性表的链式存储结构——双向链表