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

问题描述 投票:0回答:3

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

excel excel-formula coordinates worksheet-function
3个回答
12
投票

您可以尝试从

G1
填写这个公式,如下所示:

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

要获得考虑圆距离的更准确的公式,请尝试从

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)

enter image description here


3
投票

这个问题早在 2006 年就被 Tom Ogilvy 解决了这里,也发现了这里

我创建的示例:

enter image description here

原问题:

我在坐标中有 20 个命名位置。每个点都有 x,y。

a 列有位置名称
b 列有 x 坐标
c 列有 y 坐标

现在我在 2 列( e 列和 f 列)中有 400 个坐标,并且想要 g 列中最近的位置(a 列中指定的 20 个位置)的名称。

Tom Ogilvy 的原始解决方案:

假设原始数据从A1、B1和C1开始,第一个位置在E1 和 F1

如果您不想在表格中填写公式,您可以将其放在 G1 中 使用 Ctrl+Shift+Enter 提交/输入,而不是仅仅输入,因为它是 一个数组公式,然后拖动填充到 400 行。

=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)


0
投票

感谢您的解决方案! 如果您正在使用动态数组,这也可能是一个解决方案:

=BYROW(SQRT((Table!A2#-TRANSPOSE(Table!D2#))^2+(Table!B2#-TRANSPOSE(Table!E2#))^2),LAMBDA(array,INDEX(C3#,MATCH(MIN(array),array,0))))

A2# - X coordinates of main data set.
B2# - Y coordinates of main data set.
C2# - Location name of points to be matched with the closest coordinates of the main data set.
D2# - X coordinates to be matched with the main.
E2# - Y coordinates to be matched with the main.
© www.soinside.com 2019 - 2024. All rights reserved.