osgb36_to_wgs84

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

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

Parameters:
  • eastings (int | float | Iterable) – Easting (X) coordinate, eastward-measured distance.

  • northings (int | float | Iterable) – Northing (Y) coordinate, northward-measured distance.

  • as_array (bool) – Whether to return an array; defaults to False.

  • kwargs – [Optional] Additional parameters for the function pyproj.Transformer.transform.

Returns:

Geographic coordinates (Longitude, Latitude).

Return type:

tuple | numpy.ndarray

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 ]])