Coordinate and distance calculate formula

  • Upload
    anh00

  • View
    234

  • Download
    0

Embed Size (px)

Citation preview

  • 8/12/2019 Coordinate and distance calculate formula

    1/6

    Latitude, Longitude,

    And Great Circles

    This page describes how to work with Latitude and Longitude in Excel and how to computeGreat Circle Distances.

    Introduction

    ou can use Excel!s trigonometric and time "unctions to work with Latitude and Longitude

    #alues. There are two di""erent wa$s express geographical coordinates. The "irst is to use a time"ormat o" degrees%minutes%seconds. This is the same "ormat as an Excel time #alue. The other

    method is to use decimal degrees, representing #alues as the number o" degrees as a real number.

    &or example, the location '( degrees, )( minutes, *( seconds can be represented as the time'(%)(%*( or in decimal degrees as '(.+.

    ou candownload the "ilewith all the example "ormulas and code on this page.

    -emispheres And ositi#e And /egati#e Coordinates

    I" $ou are restricting $oursel" to one hemisphere "or latitude and one hemisphere "or longitude,

    $ou can use either time "ormat or decimal degrees "ormat and use posti#e #alues "or both. I" $ou

    are working with two hemispheres, $ou must choose one hemisphere to be positi#e and then usenegati#e #alues "or locations in the other hemisphere. This is "ine "or decimal degree #alues, but

    Excel can!t displa$ negati#e time #alues. There"ore, i" $ou are working in two hemispheres, $ouneed to use the decimal degrees "ormat or set the date s$stem to the 0(* base. To change the

    date "ormat, go to the Toolsmenu, choose Optionsand then the Calculationtab. There, check the

    1904 date systemsetting. 1hen using positi#e and negati#e #alues to speci"$ the hemisphere, itdoesn!t matter which hemisphere is assigned to positi#e numbers and which is assigned to

    negati#e numbers. -owe#er, $ou must be consistent in all $our calculations. I" /orth is positi#e

    in one set o" coordinates, it must be positi#e in all coordinates.

    /umber &ormatting &or Latitude And Longitude

    I" $ou are using the time "ormat "or latitude and longitude #alues, $ou will need to change the

    number "ormat "or those cells. 2$ de"ault, when $ou enter a time in a cell, Excel will use the

    Short Time"ormat as speci"ied in the 1indows 3egional 4ettings. Excel will 5roll6o#er5 times at

    '* hours 7although the underl$ing #alue remains correct8. &or example, the time #alue )(%*(%+(

    http://www.cpearson.com/Zips/LatLong.ziphttp://www.cpearson.com/Zips/LatLong.ziphttp://www.cpearson.com/Zips/LatLong.zip
  • 8/12/2019 Coordinate and distance calculate formula

    2/6

    is displa$ed as (9%*(%+(. To correct this, $ou can use a number "ormat o" :hh;%mm%ss. The s

  • 8/12/2019 Coordinate and distance calculate formula

    3/6

    In addition to the "ormulas abo#e, $ou can use an arra$ "ormula to split out the degree, minute,

    and second #alues "rom either a time6"ormat #alue or a decimal degree #alue. To split out the

    component "rom a time6"ormat #alue, select the three cells that will get the component #aluesand enter the "ollowing arra$ "ormula%

    B,(,(JI/T7A'*8K(,,(JFI/TE7A8K(,(,J4ECH/D7A8

    and press CT3L 4-I&T E/TE3. &or more in"ormation about arra$ "ormulas, see the arra$

    "ormulas pageon this web site. In the "ormula abo#e, note the di""erences between theparentheses and the curl$ braces J.

    To break out the degrees, minutes, and seconds #alues "rom a decimal degrees #alue, use the

    "ollowing arra$ "ormula. 4elect the cells that will get the component #alues, t$pe the "ormula,

    and press CT3L 4-I&T E/TE3.

    B,(,(JI/T7A8K(,,(JFI/TE7A'*8K(,(,J4ECH/D7A'*8

    As be"ore, note the di""erence between the parentheses and the curl$ braces.

    Great Circle Distances

    In Fathematics and Cartograph$, a Great Circle Distanceis the shortest path between two

    points on the sur"ace o" a sphere 7and we will assume that the Earth is a per"ect sphere, e#en

    though it reall$ isn!t8. This is the 5as the crow "iles5 distance between the two points. All lines o"Longitude are Great Circles, while the E

  • 8/12/2019 Coordinate and distance calculate formula

    4/6

    To calculate the Great Circle Distance between Location and Location', use the "ormula%

    B3adiusEarth77'A4I/743T774I/773ADIA/47D*0'*863ADIA/47D+('*88'8M'8KCH473ADIA/47D*0'*88CH473ADIA/47D+('*88

    74I/773ADIA/47E*0'*863ADIA/47E+('*88'8M'88888

    In this example, the 3adiusEarth is a named cell with the #alue 9)?(.0?)'?9''?) "or nautical

    kilometers or )0+.?)0'9+ "or nautical miles. Fultipl$ either #alue b$ .+(??0**( to get

    the length in statute kilometers or statute miles. Cells D*0 and E*0 are the latitude and longitudeo" Location and cells D+( and E+( are the latitude and longitude o" Location '. These

    coordinates are in Time "ormat. The result is the distance in either miles or kilometers,

    depending on the #alue in the cell named 3adiusEarth. &or readabilit$, the "ormula is broken into

    se#eral lines. In Excel, o" course, the "ormula is in a single line in a single cell.

    The same "ormula, using de"ined names "or coordinates is shown below. LatN and LongN are

    the coordinates o" the "irst location. Lat'N and Long'N are the coordinates o" the second location.

    B3adiusEarth77'A4I/743T774I/773ADIA/47LatN'*86

    3ADIA/47Lat'N'*88'8M'8KCH473ADIA/47LatN'*88CH473ADIA/47Lat'N'*88

    74I/773ADIA/47LongN'*863ADIA/47Long'N'*88'8M'88888

    Great Circle Distances 1ith Decimal Degrees Coordinates

    To calculate the Great Circle Distance between Location and Location ', where the coordinatesare in decimal degree "ormat, use the "ollowing "ormula%

    B3adiusEarth77'A4I/743T774I/773ADIA/47D?863ADIA/47D?'88'8M'8K

    CH473ADIA/47D?88CH473ADIA/47D?'8874I/773ADIA/47E?863ADIA/47E?'88'8M'88888

    -ere, cells D? and E? contain the latitude and longitude o" Location and cells D?' and E?'

    contain the latitude and longitude o" Location '. &or readabilit$, the "ormula is split o#er se#eral

    lines. In Excel, o" course, the "ormula is in a single line in a single cell.

    The same "ormula, using de"ined names "or the coordinates is shown below. LatNN andLongNN are the coordinates o" the start location and Lat'NN and Long'NN are the coordinates o"

    the end location.

    B3adiusEarth77'A4I/743T774I/773ADIA/47LatNN863ADIA/47Lat'NN88'8M'8KCH473ADIA/47LatNN88CH473ADIA/47Lat'NN88 74I/773ADIA/47LongNN86

    3ADIA/47Long'NN88'8M'88888

    Great Circle Distances In O2A

    The "ollowing O2A code will calculate a Great Circle Distance in either Pilometers or Files 7asspeci"ied in the 3esultAsFiles parameter 66 True indicates Files, &alse indicates Pilometers8.

  • 8/12/2019 Coordinate and distance calculate formula

    5/6

    The inputs ma$ be either decimal degrees or time6"ormat #alues. 74et the

    OaluesAsDecimalDegrees parameter to True "or decimal degrees, &alse "or Time degrees.8

    Private Const C_RADIUS_EARTH_KM As Double = 637!"73#7$6#Private Const C_RADIUS_EARTH_MI As Double = 3"%$!73"#6&$%Private Const C_PI As Double = 3!&'&%"#6%3%$"7"

    (un)tion *reatCir)leDistan)e+,atitu-e& As Double. ,on/itu-e& As Double. _ ,atitu-e# As Double. ,on/itu-e# As Double. _ 0aluesAsDe)i1alDe/rees As 2oolean. _ ResultAsMiles As 2oolean As Double

    Di1 ,at& As DoubleDi1 ,at# As DoubleDi1 ,on/& As DoubleDi1 ,on/# As DoubleDi1 4 As ,on/Di1 Delta As Double

    I5 0aluesAsDe)i1alDe/rees = True Ten 4 = &Else 4 = #'En- I5

    )onvert to -e)i1al -e/rees,at& = ,atitu-e& 8 4,on/& = ,on/itu-e& 8 4,at# = ,atitu-e# 8 4,on/# = ,on/itu-e# 8 4

    )onvert to ra-ians9 ra-ians = +-e/rees:&$ 8 PI,at& = +,at& : &$ 8 C_PI

    ,at# = +,at# : &$ 8 C_PI,on/& = +,on/& : &$ 8 C_PI,on/# = +,on/# : &$ 8 C_PI

    /et te )entral s;eri)al an/leDelta = ++# 8 Ar)Sin+S # ? _ Cos+,at& 8 Cos+,at# 8 +Sin++,on/& ,on/# : # > #I5 ResultAsMiles = True Ten *reatCir)leDistan)e = Delta 8 C_RADIUS_EARTH_MIElse *reatCir)leDistan)e = Delta 8 C_RADIUS_EARTH_KMEn- I5

    En- (un)tion

    (un)tion Ar)Sin+4 As Double As Double 02A -oesnt ave an Ar)Sin 5un)tion! I1;rovise! Ar)Sin = Atn+4 : S

  • 8/12/2019 Coordinate and distance calculate formula

    6/6

    ou can calculate the initial and terminal bearing o" a great circle with "ormulas. The initial

    bearing is the bearing at which one would lea#e the starting point to tra#el on a Great Circle

    route to the end point. The initial bearing is gi#en b$ the "ormula%

    BDEG3EE47IFA3GFE/T7CHFLEQ7/orth6/orth',East6East'88KI788

    The terminal bearing, the bearing one will be tra#elling upon arri#al at the end point, is gi#e b$

    the "ormula%

    BDEG3EE47IFA3GFE/T7CHFLEQ7/orth'6/orth,East'6East88KI788.

    2earings are measured clockwise "rom /orth, with /orth as ( degrees, East at 0( degrees, 4outh

    at ( degrees, and 1est at '?( degrees.