-
[Python] 지구의 타원을 고려한 거리계산 Package haversinepython 2021. 5. 20. 12:04
1. Package Install
1$ pip install haversinecs 2. Calculate the distance between Lyon and Paris
12345678910111213141516171819from haversine import haversine, Unitlyon = (45.7597, 4.8422) # (lat, lon)paris = (48.8567, 2.3508)haversine(lyon, paris)>> 392.2172595594006 # in kilometershaversine(lyon, paris, unit=Unit.MILES)>> 243.71201856934454 # in miles# you can also use the string abbreviation for units:haversine(lyon, paris, unit='mi')>> 243.71201856934454 # in mileshaversine(lyon, paris, unit=Unit.NAUTICAL_MILES)>> 211.78037755311516 # in nautical miles# 현재까지 호환되는 거리는 피트, 인치, 킬로미터, 미터, 마일, 나노마일이 있다.cs 3. Combine matrix
- 다양한 좌표들로부터 combined된 거리 matrix 추출
1234567891011from haversine import haversine_vector, Unitlyon = (45.7597, 4.8422) # (lat, lon)london = (51.509865, -0.118092)paris = (48.8567, 2.3508)new_york = (40.7033962, -74.2351462)haversine_vector([lyon, london], [paris, new_york], Unit.KILOMETERS, comb=True)>> array([[ 392.21725956, 343.37455271],[6163.43638211, 5586.48447423]])cs 'python' 카테고리의 다른 글
[python] index와 find의 차이 (0) 2021.07.08 [Python] Multiprocessing 예제 Code (0) 2021.07.01 [pip] requirements.txt 추출할 때 version대신 다른 reference가 생기는 bug (0) 2021.06.29 [Python] Command창에서 Argument 추가 argparse (0) 2021.04.09 [Python] Python 자동화 Schedule 모듈 (0) 2021.01.22