View Single Post

  #1 (permalink)  
Old 08-31-2006
Loggy Loggy is offline
Junior Member
White Belt
 
Join Date: Aug 2006
Posts: 3
CalcPos in python

It's fairly trivial, but I do not believe that CalcPos in python is posted anywhere.


Code:
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
Reply With Quote