我有一个以米为单位的笛卡尔方形网格,以 (-3600, -3600)、(3600, -3600)、(-3600, 3600) 和 (3600, 3600) 作为边界点。我知道中心点(0,0)对应的纬度和经度。我想根据中心参考纬度和经度将此笛卡尔网格转换为纬度经度。
import numpy as np
x = np.linspace(-3600,3600,7201)
y = np.linspace(-3600,3600,7201)
yy, xx = np.meshgrid(y,x)
referenceLatitude = 48.85865
referenceLongitude = 2.33811
我想将生成的网格转换为经纬度坐标
如有任何帮助,我们将不胜感激
我尝试使用 pyproj 进行 WGS84 投影,但我无法获取参考纬度和经度,所以它不正确
这个函数就可以解决问题:
import math
def cartesian_to_latlon(x, y, central_lat, central_lon):
# Earth radius in meters
earth_radius = 6378137
# Convert x and y distances to radians
lat_offset = y / earth_radius
lon_offset = x / (earth_radius * math.cos(math.pi * central_lat / 180))
# Convert radians to degrees
new_lat = central_lat + (lat_offset * 180 / math.pi)
new_lon = central_lon + (lon_offset * 180 / math.pi)
return new_lat, new_lon
在这里你可以用你的点替换x,y