def toUtmUps8(latlon, lon=None, datum=None, falsed=True, Utm=Utm, Ups=Ups, pole=NN, name=NN, **cmoff): '''Convert a lat-/longitude point to a UTM or UPS coordinate. @arg latlon: Latitude (C{degrees}) or an (ellipsoidal) geodetic C{LatLon} point. @kwarg lon: Optional longitude (C{degrees}) or C{None}. @kwarg datum: Optional datum to use this UTM coordinate, overriding B{C{latlon}}'s datum (C{Datum}). @kwarg falsed: False both easting and northing (C{bool}). @kwarg Utm: Optional class to return the UTM coordinate (L{Utm}) or C{None}. @kwarg Ups: Optional class to return the UPS coordinate (L{Ups}) or C{None}. @kwarg pole: Optional top/center of UPS (stereographic) projection (C{str}, C{'N[orth]'} or C{'S[outh]'}). @kwarg name: Optional name (C{str}). @kwarg cmoff: DEPRECATED, use B{C{falsed}}. Offset longitude from zone's central meridian, for UTM only (C{bool}). @return: The UTM or UPS coordinate (B{C{Utm}} respectively B{C{Ups}}) or a L{UtmUps8Tuple}C{(zone, hemipole, easting, northing, band, datum, convergence, scale)} if B{C{Utm}} respectively B{C{Ups}} is C{None} or B{C{cmoff}} is C{False}. @raise RangeError: If B{C{lat}} outside the valid UTM or UPS bands or if B{C{lat}} or B{C{lon}} outside the valid range and L{rangerrors} set to C{True}. @raise TypeError: If B{C{latlon}} is not ellipsoidal or B{C{lon}} value is missing of B{C{datum}} is invalid. @raise UTMUPSError: UTM or UPS validation failed. @raise ValueError: Invalid B{C{lat}} or B{C{lon}}. @see: Functions L{toUtm8} and L{toUps8}. ''' lat, lon, d, name = _to4lldn(latlon, lon, datum, name) z, B, p, lat, lon = utmupsZoneBand5(lat, lon) f = falsed and _xkwds_get(cmoff, cmoff=True) if z == _UPS_ZONE: u = toUps8(lat, lon, datum=d, falsed=f, Ups=Ups, pole=pole or p, name=name) else: u = toUtm8(lat, lon, datum=d, falsed=f, Utm=Utm, name=name) return u
def geoidHeight2(lat, lon, model=0, timeout=2.0): '''Get the C{NAVD88} geoid height at an C{NAD83} location. @arg lat: Latitude (C{degrees}). @arg lon: Longitude (C{degrees}). @kwarg model: Optional, geoid model ID (C{int}). @kwarg timeout: Optional, query timeout (seconds). @return: An L{GeoidHeight2Tuple}C{(height, model_name)} or C{(None, "error"}) in case of errors. @raise ValueError: Invalid B{C{timeout}}. @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=Lat(lat).toStr(prec=6), lon=Lon(lon).toStr(prec=6), model=(model if model else NN), timeout=Scalar(timeout=timeout)) # PYCHOK indent if j[:1] == '{' and j[-1:] == '}' and j.find('"error":') > 0: d, e = _json(j), 'geoidHeight' if isinstance(_xkwds_get(d, error=_n_a_), float): h = d.get(e, None) if h is not None: m = _xkwds_get(d, geoidModel=_n_a_) return GeoidHeight2Tuple(h, m) else: e = _JSON_ e = _no_(e, Fmt.QUOTE2(clips(j, limit=256, white=_SPACE_))) except (HTTPError, IOError, ParseError, TypeError, ValueError) as x: e = repr(x) e = _error(geoidHeight2, lat, lon, e) return GeoidHeight2Tuple(None, e)
def splice(iterable, n=2, **fill): '''Split an iterable into C{n} slices. @arg iterable: Items to be spliced (C{list}, C{tuple}, ...). @kwarg n: Number of slices to generate (C{int}). @kwarg fill: Optional fill value for missing items. @return: A generator for each of B{C{n}} slices, M{iterable[i::n] for i=0..n}. @raise ValueError: Invalid B{C{n}}. @note: Each generated slice is a C{tuple} or a C{list}, the latter only if the B{C{iterable}} is a C{list}. @example: >>> from pygeodesy import splice >>> a, b = splice(range(10)) >>> a, b ((0, 2, 4, 6, 8), (1, 3, 5, 7, 9)) >>> a, b, c = splice(range(10), n=3) >>> a, b, c ((0, 3, 6, 9), (1, 4, 7), (2, 5, 8)) >>> a, b, c = splice(range(10), n=3, fill=-1) >>> a, b, c ((0, 3, 6, 9), (1, 4, 7, -1), (2, 5, 8, -1)) >>> tuple(splice(list(range(9)), n=5)) ([0, 5], [1, 6], [2, 7], [3, 8], [4]) >>> splice(range(9), n=1) <generator object splice at 0x0...> ''' if not (isint(n) and n > 0): raise _ValueError(n=n) t = iterable if not isinstance(t, (list, tuple)): t = tuple(t) # force tuple, also for PyPy3 if n > 1: fill = _xkwds_get(fill, fill=_Missing) if fill is not _Missing: m = len(t) % n if m > 0: # fill with same type t += type(t)((fill, )) * (n - m) for i in range(n): yield t[i::n] # slice [i:None:n] pychok -Tb ... else: yield t
def nearestOn2(point, points, **closed_radius_LatLon_options): # PYCHOK no cover '''DEPRECATED, use function L{sphericalTrigonometry.nearestOn3}. @return: ... 2-tuple C{(closest, distance)} of the C{closest} point (L{LatLon}) on the polygon and the C{distance} between the C{closest} and the given B{C{point}}. The C{closest} is a B{C{LatLon}} or a L{LatLon2Tuple}C{(lat, lon)} if B{C{LatLon}} is C{None} ... ''' ll, d, _ = nearestOn3(point, points, **closed_radius_LatLon_options) if _xkwds_get(closed_radius_LatLon_options, LatLon=LatLon) is None: ll = LatLon2Tuple(ll.lat, ll.lon) return ll, d
def _to7zBlldfn(latlon, lon, datum, falsed, name, zone, Error, **cmoff): '''(INTERNAL) Determine 7-tuple (zone, band, lat, lon, datum, falsed, name) for L{toEtm8} and L{toUtm8}. ''' f = falsed and _xkwds_get(cmoff, cmoff=True) # DEPRECATED lat, lon, d, name = _to4lldn(latlon, lon, datum, name) z, B, lat, lon = _to3zBll(lat, lon, cmoff=f) if zone: # re-zone for ETM/UTM r, _, _ = _to3zBhp(zone, B) if r != z: if not _UTM_ZONE_MIN <= r <= _UTM_ZONE_MAX: raise Error(zone=zone) if f: # re-offset from central meridian lon += _cmlon(z) - _cmlon(r) z = r return z, B, lat, lon, d, f, name