Find the nearest set of coordinates in Excel

血红的双手。 提交于 2019-12-30 05:31:04

问题


There are two tables, each with a coordinate pair: longitude and latitude, in decimal degrees (i.e, 37.23222, -121,3433). How do I match table A with its nearest coordinate pair in table B?


回答1:


You could try filling down this formula from G1 as shown below:

=LOOKUP(1,1/FREQUENCY(0,MMULT((B$1:C$10-E1:F1)^2,{1;1})),A$1:A$10)

For a more accurate formula that takes account of the circular distances try filling down from H1:

=LOOKUP(1,1/FREQUENCY(0,SIN((RADIANS(B$1:B$10-E1))/2)^2+SIN((RADIANS(C$1:C$10-F1))/2)^2*COS(RADIANS(B$1:B$10))*COS(RADIANS(E1))),A$1:A$10)




回答2:


This problem was solved back in 2006 by Tom Ogilvy here, also found here.

The sample that I created:

Original problem:

I have 20 named locations in a coordinates. Every point have x,y.

column a has the location name
column b has the x cooedinate
column c has the y coordinate

Now i have 400 coordinates in 2 columns (column e and f ) and want to have the name of the closest location (of the 20 named in column a) in column g.

Original solution by Tom Ogilvy:

Assuming original data starts in A1, B1 and C1 with first locations in E1 and F1

If you don't want to fill your sheet with formulas, you can put this in G1 committed/entered with Ctrl+Shift+Enter rather than just enter since it is an array formula, then drag fill it down the 400 rows.

=INDEX($A$1:$A$20,MATCH(MIN(SQRT(($B$1:$B$20-E1)^2+($C$1:$C$20-F1)^2)),SQRT( ($B$1:$B$20-E1)^2+($C$1:$C$20-F1)^2),0),1)



来源:https://stackoverflow.com/questions/28384055/find-the-nearest-set-of-coordinates-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!