Coverage for pygeodesy/wgrs.py : 96%

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 -*-
decode and inspect I{World Geographic Reference System (WGRS)} references.
Transcribed from I{Charles Karney}'s C++ class U{Georef <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1Georef.html>}, but with modified C{precision} and extended with C{height} and C{radius}. See also U{World Geographic Reference System <https://WikiPedia.org/wiki/World_Geographic_Reference_System>}. '''
_item_sq, _Missing, _radius_, \ _0_5, _1_0, _2_0, _60_0, _90_0 Radius, Scalar_, Str, _xStrError
'''(INTERNAL) Convert B{C{x}} to 3_tuple C{(tile, modulo, fraction)}/ '''
'''(INTERNAL) Convert lat, lon, height. ''' # lat, lon = parseDMS2(lat, lon) Lon(lon, Error=WGRSError), height)
'''(INTERNAL) Check a georef string. ''' or geostr[:3] == 'INV' \ or not geostr.isalnum(): raise ValueError
except (AttributeError, TypeError, ValueError) as x: raise WGRSError(Georef.__name__, georef, txt=str(x))
'''(INTERNAL) Return a L{Precision_} instance. '''
'''World Geographic Reference System (WGRS) encode, decode or other L{Georef} issue. '''
'''Georef class, a named C{str}. '''
# no str.__init__ in Python 3 '''New L{Georef} from an other L{Georef} instance or georef C{str} or from a C{LatLon} instance or lat-/longitude C{str}.
@arg cll: Cell or location (L{Georef} or C{str}, C{LatLon} or C{str}). @kwarg precision: Optional, the desired georef resolution and length (C{int} 0..11), see function L{wgrs.encode} for more details. @kwarg name: Optional name (C{str}).
@return: New L{Georef}.
@raise RangeError: Invalid B{C{cll}} lat- or longitude.
@raise TypeError: Invalid B{C{cll}}.
@raise WGRSError: INValid or non-alphanumeric B{C{cll}}. '''
self._name = cll._name
else:
else: # assume LatLon except AttributeError: raise _xStrError(Georef, cll=cll) # Error=WGRSError
self.name = name
# cache all decoded attrs
'''Get this georef's height in C{meter} or C{None} if missing. '''
'''Get this georef's (center) lat- and longitude (L{LatLon2Tuple}). ''' self._decode()
'''Get this georef's precision (C{int}). ''' self._decode()
'''Get this georef's radius in C{meter} or C{None} if missing. '''
'''Return (the center of) this georef cell as an instance of the supplied C{LatLon} class.
@kwarg LatLon: Class to use (C{LatLon}) or C{None}. @kwarg height: Optional height ({meter}). @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments, ignored if C{B{LatLon}=None}.
@return: This georef location (B{C{LatLon}}) or if B{C{LatLon}} is C{None}, a L{LatLon3Tuple}C{(lat, lon, height)}.
@raise TypeError: Invalid B{C{LatLon}} or B{C{LatLon_kwds}}. ''' LatLon(*self.latlon, height=h, **LatLon_kwds)
'''Decode a C{georef} to lat-, longitude and precision.
@arg georef: To be decoded (L{Georef} or C{str}). @kwarg center: If C{True} the center, otherwise the south-west, lower-left corner (C{bool}).
@return: A L{LatLonPrec3Tuple}C{(lat, lon, precision)}.
@raise WGRSError: Invalid B{C{georef}}, INValid, non-alphanumeric or odd length B{C{georef}}. ''' raise _Error(i)
return WGRSError(_item_sq(georef=i), georef)
raise _Error(i)
Lon(lon * u, Error=WGRSError), precision)
'''Decode a C{georef} to lat-, longitude, precision, height and radius.
@arg georef: To be decoded (L{Georef} or C{str}). @kwarg center: If C{True} the center, otherwise the south-west, lower-left corner (C{bool}).
@return: A L{LatLonPrec5Tuple}C{(lat, lon, precision, height, radius)} where C{height} and/or C{radius} are C{None} if missing.
@raise WGRSError: Invalid B{C{georef}}, INValid, non-alphanumeric or odd length B{C{georef}}. '''
else:
'''Encode a lat-/longitude as a C{georef} of the given precision.
@arg lat: Latitude (C{degrees}). @arg lon: Longitude (C{degrees}). @kwarg precision: Optional, the desired C{georef} resolution and length (C{int} 0..11). @kwarg height: Optional, height in C{meter}, see U{Designation of area <https://WikiPedia.org/wiki/World_Geographic_Reference_System>}. @kwarg radius: Optional, radius in C{meter}, see U{Designation of area <https://WikiPedia.org/wiki/World_Geographic_Reference_System>}.
@return: The C{georef} (C{str}).
@raise RangeError: Invalid B{C{lat}} or B{C{lon}}.
@raise WGRSError: Invalid B{C{precision}}, B{C{height}} or B{C{radius}}.
@note: The B{C{precision}} value differs from U{Georef<https:// GeographicLib.SourceForge.io/html/classGeographicLib_1_1Georef.html>}. The C{georef} length is M{2 * (precision + 1)} and the C{georef} resolution is I{15°} for B{C{precision}} 0, I{1°} for 1, I{1′} for 2, I{0.1′} for 3, I{0.01′} for 4, ... M{10**(2 - precision)}. '''
lat *= EPS1_2
'''Determine the L{Georef} precision to meet a required (geographic) resolution.
@arg res: The required resolution (C{degrees}).
@return: The L{Georef} precision (C{int} 0..11).
@raise ValueError: Invalid B{C{res}}.
@see: Function L{wgrs.encode} for more C{precision} details. '''
'''Determine the (geographic) resolution of a given L{Georef} precision.
@arg prec: The given precision (C{int}).
@return: The (geographic) resolution (C{degrees}).
@raise ValueError: Invalid B{C{prec}}.
@see: Function L{wgrs.encode} for more C{precision} details. ''' else:
encode, precision, resolution)
# **) 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. |