多邊形求中心點(經緯度坐標點)


多邊形求中心點

因項目需要,需要求多個坐標點的中心點,在csdn中找到相關資料,該博主是參考stackoverflow中的版本,然后進行修改,這里做一個標記。

#-*- coding: UTF-8 -*-
from math import cos, sin, atan2, sqrt, pi ,radians, degrees
 
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)

參考鏈接:

  1. http://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs
  2. https://blog.csdn.net/sunny_12138/article/details/60883233


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM