簡介
根據(jù)多個經(jīng)緯度坐標計算中心點疆导;在stackoverflow中發(fā)現(xiàn)了一個解決方法赁项。需要將經(jīng)緯度進行轉(zhuǎn)化,將角度化為弧度就需用角度乘以π/180,反之就除以(π/180)澈段。
在Python提供了角度弧度轉(zhuǎn)化的函數(shù) :
radians():轉(zhuǎn)換角度為弧度的 悠菜。
degrees()方法:從弧度轉(zhuǎn)換到角度。
JAVA實現(xiàn)方式: http://www.reibang.com/p/c566903e44d0
代碼
# -*- coding: utf-8 -*-
# @Time : 2017/12/8
# @Author : fc.w
# @File : center_point_of_coordinates.py
from math import cos, sin, atan2, sqrt, radians, degrees
class CenterPointFromListOfCoordinates:
def center_geolocation(self, geolocations):
"""
輸入多個經(jīng)緯度坐標败富,找出中心點
:param geolocations: 集合
:return:
"""
x = 0
y = 0
z = 0
length = 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 / length)
y = float(y / length)
z = float(z / length)
return (degrees(atan2(y, x)), degrees(atan2(z, sqrt(x * x + y * y))))
if __name__ == '__main__':
centerObj = CenterPointFromListOfCoordinates()
list = [(112.977324, 28.178376), (112.975782, 28.172258)]
print(centerObj .center_geolocation(list))
參考文獻
[1]From stackoverflow