 Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.   ## CalcPos in python

This is a discussion on CalcPos in python within the MapPoint Desktop Discussion forums, part of the Map Forums category; It's fairly trivial, but I do not believe that CalcPos in python is posted anywhere. Code: import math # Calculates ...

1. 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)

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

2. Cool! good work, thanks, Eric  Reply With Quote

There are currently 1 users browsing this thread. (0 members and 1 guests)

calcpos, python 