Calculate Geometry - Degrees Minutes (DDD MM.mmm' [N│S])

2189
7
12-01-2017 02:10 PM
JaredDoke1
New Contributor II

In ArcMap, you could use Calculate Geometry to easily calculate the lat and long of points in an already existing field using one of several different formats that you specify. In ArcGIS Pro, that feature has been removed. Is there a way to easily calculate the latitude and longitude of points in an already existing field in Degrees Minutes (DDD MM.mmm' [N│S]? 

7 Replies
DanPatterson_Retired
MVP Emeritus

some funcs here https://stackoverflow.com/questions/2579535/how-to-convert-dd-to-dms-in-python

You could put something together perhaps along the lines of...

def dd_dmm(dd):
    """decimal degrees to deg dec min"""
    deg = int(dd)
    minsec = divmod((deg - dd)*60, 60)[-1]
    frmt = "{} {:0.2f}".format(deg, minsec)
    return deg, minsec, frmt

# ---- remove what you don't want from the 'return' statement

a = -75.55

dd_dmm(a)

(-75, 32.99999999999983, '-75 33.00')
DanPatterson_Retired
MVP Emeritus

Or this...

def dd_dmm(dd, cal_long=True):
    """decimal degrees to deg dec min"""
    deg = int(dd)
    if deg < 0:
        quad = ['S', 'W'][cal_long]
        deg = abs(deg)
    else:
        quad = ['N', 'E'][cal_long]
    minsec = divmod((deg - dd)*60, 60)[-1]
    frmt = "{} {:0.2f} {}".format(deg, minsec, quad)
    return frmt

dd_dmm(-45.5, True)  # '45 30.00 W'
dd_dmm(45.5, True)   # '45 30.00 E'
dd_dmm(-45.5, False) # '45 30.00 S'
dd_dmm(45.5, False)  # '45 30.00 N'‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Or with degree symbol

def dd_dmm(dd, cal_long=True):
    """decimal degrees to deg dec min"""
    deg_sign = u'\N{DEGREE SIGN}'
    deg = int(dd)
    if deg < 0:
        quad = ['S', 'W'][cal_long]
        deg = abs(deg)
    else:
        quad = ['N', 'E'][cal_long]
    minsec = divmod((deg - dd)*60, 60)[-1]
    frmt = "{}{} {:0.2f}' {}".format(deg, deg_sign, minsec, quad)
    return frmt

#  "45° 30.00' W"
JaredDoke1
New Contributor II

Thank you Dan! This is exactly what I was looking for. I modified the third example a little to be dd_dmm(!shape.centroid.x!, cal_long=True) so that I didn't have to calculate the decimal degrees in the first place. Thanks.

0 Kudos
DanPatterson_Retired
MVP Emeritus

cal_long is whether you want to calculate longitude if True and if False it uses latitude ... ie the E/W and N/S designation.  The incarnations assume that you wanted Longitude and Latitude in separate fields, but... modify away to suit

KoryKramer
Esri Community Moderator

Jared, you might also want to jump over to the ideas site to up vote and comment on https://community.esri.com/ideas/10695‌  Notice that it's status in In Product Plan.

Cheers

DanPatterson_Retired
MVP Emeritus

barely keeping ahead of you guys Kory...

KoryKramer
Esri Community Moderator

Haha.  Thanks for all the help you provide to the community, Dan!

Hopefully we'll see this one built in to Pro next year.

0 Kudos