简体   繁体   English

将 x,y 像素值转换为 lat 和 long

[英]Transform x,y pixel values into lat and long

I have latitude, longitude and zoom of center of my map window.我有我的 map window 中心的纬度、经度和缩放。 I have dimension map window.我有尺寸 map window。 I also have pixel positions of specific events on the map (mercator projection -openstreetmap ) in the window.我在 window 中的 map(墨卡托投影 -openstreetmap)上也有特定事件的像素位置。 Can Anyone help me how to convert these pixel positions into latitude and longitude coordinates or any other coordinate system that I will be able to visualize on different map later?谁能帮助我如何将这些像素位置转换为纬度和经度坐标或任何其他我以后能够在不同 map 上可视化的坐标系? general case of my problem我的问题的一般情况

I have found the solution using this formula ( https://en.wikipedia.org/wiki/Web_Mercator_projection ) enter image description here我找到了使用这个公式的解决方案( https://en.wikipedia.org/wiki/Web_Mercator_projection在此处输入图像描述

  1. calculate the x,y position of my center point计算我的中心点的 x,y position

  2. trasform coordinate system of window to global将 window 的坐标系转换为全局坐标系

  3. inverse transformation逆变换

     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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM