In [1]:
import requests

In [17]:
def vertcon(lon,lat):
    '''
    Call NGS VERTCON web service (https://www.ngs.noaa.gov/cgi-bin/VERTCON/vert_con.prl),
    returning the difference between the NAVD88 and NGVD29 vertical datums
    for a specified lon,lat value.   Enter longitude in degrees_east (e.g. -70.5).
    Returned value is the datum shift(NAVD 88 minus NGVD 29) in meters 
    FORMULA: height (NAVD 88) = height (NGVD 29) + datum_shift
    Note: NAVD88 datum is above NGVD29 datum on the East Coast. 
    NAVD88 datum is below NGVD29 datum on the West Coast.
    '''
    params={'LAT':'42.500','LON':'071.500','HGT':'','MODE':'G'}
    # Convert longitude in degrees_east (e.g. -71.5) to degrees_west for VERTCON
    # VERTCON needs *exactly* the right format for lon/lat, so force it to be correct 
    params['LON']='%07.3f' % -lon
    params['LAT']='%06.3f' % lat
    # VERTCON web service needs a browser header, so just use Mozilla
    headers = {'User-agent' : "Mozilla/5.0" }
    url='https://www.ngs.noaa.gov/cgi-bin/VERTCON/vert_con2.prl'
    r = requests.get(url, params=params, headers=headers)
    print r.url
    html = r.text
    ind = html.find('meter')
    datum_shift = float(html[ind-9:ind-1])
    return off

In [18]:
vertcon(-71.5,41.5)


https://www.ngs.noaa.gov/cgi-bin/VERTCON/vert_con2.prl?LAT=41.500&HGT=&LON=071.500&MODE=G
Out[18]:
-0.275

In [99]:
print off
type(off)


-0.243
Out[99]:
float

In [ ]: