wgs84_to_osgb36¶
- pyhelpers.geom.wgs84_to_osgb36(longitudes, latitudes, as_array=False, **kwargs)[source]¶
Convert latitude and longitude (WGS84) to British national grid (OSGB36).
- Parameters:
longitudes (int | float | Iterable) – Longitude of a point on Earth’s surface in degrees; abbreviated as long., λ or lambda.
latitudes (int | float | Iterable) – Latitude of a point on Earth’s surface in degrees; abbreviated as lat., φ or phi.
as_array (bool) – Whether to return an array; defaults to
False
.kwargs – [Optional] Additional parameters for the function pyproj.Transformer.transform.
- Returns:
Geographic Cartesian coordinates (Easting, Northing) or (X, Y).
- Return type:
tuple | numpy.ndarry
Examples:
>>> from pyhelpers.geom import wgs84_to_osgb36 >>> from pyhelpers._cache import example_dataframe >>> example_df = example_dataframe() >>> example_df Longitude Latitude City London -0.127647 51.507322 Birmingham -1.902691 52.479699 Manchester -2.245115 53.479489 Leeds -1.543794 53.797418 >>> lon, lat = example_df.loc['London'].values >>> x, y = wgs84_to_osgb36(longitudes=lon, latitudes=lat) >>> print(f"London (Easting, Northing): {(x, y)}") London (Easting, Northing): (530039.558844505, 180371.68016544735) >>> lonlat_array = example_df.to_numpy() >>> lonlat_array array([[-0.1276474, 51.5073219], [-1.9026911, 52.4796992], [-2.2451148, 53.4794892], [-1.5437941, 53.7974185]]) >>> lons, lats = lonlat_array.T # lonlat_array[:, 0], lonlat_array[:, 1] >>> xs, ys = wgs84_to_osgb36(longitudes=lons, latitudes=lats) >>> xs array([530039.5588445 , 406705.8870136 , 383830.03903573, 430147.44735387]) >>> ys array([180371.68016545, 286868.16664219, 398113.05583091, 433553.32711728]) >>> xy_array = wgs84_to_osgb36(longitudes=lons, latitudes=lats, as_array=True) >>> xy_array array([[530039.5588445 , 180371.68016545], [406705.8870136 , 286868.16664219], [383830.03903573, 398113.05583091], [430147.44735387, 433553.32711728]])