development

지리적 근접성을 계산하는 공식

big-blog 2020. 11. 12. 19:00
반응형

지리적 근접성을 계산하는 공식


내 응용 프로그램에서 지리적 근접 검색을 구현해야하지만 사용할 올바른 공식에 대해 매우 혼란 스럽습니다. 웹 및 StackOverflow에서 몇 가지 검색 후 솔루션이 다음과 같음을 발견했습니다.

  1. 사용 하버 사인 공식을
  2. 사용 그레이트 서클 거리 공식을
  3. 데이터베이스에서 공간 검색 엔진 사용

옵션 # 3은 실제로 ATM에 대한 옵션이 아닙니다. 이제 나는 대원 거리 공식Haversine 공식동의어 이지만 분명히 내가 틀렸다고 항상 혼란스러워합니다 .

Haversine 공식

위의 스크린 샷은 MySQL 을 사용한 멋진 Geo (근접) 검색 문서 에서 가져온 것이며 다음 기능을 사용합니다.

ASIN, SQRT, POWER, SIN, PI, COS

또한 다음 과 같은 동일한 공식 ( Spherical Law of Cosines ) 변형을 보았습니다 .

(3956 * ACOS(COS(RADIANS(o_lat)) * COS(RADIANS(d_lat)) * COS(RADIANS(d_lon) - RADIANS(o_lon)) + SIN(RADIANS(o_lat)) * SIN(RADIANS(d_lat))))

다음 기능을 사용합니다.

ACOS, COS, RADIANS, SIN

나는 수학 전문가는 아니지만이 공식은 동일합니까? 나는 더 많은 변형과 공식 ( 코사인구면 법칙Vincenty의 공식 과 같은 -가장 정확한 것 같음)을 보았고 그것은 나를 더욱 혼란스럽게 만듭니다 ...

PHP / MySQL에서 구현할 좋은 범용 공식을 선택해야합니다. 누구든지 위에서 언급 한 공식의 차이점을 설명 할 수 있습니까?

  • 계산이 가장 빠른 것은 무엇입니까?
  • 어느 것이 가장 정확한 결과를 제공합니까?
  • 결과의 속도 / 정확도 측면에서 가장 좋은 것은 무엇입니까?

이 질문에 대한 귀하의 통찰력에 감사드립니다.


유일한 이론적 답변을 바탕으로 다음과 같은 대원 거리 공식을 테스트했습니다.

  • Vincenty 공식
  • Haversine 공식
  • 코사인의 구면 법칙

Vincenty 포뮬러 그러나, 천천히 죽어 가 (0.5 mm까지) 꽤 정확 .

하버 사인 포뮬러가 빨리 Vincenty 공식보다 훨씬, 나는 꽤 많이 허용 내 요구에 대한 6 약 초에 1 개 백만 계산을 실행할 수 있었다.

코사인 공식의 구형 법 것으로 밝혀 거의 두 배 빠른 하버 사인 수식으로, 및 정밀도 차이는 neglectfulness입니다 대부분의 사용 경우에.


다음은 몇 가지 테스트 위치입니다.

  • Google 본사 ( 37.422045, -122.084347)
  • 캘리포니아 주 샌프란시스코 ( 37.77493, -122.419416)
  • 프랑스 에펠 탑 ( 48.8582, 2.294407)
  • 오페라 하우스, 시드니 ( -33.856553, 151.214696)

Google 본사-캘리포니아 주 샌프란시스코 :

  • Vincenty 공식 : 49 087.066 meters
  • Haversine 공식 : 49 103.006 meters
  • 코사인의 구면 법칙 : 49 103.006 meters

Google 본사-프랑스 에펠 탑 :

  • Vincenty 공식 : 8 989 724.399 meters
  • Haversine 공식 : 8 967 042.917 meters
  • 코사인의 구면 법칙 : 8 967 042.917 meters

Google HQ-시드니 오페라 하우스 :

  • Vincenty 공식 : 11 939 773.640 meters
  • Haversine 공식 : 11 952 717.240 meters
  • 코사인의 구면 법칙 : 11 952 717.240 meters

보시다시피 Haversine Formula와 Spherical Law of Cosine 사이 에는 눈에 띄는 차이없지만 , 둘 다 Vincenty Formula에 비해 22km만큼 높은 거리 오프셋있습니다 .


The Law of Cosines and the Haversine Formula will give identical results assuming a machine with infinite precision. The Haversine formula is more robust to floating point errors. However, today's machines have double precision of the order of 15 significant figures, and the law of cosines may work just fine for you. Both these formulas assume spherical earth, whereas Vicenty's iterative solution (most accurate) assumes ellipsoidal earth (in reality the earth is not even an ellipsoid - it is a geoid). Some references: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html

It gets better: note the latitude to be used in the law of cosines as well as the Haversine is the geocentric latitude, which is different from geodetic latitude. For a sphere, these two are the same.

Which one is fastest to compute?

In order from fastest to slowest are: law of cosines (5 trig. calls) -> haversine (involves sqrt) -> Vicenty (have to solve this iteratively in a for loop)

Which one is most accurate?

Vicenty.

Which one is best when speed and accuracy are both considered?

If your problem domain is such that for the distances you are trying to calculate, the earth can be considered as flat, then you can work out (I am not going to give details) a formula of the form x = kx * difference in longitude, y = ky * difference in latitude. Then distance = sqrt(dxdx + dydy). If your problem domain is such that it can be solved with distance squared, then you won't have to take sqrt, and this formula will be as fast as you get possibly get. It has the added advantage that you can calculate the vector distance - x is distance in east direction, and y is distance in the north direction. Otherwise, experiment with the 3 and choose what works best in your situation.


So you want to:

  • sort records by distance from p0
  • select only records whose distance from p0 is less than r

The trick is that you don't exactly need to compute the great circle distance for that! You can do with any function from a pair of points to a real value that strictly grows with the great circle distance between the points. There are many such functions and some are much faster to compute than the various formulas for the exact great circle distance. One such function is the Euclidean distance in 3D. Converting latitude and longitude to a 3D point on the sphere doesn't involve inverse trigonometric functions.

x, Y, Z가 있으면 실제로 p0에서 점까지의 거리가 필요하지 않다는 것을 알 수 있습니다. p0에서 접하는 평면으로부터의 거리를 사용할 수도 있기 때문입니다. 이 거리는 또한 대원 거리에 따라 엄격하게 증가하며 X, Y, Z에서 선형 조합으로 계산됩니다. 제곱근도 필요하지 않습니다. 원하는 대권 거리에 해당하는 계수와 차단 거리를 미리 계산하기 만하면됩니다.

참고 URL : https://stackoverflow.com/questions/2096385/formulas-to-calculate-geo-proximity

반응형