Coverage for pygeodesy/webmercator.py : 99%

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 -*-
Classes L{Wm} and L{WebMercatorError} and functions L{parseWM} and L{toWm}.
Pure Python implementation of a U{Web Mercator<https://WikiPedia.org/wiki/Web_Mercator>} (aka I{Pseudo-Mercator}) class and conversion functions for spherical and near-spherical earth models.
References U{Google Maps / Bing Maps Spherical Mercator Projection <https://AlastairA.WordPress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection>}, U{Geomatics Guidance Note 7, part 2<https://www.EPSG.org/Portals/0/373-07-02.pdf>} and U{Implementation Practice Web Mercator Map Projection <https://Earth-Info.NGA.mil/GandG/wgs84/web_mercator/%28U%29%20NGA_SIG_0011_1.0.0_WEBMERC.pdf>}. '''
_ValueError, _xkwds _easting_, _ellipsoidal_, _northing_, \ _radius_, _SPACE_ Radius, Radius_
# _FalseEasting = 0 # false Easting (C{meter}) # _FalseNorthing = 0 # false Northing (C{meter}) # _LonOrigin = 0 # longitude of natural origin (C{degrees})
'''3-Tuple C{(easting, northing, radius)}, all in C{meter}. '''
'''Web Mercator (WM) parser or L{Wm} issue. '''
'''Web Mercator (WM) coordinate. '''
'''New L{Wm} Web Mercator (WM) coordinate.
@arg x: Easting from central meridian (C{meter}). @arg y: Northing from equator (C{meter}). @kwarg radius: Optional earth radius (C{meter}). @kwarg name: Optional name (C{str}).
@raise WebMercatorError: Invalid B{C{x}}, B{C{y}} or B{C{radius}}.
@example:
>>> import pygeodesy >>> w = pygeodesy.Wm(448251, 5411932) '''
self.name = name
'''Get the lat- and longitude (L{LatLon2Tuple}C{(lat, lon)}). '''
'''Convert this WM coordinate to a lat- and longitude.
@kwarg datum: Optional, ellipsoidal datum (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}) or C{None}.
@return: A L{LatLon2Tuple}C{(lat, lon)}.
@raise TypeError: Invalid or non-ellipsoidal B{C{datum}}.
@see: Method C{toLatLon}. ''' raise _IsnotError(_ellipsoidal_, datum=datum) # <https://Earth-Info.NGA.mil/GandG/wgs84/web_mercator/ # %28U%29%20NGA_SIG_0011_1.0.0_WEBMERC.pdf>
Lon(degrees180(x)), name=self.name)
'''Parse a string to a similar L{Wm} instance.
@arg strWM: The WM coordinate (C{str}), see function L{parseWM}. @kwarg name: Optional instance name (C{str}), overriding this name.
@return: The similar instance (L{Wm}).
@raise WebMercatorError: Invalid B{C{strWM}}. ''' name=name or self.name)
def parseWM(self, strWM, name=NN): # PYCHOK no cover '''DEPRECATED, use method L{Wm.parse}.''' return self.parse(strWM, name=name)
'''Get the lat- and longitude ((L{PhiLam2Tuple}C{(phi, lam)}). '''
'''Get the earth radius (C{meter}). '''
def to2ll(self, datum=None): # PYCHOK no cover '''DEPRECATED, use method C{latlon2}.
@return: A L{LatLon2Tuple}C{(lat, lon)}. ''' return self.latlon2(datum=datum)
'''Convert this WM coordinate to a geodetic point.
@arg LatLon: Ellipsoidal class to return the geodetic point (C{LatLon}). @kwarg datum: Optional datum for ellipsoidal or C{None} for spherical B{C{LatLon}} (C{Datum}). @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments.
@return: Point of this WM coordinate (B{C{LatLon}}).
@raise TypeError: If B{C{LatLon}} and B{C{datum}} are incompatible or if B{C{datum}} is invalid or not ellipsoidal.
@example:
>>> w = Wm(448251.795, 5411932.678) >>> from pygeodesy import sphericalTrigonometry as sT >>> ll = w.toLatLon(sT.LatLon) # 43°39′11.58″N, 004°01′36.17″E ''' else: raise _TypeError(LatLon=LatLon, datum=datum)
'''Return a string representation of this WM coordinate.
@kwarg prec: Optional number of decimals, unstripped (C{int}). @kwarg fmt: Optional, enclosing backets format (C{str}). @kwarg sep: Optional separator between name:value pairs (C{str}). @kwarg radius: Optionally, include radius (C{bool} or C{scalar}).
@return: This WM as "[x:meter, y:meter]" (C{str}) plus ", radius:meter]" if B{C{radius}} is C{True} or C{scalar}.
@raise WebMercatorError: Invalid B{C{radius}}. '''
'''Return a string representation of this WM coordinate.
@kwarg prec: Optional number of decimals, unstripped (C{int}). @kwarg sep: Optional separator to join (C{str}) or C{None} to return an unjoined C{tuple} of C{str}s. @kwarg radius: Optionally, include radius (C{bool} or C{scalar}).
@return: This WM as "meter meter" (C{str}) plus " radius" if B{C{radius}} is C{True} or C{scalar}.
@raise WebMercatorError: Invalid B{C{radius}}.
@example:
>>> w = Wm(448251, 5411932.0001) >>> w.toStr(4) # 448251.0 5411932.0001 >>> w.toStr(sep=', ') # 448251, 5411932 ''' else: raise WebMercatorError(radius=radius)
'''Get the easting (C{meter}). '''
'''Get the northing (C{meter}). '''
'''Parse a string C{"e n [r]"} representing a WM coordinate, consisting of easting, northing and an optional radius.
@arg strWM: A WM coordinate (C{str}). @kwarg radius: Optional earth radius (C{meter}). @kwarg Wm: Optional class to return the WM coordinate (L{Wm}) or C{None}. @kwarg name: Optional name (C{str}).
@return: The WM coordinate (B{C{Wm}}) or an L{EasNorRadius3Tuple}C{(easting, northing, radius)} if B{C{Wm}} is C{None}.
@raise WebMercatorError: Invalid B{C{strWM}}.
@example:
>>> u = parseWM('448251 5411932') >>> u.toRepr() # [E:448251, N:5411932] '''
raise ValueError
_xnamed(Wm(x, y, radius=r), name)
strWM=strWM, Error=WebMercatorError)
'''Convert a lat-/longitude point to a WM coordinate.
@arg latlon: Latitude (C{degrees}) or an (ellipsoidal or spherical) geodetic C{LatLon} point. @kwarg lon: Optional longitude (C{degrees} or C{None}). @kwarg radius: Optional earth radius (C{meter}). @kwarg Wm: Optional class to return the WM coordinate (L{Wm}) or C{None}. @kwarg name: Optional name (C{str}). @kwarg Wm_kwds: Optional, additional B{C{Wm}} keyword arguments, ignored if C{B{Wm}=None}.
@return: The WM coordinate (B{C{Wm}}) or an L{EasNorRadius3Tuple}C{(easting, northing, radius)} if B{C{Wm}} is C{None}.
@raise ValueError: If B{C{lon}} value is missing, if B{C{latlon}} is not scalar, if B{C{latlon}} is beyond the valid WM range and L{rangerrors} is set to C{True} or if B{C{radius}} is invalid.
@example:
>>> p = LatLon(48.8582, 2.2945) # 448251.8 5411932.7 >>> w = toWm(p) # 448252 5411933 >>> p = LatLon(13.4125, 103.8667) # 377302.4 1483034.8 >>> w = toWm(p) # 377302 1483035 '''
_xnamed(Wm(e, n, **_xkwds(Wm_kwds, radius=r)), name)
# **) MIT License # # Copyright (C) 2016-2021 -- 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. |