我有一个边框:转换纬度/长到X,内Y位置边框
Left -122.27671
Bottom 37.80445
Right -122.26673
Top 37.81449
它也可以转化为NE纬度/经度和SW纬度/龙
在该边界框,我想找到特定纬度/经度的X,Y位置。这将使用墨卡托投影。
我见过的答案是找到X,Y采用墨卡托投影的世界地图上的位置,而不是特定的经/纬度范围内。
任何帮助表示赞赏!
UPDATE 把这个从我看到的另一个问题放在一起。任何人都可以验证,如果这看起来合法?
map_width = 1240
map_height = 1279
map_lon_left = -122.296916
map_lon_right = -122.243380
map_lon_delta = map_lon_right - map_lon_left
map_lat_bottom = 37.782368
map_lat_bottom_degree = map_lat_bottom * Math::PI/180
def convert_geo_to_pixel(lat, long)
x = (long - map_lon_left) * (map_width/map_lon_delta)
lat = lat * Math::PI/180
world_map_width = ((map_width/map_lon_delta) * 360)/(2 * Math::PI)
map_offset_y = (world_map_width/2 * Math.log((1 + Math.sin(map_lat_bottom_degree))/(1 - Math.sin(map_lat_bottom_degree))))
y = map_height - ((world_map_width/2 * Math.log((1 + Math.sin(lat))/(1 - Math.sin(lat)))) - map_offset_y)
return [x, y]
end
是我在上面使用的代码不正确吗?有您的例子输出'X,y'当一个边框内给予纬度/经度很难理解? – theartofbeing
您的x计算是正确的。你似乎错了。我的纬度相当于你的纬度,B = map_lat_bottom,T = map_lat_top(没有看到它在你的代码) – MBo
我从http://stackoverflow.com/questions/2103924/mercator-longitude-and-latitude-抄我的解决办法计算到的X和Y型上一个裁剪地图的最/ 10401734#10401734 我相信map_lat左和右是左上角和右上角。既然我们知道角落的位置,我们需要的只是底部的纬度来完成正方形。这就是我解释这个解决方案的方式? – theartofbeing