如何在Excel中找到给定经纬度的前三个最近位置?

huangapple go评论74阅读模式
英文:

How to Find Top 3 Nearest Location Given Lat Long in Excel?

问题

所以我在Excel中有2个工作表,名为Sheet1和Sheet2。表格结构如下:

Sheet1

如何在Excel中找到给定经纬度的前三个最近位置?

Sheet2

如何在Excel中找到给定经纬度的前三个最近位置?

我想要从Sheet1找到离Sheet2最近的3个位置。预期输出的示例应该如下:

如何在Excel中找到给定经纬度的前三个最近位置?

我已经尝试过=LOOKUP(1,1/FREQUENCY(0,MMULT((Sheet2!B$2:C$5-Sheet1!B2:C2)^2,{1;1})), Sheet2!A$2:A$5),但它只给了我最近的1个位置。

Excel版本:Excel 365

提前感谢!

英文:

so I have 2 sheets in Excel named Sheet1 and Sheet2. The table structure simply like below:

Sheet1

如何在Excel中找到给定经纬度的前三个最近位置?

Sheet2

如何在Excel中找到给定经纬度的前三个最近位置?

I want to find 3 nearest location from Sheet1 to Sheet2. Example of expected output should be:

如何在Excel中找到给定经纬度的前三个最近位置?

I already tried =LOOKUP(1,1/FREQUENCY(0,MMULT((Sheet2!B$2:C$5-Sheet1!B2:C2)^2,{1;1})), Sheet2!A$2:A$5) but it only gave me 1 nearest location only.

Excel version: Excel 365

Thanks in advance!

答案1

得分: 2

以下是翻译好的内容:

"Formula in E1:

=REDUCE("最近 #"&{1,2,3},ROW(A2:A6),LAMBDA(x,y,VSTACK(x,TAKE(TOROW(SORTBY(A9:A13,ABS(INDEX(B:B,y)-B9:B13)+ABS(INDEX(C:C,y)-C9:C13))),,3))))

Using a calculated distance of ABS(lat1-lat2)+ABS(long1-long2) gave me the exact same results as trying to find the actual distance in, say miles, using other more intricate formulae like this one. Are you sure about your desired results?"

英文:

Right, at risk of having a faulty calculation of distance, try:

如何在Excel中找到给定经纬度的前三个最近位置?

Formula in E1:

=REDUCE("Nearest #"&{1,2,3},ROW(A2:A6),LAMBDA(x,y,VSTACK(x,TAKE(TOROW(SORTBY(A9:A13,ABS(INDEX(B:B,y)-B9:B13)+ABS(INDEX(C:C,y)-C9:C13))),,3))))

Using a calculated distance of ABS(lat1-lat2)+ABS(long1-long2) gave me the exact same results as trying to find the actual distance in, say miles, using other more intricate formulae like this one. Are you sure about your desired results?

答案2

得分: 0

这是一个使用VLOOKUP()函数进行两个X值之间的线性插值以得到计算的Y值的示例。

=VLOOKUP(A2,$A$5:$B$8,2,1)+((A2-(VLOOKUP(A2+5,$A$5:$B$8,1,1)-VLOOKUP(A2,$A$5:$B$8,1,1)))/(VLOOKUP(A2+5,$A$5:$B$8,1,1)-VLOOKUP(A2,$A$5:$B$8,1,1)))*(VLOOKUP(A2+5,$A$5:$B$8,2,1)-VLOOKUP(A2,$A$5:$B$8,2,1))

用这个来从蒸汽表格,也就是水和空气属性表格中获取温度、密度等数据。

英文:

So an example of vlookup() being used to do a straight line interpolation between two X values to give the calculated Y value.

=VLOOKUP(A2,$A$5:$B$8,2,1)+((A2-(VLOOKUP(A2+5,$A$5:$B$8,1,1)-VLOOKUP(A2,$A$5:$B$8,1,1)))/(VLOOKUP(A2+5,$A$5:$B$8,1,1)-VLOOKUP(A2,$A$5:$B$8,1,1)))*(VLOOKUP(A2+5,$A$5:$B$8,2,1)-VLOOKUP(A2,$A$5:$B$8,2,1))

如何在Excel中找到给定经纬度的前三个最近位置?

Used this to get temperatures, density etc from steam tables aka tables of the properties of water and air.

答案3

得分: 0

我使用了勾股定理距离来使用SUMPRODUCT和INDEX计算最近的位置。

Sheet1:

如何在Excel中找到给定经纬度的前三个最近位置?

Sheet2:

如何在Excel中找到给定经纬度的前三个最近位置?

请注意,我只添加了一个名为Alpacca的测试列和一个名次列,仅用于检查我的输出,但您不需要它们。

数组公式(您必须按下<kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>ENTER</kbd>来输入它):

=INDEX(Sheet2!$A$2:$A$6,SUMPRODUCT(--(SMALL (SQRT (($B2-Sheet2!$B$2:$B$6)^2+($C2-Sheet2!$C$2:$C$6)^2), RIGHT (D$1,1))= SQRT (($B2-Sheet2!$B$2:$B$6)^2+($C2-Sheet2!$C$2:$C$6)^2))*ROW(Sheet2!$A$2:$A$6))-1)

如果出现2个或更多位置恰好在相同的距离上,该公式将无法工作并返回错误的输出。

英文:

I've used the Pythagoras distance to calculate nearest location using SUMPRODUCT and INDEX.

Sheet1:

如何在Excel中找到给定经纬度的前三个最近位置?

Sheet2:

如何在Excel中找到给定经纬度的前三个最近位置?

Notice I've added just a test column with Alpacca and a rank column just to check my output but you don't need them.

Array formula (you must introduce it pressing <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>ENTER</kbd>:

=INDEX(Sheet2!$A$2:$A$6,SUMPRODUCT(--(SMALL (SQRT (($B2-Sheet2!$B$2:$B$6)^2+($C2-Sheet2!$C$2:$C$6)^2), RIGHT (D$1,1))= SQRT (($B2-Sheet2!$B$2:$B$6)^2+($C2-Sheet2!$C$2:$C$6)^2))*ROW(Sheet2!$A$2:$A$6))-1)

If, by any chance, 2 or more locations are exactly at the same distance, the formula won't work and will return wrong output.

huangapple
  • 本文由 发表于 2023年2月16日 14:38:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定