Coverage for pygeodesy/elevations.py : 92%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
for (lat, lon) locations, currently limited to the U{Conterminous US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}, see also module L{geoids}, module L{heights} classes and U{USGS10mElev.py <https://Gist.GitHub.com/pyRobShrk>}.
B{macOS}: If an C{SSLCertVerificationError} occurs, especially this I{"[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self "signed certificate in certificate chain ..."}, review U{this post <https://StackOverflow.com/questions/27835619/urllib-and-ssl-certificate -verify-failed-error>} for a remedy. From a Terminal window run: C{"/Applications/Python X.Y/Install Certificates.command"}
@newfield example: Example, Examples '''
# from urllib.parse import quote
except ImportError:
def _json(ngs): # PYCHOK no cover '''(INTERNAL) Convert an NGS response in JSON to a C{dict}. ''' # b'{"geoidModel": "GEOID12A", # "station": "UserStation", # "lat": 37.8816, # "latDms": "N375253.76000", # "lon": -121.9142, # "lonDms": "W1215451.12000", # "geoidHeight": -31.703, # "error": 0.064 # }' # # or in case of errors: # # b'{"error": "No suitable Geoid model found for model 15" # }' d = {} for t in ngs.strip().lstrip('{').rstrip('}').split(','): j = t.strip().strip('"').split('": ') if len(j) != 2: raise ValueError('json: %r' % (t,)) k, v = j try: v = float(v) except ValueError: v = v.lstrip().lstrip('"') d[k] = v return d
'''(INTERNAL) Format an error '''
'''(INTERNAL) Build B{C{url}} query, get and verify response. '''
raise IOError('code %d: %s' % (s, u.geturl()))
# urlcleanup()
'''Unicode or C{bytes} to C{str}. '''
'''(INTERNAL) Get a <tag>value</tag> from XML. ''' # b'<?xml version="1.0" encoding="utf-8" ?> # <USGS_Elevation_Point_Query_Service> # <Elevation_Query x="-121.914200" y="37.881600"> # <Data_Source>3DEP 1/3 arc-second</Data_Source> # <Elevation>3851.03</Elevation> # <Units>Feet</Units> # </Elevation_Query> # </USGS_Elevation_Point_Query_Service>' return 'no XML tag <%s>' % (tag,)
'''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}. ''' ('x=%.6f' % (lon,), 'y=%.6f' % (lat,), 'units=Meters', # Feet 'output=xml'), timeout=float(timeout)) except ValueError: pass else: e = 'no XML "%s"' % (clipStr(x, limit=128, white=' '),)
'''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}. ''' ('lat=%.6f' % (lat,), 'lon=%.6f' % (lon,), 'model=%s' % (model,) if model else ''), timeout=float(timeout)) # PYCHOK 5 e = 'geoidHeight' else:
if __name__ == '__main__':
# <https://WikiPedia.org/wiki/Mount_Diablo> for f in (elevation2, # (1173.79, '3DEP 1/3 arc-second') geoidHeight2): # (-31.703, 'GEOID12B') t = f(37.8816, -121.9142) print('%s: %s' % (f.__name__, t))
# **) MIT License # # Copyright (C) 2016-2020 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE.
# % python -m pygeodesy.elevations # elevation2: (1173.79, '3DEP 1/3 arc-second') # geoidHeight2: (-31.703, 'GEOID12B') |