0% found this document useful (0 votes)
74 views

Find The Nearest Set of Coordinates in Excel - Stack Overflow

This document discusses finding the nearest set of coordinates between two tables in Excel. It provides two formulas to match the coordinates in table A to the nearest coordinates in table B. The first formula treats longitude and latitude as x and y values, while the second formula is more accurate as it uses the Haversine formula to calculate spherical distances on Earth's surface. The second formula is recommended for coordinate matching on a globe.

Uploaded by

Syed Fahad Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Find The Nearest Set of Coordinates in Excel - Stack Overflow

This document discusses finding the nearest set of coordinates between two tables in Excel. It provides two formulas to match the coordinates in table A to the nearest coordinates in table B. The first formula treats longitude and latitude as x and y values, while the second formula is more accurate as it uses the Haversine formula to calculate spherical distances on Earth's surface. The second formula is recommended for coordinate matching on a globe.

Uploaded by

Syed Fahad Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

 

Find the nearest set of coordinates in Excel


Asked
7 years, 1 month ago Modified
5 months ago Viewed
34k times

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?
3
excel excel-formula coordinates worksheet-function

Share Follow edited Oct 6, 2021 at 3:29 asked Feb 7, 2015 at 15:42
3
ZygD Bergen88
9,378 35 59 78 157 2 4 14

2 Answers Active Oldest Votes

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

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

Share Follow edited Feb 7, 2015 at 19:12 answered Feb 7, 2015 at 17:40
Join Stack Overflow to learn, share knowledge, and build your career. lori_m Sign up
5,327 1 16 26
The first formula was accurate. I compared the results by mapping and spatial-joining the data. the 1st
formula results were 100% match with the mapped results.
–  Bergen88
Feb 7, 2015 at 19:36

2 The first formula is only accurate if you treat longitude and latitude as a unit x and unit y change. For
locations on the surface of the earth this will only be a reasonable approximation near the tropics. The
second formula is based on a standard formula for spherical distances:
en.wikipedia.org/wiki/Haversine_formula
– lori_m
Feb 7, 2015 at 21:54

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

2 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:

Join Stack Assuming original


Overflow to learn, data
sharestarts in A1, and
knowledge, B1 and C1your
build withcareer.
first locations in E1
and F1
Sign up
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)

Share Follow edited Feb 9, 2017 at 21:23 answered Feb 7, 2015 at 17:02
ZygD
9,378 35 59 78

Join Stack Overflow to learn, share knowledge, and build your career. Sign up

You might also like