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'
2 경위도 전환 각도 코드
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Seven'
import math
#
def getDegree(latA, lonA, latB, lonB):
radLatA = math.radians(latA)
radLonA = math.radians(lonA)
radLatB = math.radians(latB)
radLonB = math.radians(lonB)
dLon = radLonB - radLonA
y = math.sin(dLon) * math.cos(radLatB)
x = math.cos(radLatA) * math.sin(radLatB) - math.sin(radLatA) * math.cos(radLatB) * math.cos(dLon)
brng = math.degrees(math.atan2(y, x))
brng = round((brng + 360) % 360, 4)
brng = int(brng)
if (brng == 0.0) or ((brng == 360.0)):
return ' '
elif brng == 90.0:
return ' '
elif brng == 180.0:
return ' '
elif brng == 270.0:
return ' '
elif 0 < brng < 90:
return f' {brng}'
elif 90 < brng < 180:
return f' {brng - 90}'
elif 180 < brng < 270:
return f' {270 - brng}'
elif 270 < brng < 360:
return f' {brng - 270}'
else:
pass
3 검증심 천 사 파리(22.599578,113.973129)를 기점 으로 심 천 평 산 역(22.6986848,114.331032)을 종점 으로 바 이 두 지도,구 글 지도 등 을 결합 해 효과 검증 을 실시 했다.
프로그램 실행 결 과 는 다음 과 같 습 니 다.
바 이 두 측정 거 리 는 38.3km 이다.
Google 지도 수 동 거리 39.31km
거리 와 각도 모두 문제 가 없다.
파 이 썬 경위도 좌표 가 거리 와 각도 로 전환 되 는 실현 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 파 이 썬 경위도 좌표 가 거리 와 각도 로 전환 되 는 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Python의 None과 NULL의 차이점 상세 정보그래서 대상 = 속성 + 방법 (사실 방법도 하나의 속성, 데이터 속성과 구별되는 호출 가능한 속성 같은 속성과 방법을 가진 대상을 클래스, 즉 Classl로 분류할 수 있다.클래스는 하나의 청사진과 같아서 하나의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.