osgb36_to_wgs84

pyhelpers.geom.osgb36_to_wgs84(eastings, northings, as_array=False, **kwargs)

Convert British national grid (OSGB36) to latitude and longitude (WGS84).

Parameters
  • eastings (int or float or Iterable[int, float]) – Easting (X), eastward-measured distance (or the x-coordinate)

  • northings (int or float or Iterable[int, float]) – Northing (Y), northward-measured distance (or the y-coordinate)

  • as_array (bool) – whether to return an array, defaults to False

  • kwargs – [optional] parameters of pyproj.Transformer.transform

Returns

geographic coordinate (Longitude, Latitude)

Return type

tuple or numpy.ndarry

Examples:

>>> from pyhelpers.geom import osgb36_to_wgs84
>>> from pyhelpers._cache import example_dataframe

>>> example_df = example_dataframe(osgb36=True)
>>> example_df
                  Easting       Northing
City
London      530039.558844  180371.680166
Birmingham  406705.887014  286868.166642
Manchester  383830.039036  398113.055831
Leeds       430147.447354  433553.327117

>>> x, y = example_df.loc['London'].values
>>> lon, lat = osgb36_to_wgs84(eastings=x, northings=y)
>>> print(f"London (Longitude, Latitude): {(lon, lat)}")
London (Longitude, Latitude): (-0.12764738749567286, 51.50732189539607)

>>> xy_array = example_df.to_numpy()
>>> xs, ys = xy_array.T  # xy_array[:, 0], xy_array[:, 1]
>>> lons, lats = osgb36_to_wgs84(eastings=xs, northings=ys)
>>> lons
array([-0.12764739, -1.90269109, -2.24511479, -1.54379409])
>>> lats
array([51.5073219, 52.4796992, 53.4794892, 53.7974185])

>>> lonlat_array = osgb36_to_wgs84(eastings=xs, northings=ys, as_array=True)
>>> lonlat_array
array([[-0.12764739, 51.5073219 ],
       [-1.90269109, 52.4796992 ],
       [-2.24511479, 53.4794892 ],
       [-1.54379409, 53.7974185 ]])