Coverage for pygeodesy/osgr.py : 93%

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 -*-
and functions L{parseOSGR} and L{toOsgr}.
Pure Python implementation of OS Grid Reference functions using an ellipsoidal earth model, transcribed from JavaScript originals by I{(C) Chris Veness 2005-2016} published under the same MIT Licence**, see U{OS National Grid<https://www.Movable-Type.co.UK/scripts/latlong-os-gridref.html>} and U{Module osgridref <https://www.Movable-Type.co.UK/scripts/geodesy/docs/module-osgridref.html>}.
OSGR provides geocoordinate references for UK mapping purposes, converted in 2015 to work with WGS84 datum by default or OSGB36 as option.
See U{Guide<https://www.OrdnanceSurvey.co.UK/docs/support/guide-coordinate-systems-great-britain.pdf>}, U{Proposed Changes<https://www.OrdnanceSurvey.co.UK/blog/2014/09/proposed-changes-to-latitude-and-longitude-representation-on-paper-maps-tell-us-your-thoughts>}, U{Confirmation<https://www.OrdnanceSurvey.co.UK/blog/2014/12/confirmation-on-changes-to-latitude-and-longitude>} and U{Ordnance Survey National Grid<https://WikiPedia.org/wiki/Ordnance_Survey_National_Grid>}.
See also Karney U{'Transverse Mercator with an accuracy of a few nanometers' <https://Arxiv.org/pdf/1002.1417v3.pdf>}, 2011 (building on Krüger U{'Konforme Abbildung des Erdellipsoids in der Ebene' <https://bib.GFZ-Potsdam.DE/pub/digi/krueger2.pdf>}, 1912), Seidel U{'Die Mathematik der Gauß-Krueger-Abbildung' <https://Henrik-Seidel.GMXhome.DE/gausskrueger.pdf>}, 2006 and U{Transverse Mercator: Redfearn series <https://WikiPedia.org/wiki/Transverse_Mercator:_Redfearn_series>}.
@newfield example: Example, Examples '''
_NamedBase, nameof, _xattrs, _xnamed halfs2, issubclassof, property_RO, sincos2
# all public contants, classes and functions
'''(INTERNAL) Convert datum if needed. ''' except AttributeError: raise TypeError('no %s.convertDatum: %r' % (name, ll))
'''(INTERNAL) Compute meridional arc. ''' sin(a_ * 2) * cos(_a * 2), -sin(a_ * 3) * cos(_a * 3))
'''Ordinance Survey Grid References (OSGR) parse or other L{Osgr} issue. '''
'''Ordinance Survey Grid References (OSGR) coordinate. '''
'''New L{Osgr} National Grid Reference.
@param easting: Easting from OS false easting (C{meter}). @param northing: Northing from from OS false northing (C{meter}). @keyword name: Optional name (C{str}).
@raise OSGRError: Invalid B{C{easting}} or B{C{northing}}.
@example:
>>> from pygeodesy import Osgr >>> r = Osgr(651409, 313177) ''' self.name = name
'''(INTERNAL) Make copy with add'l, subclass attributes. ''' return _xattrs(self.classof(self.easting, self.northing), self, *attrs)
'''Copy this OSGR reference.
@return: The copy (L{Osgr} or subclass thereof). ''' return self._xcopy()
def datum(self): '''Get the datum (L{Datum}). ''' return self._datum
def easting(self): '''Get the easting (C{meter}). ''' return self._easting
def northing(self): '''Get the northing (C{meter}). ''' return self._northing
'''Parse a string to an Osgr instance.
For more details, see function L{parseOSGR} in this module L{osgr}. ''' return parseOSGR(strOSGR)
'''Convert this OSGR coordinate to an (ellipsoidal) geodetic point.
I{Note formulation implemented here due to Thomas, Redfearn, etc. is as published by OS, but is inferior to Krüger as used by e.g. Karney 2011.}
@keyword LatLon: Optional ellipsoidal (sub-)class to return the point (C{LatLon}) or C{None}. @keyword datum: Optional datum to use (C{Datum}).
@return: The geodetic point (B{C{LatLon}}) or a L{LatLonDatum3Tuple}C{(lat, lon, datum)} if B{C{LatLon}} is C{None}.
@raise TypeError: If B{C{LatLon}} is not ellipsoidal or if B{C{datum}} conversion failed.
@example:
>>> from pygeodesy import ellipsoidalVincenty as eV >>> g = Osgr(651409.903, 313177.270) >>> p = g.toLatLon(eV.LatLon) # 52°39′28.723″N, 001°42′57.787″E >>> # to obtain (historical) OSGB36 lat-/longitude point >>> p = g.toLatLon(eV.LatLon, datum=Datums.OSGB36) # 52°39′27.253″N, 001°43′04.518″E '''
tar / ( 2 * v), tar / ( 24 * v3) * fdot((1, 3, -9), 5 + x2, ta2, ta2 * x2), tar / (720 * v5) * fdot((61, 90, 45), 1, ta2, ta4))
csa / v, csa / ( 6 * v3) * fsum_(vr, ta, ta), csa / ( 120 * v5) * fdot((5, 28, 24), 1, ta2, ta4), csa / (5040 * v7) * fdot((61, 662, 1320, 720), ta, ta2, ta4, ta6))
'''(INTERNAL) Convert cached LatLon ''' if datum and datum != ll.datum: raise TypeError('no %s.convertDatum: %r' % (LatLon, ll)) return _xnamed(LatLonDatum3Tuple(ll.lat, ll.lon, ll.datum), ll.name) raise _IsNotError(_LLEB.__name__, LatLon=LatLon)
'''Return a string representation of this OSGR coordinate.
Note that OSGR coordinates are truncated, not rounded (unlike UTM grid references).
@keyword prec: Optional number of digits (C{int}). @keyword sep: Optional C{join} separator (C{str}).
@return: This OSGR as C{"EN easting northing"} or as C{"easting,northing"} if B{C{prec}} is non-positive (C{str}).
@raise ValueError: Invalid B{C{prec}}.
@example:
>>> r = Osgr(651409, 313177) >>> str(r) # TG 5140 1317 >>> r.toStr(prec=0) # 651409,313177 '''
0 > N or N > 12: return '' _i2c((N * 5) % 25 + (E % 5))
else:
'''Return a string representation of this OSGR coordinate.
@keyword prec: Optional number of digits (C{int}). @keyword fmt: Optional enclosing backets format (C{str}). @keyword sep: Optional separator to join (C{str}).
@return: This OSGR (C{str}) "[G:00B, E:meter, N:meter]" or "OSGR:meter,meter" if B{C{prec}} is non-positive. ''' else:
'''Parse an OSGR coordinate string to an Osgr instance.
Accepts standard OS Grid References like 'SU 387 148', with or without whitespace separators, from 2- up to 10-digit references (1 m × 1 m square), or fully numeric, comma-separated references in metres, for example '438700,114800'.
@param strOSGR: An OSGR coordinate (C{str}). @keyword Osgr: Optional (sub-)class to return the OSGR coordinate (L{Osgr}) or C{None}. @keyword name: Optional B{C{Osgr}} name (C{str}).
@return: The OSGR coordinate (B{C{Osgr}}) or an L{EasNor2Tuple}C{(easting, northing)} if B{C{Osgr}} is C{None}.
@raise OSGRError: Invalid B{C{strOSGR}}.
@example:
>>> g = parseOSGR('TG 51409 13177') >>> str(g) # TG 51409 13177 >>> g = parseOSGR('TG5140913177') >>> str(g) # TG 51409 13177 >>> g = parseOSGR('TG51409 13177') >>> str(g) # TG 51409 13177 >>> g = parseOSGR('651409,313177') >>> str(g) # TG 51409 13177 >>> g.toStr(prec=0) # 651409,313177 '''
raise ValueError # caught below
else: # "GR easting northing"
0 > N or N > 12: raise ValueError # caught below
else: raise ValueError # caught below
except ValueError: raise OSGRError('%s invalid: %r' % ('strOSGR', strOSGR))
'''Convert a lat-/longitude point to an OSGR coordinate.
@param latlon: Latitude (C{degrees}) or an (ellipsoidal) geodetic C{LatLon} point. @keyword lon: Optional longitude in degrees (scalar or C{None}). @keyword datum: Optional datum to convert (C{Datum}). @keyword Osgr: Optional (sub-)class to return the OSGR coordinate (L{Osgr}) or C{None}. @keyword name: Optional B{C{Osgr}} name (C{str}).
@return: The OSGR coordinate (B{C{Osgr}}) or an L{EasNor2Tuple}C{(easting, northing)} if B{C{Osgr}} is C{None}.
@raise TypeError: Non-ellipsoidal B{C{latlon}} or B{C{datum}} conversion failed.
@raise OSGRError: Invalid B{C{latlon}} or B{C{lon}}.
@example:
>>> p = LatLon(52.65798, 1.71605) >>> r = toOsgr(p) # TG 51409 13177 >>> # for conversion of (historical) OSGB36 lat-/longitude: >>> r = toOsgr(52.65757, 1.71791, datum=Datums.OSGB36) ''' # XXX fix failing _LLEB.convertDatum() raise OSGRError('%s not %s: %r' % ('lon', None, lon))
(vsa / 2) * ca, (vsa / 24) * ca3 * fsum_(5, -ta2, 9 * x2), (vsa / 720) * ca5 * fsum_(61, ta4, -58 * ta2))
(v * ca), (v / 6) * ca3 * (r - ta2), (v / 120) * ca5 * fdot((-18, 1, 14, -58), ta2, 5 + ta4, x2, ta2 * x2))
r = EasNor2Tuple(e, n) else:
# **) 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. |