Python实现经纬度坐标转换为距离及角度-创新互联

今天就跟大家聊聊有关Python实现经纬度坐标转换为距离及角度,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

为灞桥等地区用户提供了全套网页设计制作服务,及灞桥网站建设行业解决方案。主营业务为网站建设、网站制作、灞桥网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

1 经纬度转换距离代码


#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Seven'


import math


# 计算距离
def getDistance(latA, lonA, latB, lonB):
  ra = 6378140 # 赤道半径
  rb = 6356755 # 极半径
  flatten = (ra - rb) / ra # Partial rate of the earth
  # change angle to radians
  radLatA = math.radians(latA)
  radLonA = math.radians(lonA)
  radLatB = math.radians(latB)
  radLonB = math.radians(lonB)

  pA = math.atan(rb / ra * math.tan(radLatA))
  pB = math.atan(rb / ra * math.tan(radLatB))
  x = math.acos(math.sin(pA) * math.sin(pB) + math.cos(pA) * math.cos(pB) * math.cos(radLonA - radLonB))
  c1 = (math.sin(x) - x) * (math.sin(pA) + math.sin(pB)) ** 2 / math.cos(x / 2) ** 2
  c2 = (math.sin(x) + x) * (math.sin(pA) - math.sin(pB)) ** 2 / math.sin(x / 2) ** 2
  dr = flatten / 8 * (c1 - c2)
  distance = ra * (x + dr)
  distance = round(distance / 1000, 4)
  return f'{distance}km'

分享文章:Python实现经纬度坐标转换为距离及角度-创新互联
URL分享:http://pwwzsj.com/article/coipss.html