Loggy
08-31-2006, 07:54 PM
It's fairly trivial, but I do not believe that CalcPos in python is posted anywhere.
import math
# Calculates lat/long of a mappoint location object
# This function was originally written in VB by
# Gilles Kohl (gilles@compuserve.com)
# original: http://www.mp2kmag.com/articles.asp?ArticleID=13
def CalcPos(objMap, locX):
locNorthPole = objMap.GetLocation(90, 0)
locSantaCruz = objMap.GetLocation(0, -90)
dblHalfEarth = objMap.Distance(locNorthPole, objMap.GetLocation(-90, 0))
dblQuarterEarth = dblHalfEarth / 2
# Compute latitude from distance to north pole
dblLat = 90 - 180 * objMap.Distance(locNorthPole, locX) / dblHalfEarth
# Compute great circle distance to locX from point
# on Greenwich meridian and computed Latitude
d = objMap.Distance(objMap.GetLocation(dblLat, 0), locX)
# convert latitude to radian
l = (dblLat / 180) * math.pi
# Compute Longitude from great circle distance
dblLon = 180 * math.acos((math.cos((d * 2 * math.pi)/(2 * dblHalfEarth)) -
math.sin(l) * math.sin(l))/(math.cos(l) * math.cos(l))) / math.pi
# Correct longitude sign if located in western hemisphere
if objMap.Distance(locSantaCruz, locX) < dblQuarterEarth:
dblLon = -1 * dblLon
return (dblLat, dblLon)
# END function
import math
# Calculates lat/long of a mappoint location object
# This function was originally written in VB by
# Gilles Kohl (gilles@compuserve.com)
# original: http://www.mp2kmag.com/articles.asp?ArticleID=13
def CalcPos(objMap, locX):
locNorthPole = objMap.GetLocation(90, 0)
locSantaCruz = objMap.GetLocation(0, -90)
dblHalfEarth = objMap.Distance(locNorthPole, objMap.GetLocation(-90, 0))
dblQuarterEarth = dblHalfEarth / 2
# Compute latitude from distance to north pole
dblLat = 90 - 180 * objMap.Distance(locNorthPole, locX) / dblHalfEarth
# Compute great circle distance to locX from point
# on Greenwich meridian and computed Latitude
d = objMap.Distance(objMap.GetLocation(dblLat, 0), locX)
# convert latitude to radian
l = (dblLat / 180) * math.pi
# Compute Longitude from great circle distance
dblLon = 180 * math.acos((math.cos((d * 2 * math.pi)/(2 * dblHalfEarth)) -
math.sin(l) * math.sin(l))/(math.cos(l) * math.cos(l))) / math.pi
# Correct longitude sign if located in western hemisphere
if objMap.Distance(locSantaCruz, locX) < dblQuarterEarth:
dblLon = -1 * dblLon
return (dblLat, dblLon)
# END function