在 Excel 中找到最近的一组坐标

Find the nearest set of coordinates in Excel

有两个 table,每个都有一个坐标对:经度和纬度,以十进制表示(即 37.23222,-121,3433)。如何将 table A 与其在 table B 中最近的坐标对匹配?

Tom Ogilvy 在 2006 年解决了这个问题 here, also found here

我创建的示例:

原题:

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.

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:$A,MATCH(MIN(SQRT(($B:$B-E1)^2+($C:$C-F1)^2)),SQRT( ($B:$B-E1)^2+($C:$C-F1)^2),0),1)

您可以尝试从 G1 中填写这个公式,如下所示:

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

要获得考虑到圆距离的更准确的公式,请尝试从 H1 向下填充:

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