Package pygeodesy :: Module osgr |
[frames] | no frames]

# Module osgr

Ordinance Survey Grid References (OSGR) classes Osgr an OSGRError and functions parseOSGR and toOsgr.

Pure Python implementation of OS Grid Reference functions using an ellipsoidal earth model, transcribed from JavaScript originals by (C) Chris Veness 2005-2016 published under the same MIT Licence**, see OS National Grid and Module osgridref.

OSGR provides geocoordinate references for UK mapping purposes, converted in 2015 to work with WGS84 datum by default or OSGB36 as option.

See Guide, Proposed Changes, Confirmation and Ordnance Survey National Grid.

See also Karney 'Transverse Mercator with an accuracy of a few nanometers', 2011 (building on Krüger 'Konforme Abbildung des Erdellipsoids in der Ebene', 1912), Seidel 'Die Mathematik der Gauß-Krueger-Abbildung', 2006 and Transverse Mercator: Redfearn series.

Version: 20.03.23

Classes
| OSGRError Ordinance Survey Grid References (OSGR) parse or other Osgr issue.
| Osgr Ordinance Survey Grid References (OSGR) coordinate.

Functions
parseOSGR(strOSGR, Osgr=<class 'pygeodesy.osgr.Osgr'>, name=`'````'`) Parse an OSGR coordinate string to an Osgr instance. |
toOsgr(latlon, lon=None, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran`...`, Osgr=<class 'pygeodesy.osgr.Osgr'>, name=`'````'`, **Osgr_kwds) Convert a lat-/longitude point to an OSGR coordinate. |

Variables
| __all__ = `_ALL_LAZY.osgr`

Function Details

### parseOSGR(strOSGR, Osgr=<class 'pygeodesy.osgr.Osgr'>, name=`'````'`) |
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'. Parameters: `strOSGR` - An OSGR coordinate (`str`). `Osgr` - Optional class to return the OSGR coordinate (Osgr) or `None`. `name` - Optional `Osgr` name (`str`). Returns: The OSGR coordinate (`Osgr`) or an EasNor2Tuple`(easting, northing)` if `Osgr` is `None`. Raises: `OSGRError` - Invalid `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

### toOsgr(latlon, lon=None, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran`...`, Osgr=<class 'pygeodesy.osgr.Osgr'>, name=`'````'`, **Osgr_kwds) |
Convert a lat-/longitude point to an OSGR coordinate. Parameters: `latlon` - Latitude (`degrees`) or an (ellipsoidal) geodetic `LatLon` point. `lon` - Optional longitude in degrees (scalar or `None`). `datum` - Optional datum to convert (`Datum`). `Osgr` - Optional class to return the OSGR coordinate (Osgr) or `None`. `name` - Optional `Osgr` name (`str`). `Osgr_kwds` - Optional, additional `Osgr` keyword arguments, ignored if `Osgr=None`. Returns: The OSGR coordinate (`Osgr`) or an EasNor2Tuple`(easting, northing)` if `Osgr` is `None`. Raises: `TypeError` - Non-ellipsoidal `latlon` or `datum` conversion failed. `OSGRError` - Invalid `latlon` or `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)