如何解决在 Python 中将英国国家网格坐标转换为 WGS64 纬度和经度
我无法将东/北坐标表从英国国家网格系统转换为 WGS84 系统中的纬度/经度坐标。我已经用来自军械测量局的 Helmert 转换电子表格中的常量编写了以下函数集:https://www.ordnancesurvey.co.uk/business-government/tools-support/os-net/coordinates
import math
import pandas as pd
North = 666099.000 # Northing to be transformed
East = 253697.000 # Easting to be transformed
a = 6377563.396 # Semi-major axis for OGSB36
#a = 6378137.0000 # Semi-major axis for WGS84
b = 6356256.909 # Semi-minor axis for OGSB36
#b = 6356752.3142 # Semi-minor axis for WGS84
f0 = 0.9996012717 # Central Meridan Scale
e0 = 400000 # True origin Easting
n0 = -100000 # True origin Northing
PHI0 = 0.855211333 # True origin latitude (Radians) i.e. N 49 0' 0''
DecimalPHI0 = 49.00000000 # True origin latitude (Degrees)
LAM0 = -0.034906585 # True origin longitude (Radians) i.e. W 2 0' 0''
DecimalLAM0 = -2.00000000 # True origin longitude (Degrees)
def InitialLat(North,n0,af0,PHI0,n,bf0):
"""
Compute initial value for Latitude (PHI) IN RADIANS.
Input:
- northing of point (North) and northing of false origin (n0) in meters;
- semi major axis multiplied by central meridian scale factor (af0) in meters;
- latitude of false origin (PHI0) IN RADIANS;
- n (computed from a,b and f0) and
- ellipsoid semi major axis multiplied by central meridian scale factor (bf0) in meters.
"""
#First PHI value (PHI1)
PHI1 = ((North - n0) / af0) + PHI0
def Marc(bf0,PHI1):
"""
Compute meridional arc.
Input:
- ellipsoid semi major axis multiplied by central meridian scale factor (bf0) in meters;
- n (computed from a,b and f0);
- lat of false origin (PHI0) and initial or final latitude of point (PHI) IN RADIANS.
"""
Marc = bf0 * (((1 + n + ((5 / 4) * (n ** 2)) + ((5 / 4) * (n ** 3))) * (PHI1 - PHI0))
- (((3 * n) + (3 * (n ** 2)) + ((21 / 8) * (n ** 3))) * (math.sin(PHI1 - PHI0)) * (math.cos(PHI1 + PHI0)))
+ ((((15 / 8) * (n ** 2)) + ((15 / 8) * (n ** 3))) * (math.sin(2 * (PHI1 - PHI0))) * (math.cos(2 * (PHI1 + PHI0))))
- (((35 / 24) * (n ** 3)) * (math.sin(3 * (PHI1 - PHI0))) * (math.cos(3 * (PHI1 + PHI0)))))
return Marc
# Calculate M
M = Marc(bf0,PHI1)
#Calculate new PHI value (PHI2)
PHI2 = ((North - n0 - M) / af0) + PHI1
#Iterate to get final value for InitialLat
while abs(North - n0 - M) > 0.00001:
PHI2 = ((North - n0 - M) / af0) + PHI1
M = Marc(bf0,PHI2)
PHI1 = PHI2
InitialLat = PHI2
return InitialLat
def E_N_to_Lat(East,North,a,b,e0,f0,LAM0):
"""
Un-project Transverse Mercator eastings and northings back to latitude.
Input:
- eastings (East) and northings (North) in meters; _
- ellipsoid axis dimensions (a & b) in meters; _
- eastings (e0) and northings (n0) of false origin in meters; _
- central meridian scale factor (f0) and _
- latitude (PHI0) and longitude (LAM0) of false origin in decimal degrees.
"""
#Convert angle measures to radians
Pi = math.pi
RadPHI0 = PHI0 * (Pi / 180)
RadLAM0 = LAM0 * (Pi / 180)
# Compute af0,bf0,e squared (e2),n and Et
af0 = a * f0
bf0 = b * f0
e2 = ((af0 ** 2) - (bf0 ** 2)) / (af0 ** 2)
n = (af0 - bf0) / (af0 + bf0)
Et = East - e0
# Compute initial value for latitude (PHI) in radians
PHId = InitialLat(North,RadPHI0,bf0)
# Compute nu,rho and eta2 using value for PHId
nu = af0 / (math.sqrt(1 - (e2 * ((math.sin(PHId)) ** 2))))
rho = (nu * (1 - e2)) / (1 - (e2 * (math.sin(PHId)) ** 2))
eta2 = (nu / rho) - 1
# Compute Latitude
VII = (math.tan(PHId)) / (2 * rho * nu)
VIII = ((math.tan(PHId)) / (24 * rho * (nu ** 3))) * (5 + (3 * ((math.tan(PHId)) ** 2)) + eta2 - (9 * eta2 * ((math.tan(PHId)) ** 2)))
IX = ((math.tan(PHId)) / (720 * rho * (nu ** 5))) * (61 + (90 * ((math.tan(PHId)) ** 2)) + (45 * ((math.tan(PHId)) ** 4)))
E_N_Lat = (180 / Pi) * (PHId - ((Et ** 2) * VII) + ((Et ** 4) * VIII) - ((Et ** 6) * IX))
return(E_N_Lat)
def E_N_to_Long(East,LAM0):
"""
Un-project Transverse Mercator eastings and northings back to longitude.
Input:
- eastings (East) and northings (North) in meters;
- ellipsoid axis dimensions (a & b) in meters;
- eastings (e0) and northings (n0) of false origin in meters;
- central meridian scale factor (f0) and
- latitude (PHI0) and longitude (LAM0) of false origin in decimal degrees.
"""
# Convert angle measures to radians
Pi = 3.14159265358979
RadPHI0 = PHI0 * (Pi / 180)
RadLAM0 = LAM0 * (Pi / 180)
# Compute af0,n and Et
af0 = a * f0
bf0 = b * f0
e2 = ((af0 ** 2) - (bf0 ** 2)) / (af0 ** 2)
n = (af0 - bf0) / (af0 + bf0)
Et = East - e0
# Compute initial value for latitude (PHI) in radians
PHId = InitialLat(North,rho and eta2 using value for PHId
nu = af0 / (math.sqrt(1 - (e2 * ((math.sin(PHId)) ** 2))))
rho = (nu * (1 - e2)) / (1 - (e2 * (math.sin(PHId)) ** 2))
eta2 = (nu / rho) - 1
# Compute Longitude
X = ((math.cos(PHId)) ** -1) / nu
XI = (((math.cos(PHId)) ** -1) / (6 * (nu ** 3))) * ((nu / rho) + (2 * ((math.tan(PHId)) ** 2)))
XII = (((math.cos(PHId)) ** -1) / (120 * (nu ** 5))) * (5 + (28 * ((math.tan(PHId)) ** 2)) + (24 * ((math.tan(PHId)) ** 4)))
XIIA = (((math.cos(PHId)) ** -1) / (5040 * (nu ** 7))) * (61 + (662 * ((math.tan(PHId)) ** 2)) + (1320 * ((math.tan(PHId)) ** 4)) + (720 * ((math.tan(PHId)) ** 6)))
E_N_Long = (180 / Pi) * (RadLAM0 + (Et * X) - ((Et ** 3) * XI) + ((Et ** 5) * XII) - ((Et ** 7) * XIIA))
return E_N_Long
def E_N_to_Lat_Long(North,East):
Lat = E_N_to_Lat(East,DecimalPHI0,DecimalLAM0)
Long = E_N_to_Long(East,DecimalLAM0)
return [Lat,Long]
这一切运行良好,但它只有 +/- 3m 左右的转换精度,这对于我需要它的应用程序来说不够好。使用 Python 转换数千个坐标是否有更好的选择?
解决方法
这里有几个用于从 WGS84 转换为 BNG 的 Python 库,它们都利用 OSTN15 进行准确的转换: https://github.com/urschrei/convertbng
https://grid-banger.readthedocs.io/en/latest/README.html
可以在此处找到 OS 的更多信息:https://www.ordnancesurvey.co.uk/documents/resources/guide-coordinate-systems-great-britain.pdf
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。