将x,y像素值转换为经度和纬度

时间:2020-07-08 17:35:17

标签: python math geolocation maps geography

我有地图窗口中心的纬度,经度和缩放比例。我有尺寸图窗口。我在窗口中的地图上也有特定事件的像素位置(墨镜投影-openstreetmap)。有人可以帮助我如何将这些像​​素位置转换为纬度和经度坐标,或者以后可以在其他地图上可视化的任何其他坐标系吗? enter image description here

1 个答案:

答案 0 :(得分:0)

我已经找到使用该公式(https://en.wikipedia.org/wiki/Web_Mercator_projection)的解决方案 enter image description here

  1. 计算中心点的x,y位置

  2. 将窗口的坐标系转换为全局坐标

  3. 逆变换

      def LatLontoXY(lat_center,lon_center,zoom):
         C =(256/(2*pi) )* 2**zoom
    
         x=C*(math.radians(lon_center)+pi)
         y=C*(pi-math.log( math.tan(  (pi/4) + math.radians(lat_center)/2    )  ))
    
         return x,y
    
     def xy2LatLon(lat_center,lon_center,zoom,width_internal,height_internal,pxX_internal,pxY_internal):
    
         xcenter,ycenter=LatLontoXY(lat_center,lon_center,zoom)
    
         xPoint=xcenter- (width_internal/2-pxX_internal)
         ypoint=ycenter -(height_internal/2-pxY_internal)
    
    
         C = (256 / (2 * pi)) * 2 ** zoom
         M = (xPoint/C)-pi
         N =-(ypoint/C) + pi
    
         lon_Point =math.degrees(M)
         lat_Point =math.degrees( (math.atan( math.e**N)-(pi/4))*2 )
    
         return lat_Point,lon_Point