Data C : Airport Data File : Great Circle Distance Calculator
<%
Dim regionID
'air regions dropdown
Dim jmSQL, rsAirDropR
'---create dsn-less conn-----
Dim DB, Dir, Path, f, airports
DB = "_data\airports.mdb"
Dir = Request.ServerVariables("SCRIPT_NAME")
Dir = StrReverse(Dir)
Dir = Mid(Dir, InStr(1, Dir, "/"))
Dir = StrReverse(Dir)
Path = Server.MapPath(Dir) & "\"
f = "airports.dsn"
airports = "filedsn=" & Path & f & ";DefaultDir=" & Path & _
";DBQ=" & Path & DB & ";"
'-----------------------------
jmSQL = "SELECT DISTINCT apTable.REGION FROM apTable;"
Set rsAirDropR = Server.CreateObject("ADODB.Recordset")
rsAirDropR.Open jmSQL, airports
If Not rsAirDropR.EOF Then
%>
Step One |
Departing From |
|
|
Regions |
Countries |
Cities |
|
<%
Else
regionID = CStr(Request.QueryString("REGION"))
%>
<%
End If
%>
<%
Dim countryID
regionID = CStr(Request.QueryString("REGION"))
'air regions dropdown
Dim countrySQL, rsAirDropC
countrySQL = "SELECT DISTINCT apTable.REGION, apTable.COUNTRY FROM apTable WHERE apTable.REGION = '" & regionID & "';"
Set rsAirDropC = Server.CreateObject("ADODB.Recordset")
rsAirDropC.Open countrySQL, airports
If Not rsAirDropC.EOF Then
%>
|
<%
End If
%>
<%
Dim cityID
cityID = CStr(Request.QueryString("city"))
countryID = CStr(Request.QueryString("country"))
regionID = CStr(Request.QueryString("REGION"))
'air regions dropdown
Dim citySQL, rsAirDropCN
citySQL = "SELECT DISTINCT apTable.CITY_NAME FROM apTable WHERE apTable.COUNTRY = '"
citySQL = citySQL & Replace(countryID,"'","''") & "';"
Set rsAirDropCN = Server.CreateObject("ADODB.Recordset")
rsAirDropCN.Open citySQL, airports
If Not rsAirDropCN.EOF Then
%>
|
<%
End If
%>
<%
Dim thisRegion, thisCountry, thisCity
thisRegion = CStr(Request.QueryString("region"))
thisCountry = CStr(Request.QueryString("country"))
thisCity = CStr(Request.QueryString("city"))
'air regions dropdown
Dim showcitySQL, rsShowCN
showcitySQL = "SELECT DISTINCT apTable.AIRP_NAME, apTable.LENGTH, apTable.ELEV, apTable.LOCATION FROM apTable WHERE apTable.CITY_NAME = '"
showcitySQL = showcitySQL & Replace(thisCity,"'","''") & "';"
Set rsShowCN = Server.CreateObject("ADODB.Recordset")
rsShowCN.Open showcitySQL, airports
If Not rsShowCN.EOF Then
'first variable for location data
Dim locOne,airportOne
locOne = rsShowCN("LOCATION")
airportOne = rsShowCN("AIRP_NAME")
%>
<%
Do While Not rsShowCN.EOF
%>
<%=airportOne%>
|
Length: <%=rsShowCN("LENGTH")%>(ft)
|
Elevation: <%=rsShowCN("ELEV")%>(ft)
|
Location: <%=locOne%>
|
<%
rsShowCN.MoveNext
loop
%>
<%
End If
%>
<%
'close airports one rs
rsShowCN.Close
Dim regionTwoID
'air regions dropdown
Dim jmSQLtwo, rsAirDropRtwo
jmSQLtwo = "SELECT DISTINCT apTable.REGION FROM apTable;"
Set rsAirDropRtwo = Server.CreateObject("ADODB.Recordset")
rsAirDropRtwo.Open jmSQLtwo, airports
If Not rsAirDropRtwo.EOF Then
%>
Step Two |
To Arrive In |
|
|
Regions |
Countries |
Cities |
|
<%
Else
regionTwoID = CStr(Request.QueryString("aregionTwo"))
%>
<%
End If
%>
<%
Dim countryIDtwo
regionTwoID = CStr(Request.QueryString("aregionTwo"))
'air regions dropdown
Dim countrySQLtwo, rsAirDropCtwo
countrySQLtwo = "SELECT DISTINCT apTable.REGION, apTable.COUNTRY FROM apTable WHERE apTable.REGION = '" & regionTwoID & "';"
Set rsAirDropCtwo = Server.CreateObject("ADODB.Recordset")
rsAirDropCtwo.Open countrySQLtwo, airports
If Not rsAirDropCtwo.EOF Then
%>
|
<%
End If
%>
<%
Dim cityIDtwo
cityIDtwo = CStr(Request.QueryString("cityTwo"))
countryIDtwo = CStr(Request.QueryString("countryTwo"))
regionTwoID = CStr(Request.QueryString("aregionTwo"))
'air regions dropdown
Dim citySQLtwo, rsAirDropCNtwo
citySQLtwo = "SELECT DISTINCT apTable.CITY_NAME FROM apTable WHERE apTable.COUNTRY = '"
citySQLtwo = citySQLtwo & Replace(countryIDtwo,"'","''") & "';"
Set rsAirDropCNtwo = Server.CreateObject("ADODB.Recordset")
rsAirDropCNtwo.Open citySQLtwo, airports
If Not rsAirDropCNtwo.EOF Then
%>
|
<%
End If
%>
<%
Dim thisRegionTwo, thisCountryTwo, thisCityTwo
thisRegionTwo = CStr(Request.QueryString("aregionTwo"))
thisCountryTwo = CStr(Request.QueryString("countryTwo"))
thisCityTwo = CStr(Request.QueryString("cityTwo"))
'air regions dropdown
Dim showcitySQLTwo, rsShowCNTwo
showcitySQLTwo = "SELECT DISTINCT apTable.AIRP_NAME, apTable.LENGTH, apTable.ELEV, apTable.LOCATION FROM apTable WHERE apTable.CITY_NAME = '"
showcitySQLTwo = showcitySQLTwo & Replace(thisCityTwo,"'","''") & "';"
Set rsShowCNTwo = Server.CreateObject("ADODB.Recordset")
rsShowCNTwo.Open showcitySQLTwo, airports
If Not rsShowCNTwo.EOF Then
'second variable for location data
Dim locTwo, airportTwo
locTwo = rsShowCNTwo("LOCATION")
airportTwo = rsShowCNTwo("AIRP_NAME")
%>
<%
Do While Not rsShowCNTwo.EOF
%>
<%=airportTwo%>
|
Length: <%=rsShowCNTwo("LENGTH")%>(ft)
|
Elevation: <%=rsShowCNTwo("ELEV")%>(ft)
|
Location: <%=locTwo%>
|
<%
rsShowCNTwo.MoveNext
loop
%>
<%
End If
%>
<%
if locTwo = "" Then
Response.Write("")
Else
'---------STEP ONE------------
'get latitute and longitude for both airports
Dim latOne, latmidOne, dirOne, equalsOne
Dim longOne, longmidOne, dirLgOne, equalsLgOne
Dim locOneLength, locTwoLength
'latitude for airport one
locOneLength = Len(locOne)
latOne = Left(locOne, 2)
latmidOne = Mid(locOne, 3, 2)
dirOne = Mid(locOne, 5, 1)
latmidOne = CInt(latmidOne)
latmidOne = latmidOne / 60
equalsOne = latOne + latmidOne
equalsOne = Round(equalsOne, 3)
'longitude for airport one
If locOneLength = 12 Then
longOne = Mid(locOne, 7,3)
longmidOne = Mid(locOne, 10, 2)
Else
longOne = Mid(locOne, 7,2)
longmidOne = Mid(locOne, 9, 2)
End If
dirLgOne = Right(locOne, 1)
longmidOne = CInt(longmidOne)
longmidOne = longmidOne / 60
equalsLgOne = longOne + longmidOne
Dim latTwo, latmidTwo, dirTwo, equalsTwo
Dim longTwo, longmidTwo, longLgTwo, dirLgTwo, equalsLgTwo
'latitude for airport Two
locTwoLength = Len(locTwo)
latTwo = Left(locTwo, 2)
latmidTwo = Mid(locTwo, 3, 2)
dirTwo = Mid(locTwo, 5, 1)
latmidTwo = CInt(latmidTwo)
latmidTwo = latmidTwo / 60
equalsTwo = latTwo + latmidTwo
equalsTwo = Round(equalsTwo, 3)
'longitude for airport Two
If locTwoLength = 12 Then
longTwo = Mid(locTwo, 7,3)
longmidTwo = Mid(locTwo, 10, 2)
Else
longTwo = Mid(locTwo, 7,2)
longmidTwo = Mid(locTwo, 9, 2)
End If
dirLgTwo = Right(locTwo, 1)
longmidTwo = CInt(longmidTwo)
longmidTwo = longmidTwo / 60
equalsLgTwo = longTwo + longmidTwo
'---------STEP TWO------------
'determine angle at earth center from North Pole for each airport
'south is positive
'airport one
Dim AOB, vAOB, AOC, vAOC
If dirOne = "N" Then
vAOB = "-" & CStr(equalsOne)
vAOB = CDbl(vAOB)
vAOB = Round(vAOB, 2)
Else
vAOB = equalsOne
vAOB = Round(vAOB, 2)
End If
AOB = 90 + vAOB
'airport two
If dirTwo = "N" Then
vAOC = "-" & CStr(equalsTwo)
vAOC = CDbl(vAOC)
vAOC = Round(vAOC, 2)
Else
vAOC = equalsOne
vAOC = Round(vAOC, 2)
End If
AOC = 90 + vAOC
'---------STEP THREE------------
'looking down polar axis determine angle between the two points
'east is positive
Dim BOCpolar, vequalsLgOne, vequalsLgTwo
If dirLgOne = "W" Then
'vequalsLgOne = "-" & CStr(equalsLgOne)
'vequalsLgOne = CDbl(vequalsLgOne)
vequalsLgOne = equalsLgOne
Else
vequalsLgOne = equalsLgOne
End If
If dirLgTwo = "W" Then
'vequalsLgTwo = "-" & CStr(equalsLgTwo)
'vequalsLgTwo = CDbl(vequalsLgTwo)
vequalsLgTwo = equalsLgTwo
Else
vequalsLgTwo = equalsLgTwo
End If
BOCpolar = (vequalsLgOne) + (vequalsLgTwo)
BOCpolar = Round(BOCpolar, 2)
'---------STEP FOUR------------
'true anlge between two points referenced to the centre (BOCtrue)
'must convert degrees to radians - degrees times pi/180
Dim cosAOB, cosAOC, cosBOCp, sinAOB
Dim sinAOC, cosBOCtrue, BOCtrue, greatCircleDist, greatCircleDistKM
Dim pi, toDegrees, toRadians, firstpart, secondpart
pi = 3.1415926535897932
toDegrees = 180 / pi
toRadians = pi / 180
AOB = AOB * toRadians
cosAOB = cos(AOB)
AOC = AOC * toRadians
cosAOC = cos(AOC)
BOCpolar = BOCpolar * toRadians
cosBOCp = cos(BOCpolar)
sinAOB = sin(AOB)
sinAOC = sin(AOC)
firstpart = cosAOB * cosAOC
secondpart = cosBOCp * sinAOB * sinAOC
cosBOCtrue = firstpart + secondpart
BOCtrue = Atn(-cosBOCtrue / Sqr(-cosBOCtrue * cosBOCtrue + 1)) + 2 * Atn(1)
BOCtrue = BOCtrue * toDegrees
BOCtrue = Round(BOCtrue, 2)
greatCircleDist = BOCtrue * 60
greatCircleDist = Int(greatCircleDist)
greatCircleDistKM = (greatCircleDist * 1.852)
greatCircleDistKM = CInt(greatCircleDistKM)
%>
Great Circle distance |
<%=airportOne%>
|
<%=locOne%>
|
Using 60nm per degree gives: |
<%=airportTwo%>
|
<%=locTwo%>
|
<%=greatCircleDist%>nm (<%=greatCircleDistKM%>km) |
<%
End If
%>
Please note location data takes the following format: 4853N = 48 deg 53 min North.
This data file contains information on the main airports around the
world, gathered from various public sources. The data is useful in identifying the runway
conditions (length and height) and estimating the geometrical distance between city pairs
on a particular route (eg. Los Angeles to Tokyo).
To use the online great circle distance, please select a Region, Country and City for Aiport One. Then choose a Region, Country and City for Airport Two. This will then calculate the Great Circle Distance between the selected Airports.
|