def elevation2(lat, lon, timeout=2.0): '''Get the geoid elevation at an C{NAD83} to C{NAVD88} location. @param lat: Latitude (C{degrees}). @param lon: Longitude (C{degrees}). @keyword timeout: Optional, query timeout (seconds). @return: An L{Elevation2Tuple}C{(elevation, data_source)} or (C{None, "error"}) in case of errors. @note: The returned C{elevation} is C{None} if B{C{lat}} or B{C{lon}} is invalid or outside the C{Conterminous US (CONUS)}, if conversion failed or if the query timed out. The C{error} is the C{HTTP-, IO-, SSL-, Type-, URL-} or C{ValueError} as a string (C{str}). @see: U{USGS National Map<https://NationalMap.gov/epqs>}, the U{FAQ<https://www.USGS.gov/faqs/what-are-projection- horizontal-and-vertical-datum-units-and-resolution-3dep-standard-dems>}, U{geoid.py<https://Gist.GitHub.com/pyRobShrk>}, module L{geoids}, classes L{GeoidG2012B}, L{GeoidKarney} and L{GeoidPGM}. ''' try: x = _qURL( 'https://NED.USGS.gov/epqs/pqs.php', # https://NationalMap.gov/epqs/pqs.php ( 'x=%.6f' % (lon, ), 'y=%.6f' % (lat, ), 'units=Meters', # Feet 'output=xml'), timeout=float(timeout)) if x[:6] == '<?xml ': e = _xml('Elevation', x) try: e = float(e) if -1000000 < e < 1000000: return Elevation2Tuple(e, _xml('Data_Source', x)) e = 'non-CONUS %.2f' % (e, ) except ValueError: pass else: e = 'no XML "%s"' % (clipStr(x, limit=128, white=' '), ) except (HTTPError, IOError, TypeError, ValueError) as x: e = repr(x) return Elevation2Tuple(None, _error(elevation2, lat, lon, e))
def geoidHeight2(lat, lon, model=0, timeout=2.0): '''Get the C{NAVD88} geoid height at an C{NAD83} location. @param lat: Latitude (C{degrees}). @param lon: Longitude (C{degrees}). @keyword model: Optional, geoid model ID (C{int}). @keyword timeout: Optional, query timeout (seconds). @return: An L{GeoidHeight2Tuple}C{(height, model_name)} or C{(None, "error"}) in case of errors. @note: The returned C{height} is C{None} if B{C{lat}} or B{C{lon}} is invalid or outside the C{Conterminous US (CONUS)}, if the B{C{model}} was invalid, if conversion failed or if the query timed out. The C{error} is the C{HTTP-, IO-, SSL-, Type-, URL-} or C{ValueError} as a string (C{str}). @see: U{NOAA National Geodetic Survey <https://www.NGS.NOAA.gov/INFO/geodesy.shtml>}, U{Geoid<https://www.NGS.NOAA.gov/web_services/geoid.shtml>}, U{USGS10mElev.py<https://Gist.GitHub.com/pyRobShrk>}, module L{geoids}, classes L{GeoidG2012B}, L{GeoidKarney} and L{GeoidPGM}. ''' try: j = _qURL('https://Geodesy.NOAA.gov/api/geoid/ght', ('lat=%.6f' % (lat, ), 'lon=%.6f' % (lon, ), 'model=%s' % (model, ) if model else ''), timeout=float(timeout)) # PYCHOK 5 if j[:1] == '{' and j[-1:] == '}' and j.find('"error":') > 0: d = _json(j) if isinstance(d.get('error', 'N/A'), float): h = d.get('geoidHeight', None) if h is not None: m = _str(d.get('geoidModel', 'N/A')) return GeoidHeight2Tuple(h, m) e = 'geoidHeight' else: e = 'JSON' e = 'no %s "%s"' % (e, clipStr(j, limit=256, white=' ')) except (HTTPError, IOError, TypeError, ValueError) as x: e = repr(x) e = _error(geoidHeight2, lat, lon, e) return GeoidHeight2Tuple(None, e)