[thelist] ASP/GPS Question: converting from decimal degrees to degrees, minutes and seconds

Christian Anderson christian at photokyo.com
Thu Jan 22 21:52:44 CST 2004


Hi Everyone,

Its been a while since I’ve been on the list since I’ve switched jobs and
haven’t been online in a while.

I have a question about converting GPS decimal degrees to degrees, minutes,
seconds in ASP. For example, what I have right now is something like this:

lat=+42.84779
lon=+140.71558

I want to convert this to something like lat=+42.x.x.x and lon=+140.x.x.x

I have someone that is heavy into python and came up with the following, but
since I’m using asp I was wondering if anyone knew how to translate this
into asp? Or instead of translating, just making it work? ;)

Anyway here is the code, and I look forward to your replies. Thanks!

def degrees_to_dms_string(deg):

    # Separate out the sign.
    if deg < 0.0:
        sign = '-'
        deg = -deg
    else:
        sign = '+'

    # Convert to an integer to avoid inconsistent rounding later.
    # The least significant digit of the result corresponds to
    # centiseconds so multiply the number accordingly.  Note that
    # int rounds towards zero.
    csec = int(deg * 60.0 * 60.0 * 100.0 + 0.5)

    # Split up into the four components.  divmod calculates
    # quotient and remainder simultaneously.
    sec, csec = divmod(csec, 100)
    min, sec = divmod(sec, 60)
    deg, min = divmod(min, 60)

    # Convert the four components and sign into a string.  The
    # % operator on strings works like C's sprintf function.
    return '%s%d.%02d.%02d.%02d' % (sign, deg, min, sec, csec)


Christian Anderson
Niseko Hirafu, Hokkaido, Japan
http://www.photokyo.com
 




More information about the thelist mailing list